• OpenGL Win32 动画


    #include <iostream>
    #include <gl\glut.h>
    #include <gl\GL.h>
    #include <gl\GLU.h>
    
    #include "base.h"
    using namespace std;
    
    int x, y;
    
    void display(void)
    {
        
        glClear(GL_COLOR_BUFFER_BIT);
    
        glPushMatrix();
    
        //glBegin(GL_TRIANGLES);
        glBegin(GL_QUADS);
        glVertex2d(x, y);
        glVertex2d(x + 35, y);
        glVertex2d(x + 35, y + 35);
        glVertex2d(x, y + 35);
        glEnd();
    
        glPopMatrix();
    //glFlush();
        glutSwapBuffers();
    }
    void init()
    {
        glClearColor (0.0, 0.0, 0.0, 0.0);
        glColor3f(1.0, 1.0, 1.0);
    
        x = y = 0;
    }
    
    void reshape(int w, int h)
    {
        double d = MapHeight / 600.0 / 2;
        double dw = w / 2.0 * d;
        double dh = h / 2.0 * d;
        glViewport(0,0,w,h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(-dw, dw, -dh, dh);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glutPostRedisplay();
    }
    
    void onTimer(int value)
    {
        printf("dfd\n");
        x += 10;
    
        // 重绘
        glutPostRedisplay();
        glutTimerFunc(50, onTimer, 0);
    }
    
    int main(int argc, char** argv)
    {
        glutInit(&argc,argv);
    
        glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
    
        //    glutInitWindowSize(MapWidth,MapHeight);
        double radio = MapWidth * 1.0 / MapHeight;
        glutInitWindowSize(600 * radio,600);
        glutInitWindowPosition(0,0);
        glutCreateWindow("simple");
    
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutTimerFunc(50, onTimer, 0);
    
        init();
    
        glutMainLoop();
    
        //system("pause");
    }
  • 相关阅读:
    银行卡号每隔四位添加一个分隔符
    clipboard.js实现文本复制
    选中|复制文本
    react---之下拉菜单默认选中的值始终不变的问题
    create-react-app支持less配置
    数对
    安置路灯
    被三整除
    牛牛找工作
    C++ std::pair
  • 原文地址:https://www.cnblogs.com/litstrong/p/2457824.html
Copyright © 2020-2023  润新知