0
我沒有在我的程序中使用glutMainLoop(),但我在一個簡單的while循環中使用glutMainLoopEvent()。這很好,但重新調整回調從未被調用過。我在main()中註冊了我的reshape事件。這裏是我的源代碼:Freeglut Reshape回調
#include <iostream>
#include "GL/freeglut.h"
float angle = 0.0f;
void ResizeEvent(int w, int h)
{
std::cout << "Resizing... << w << " " << h << std::Endl;
if(h == 0)
h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (GLdouble)w/h, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void InitializeGL()
{
glClearColor(0.0, 0.0, 0.0, 1.0f);
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 640.0/480.0, 0.1, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Update()
{
angle += 0.05f;
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);
glRotatef(angle, 0.5f, 1.0f, 0.75f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
glutCreateWindow("Learning freeglut");
InitializeGL();
glutReshapeFunc(ResizeEvent);
while(true)
{
Update();
Display();
glutMainLoopEvent();
}
return 0;
}
在此先感謝!
編輯:任何人?
請問,如果你使用glutMainLoop(該重塑函數被調用)? – Ben 2014-10-06 21:18:30
是的。我嘗試使用其他事件,例如鍵盤事件,它可以與glutMainLoop和glutMainLoopEvent一起使用。 – KrounNouns 2014-10-06 21:29:34