按红宝书上的例子打了一段程序,发现执行不正常:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.00);
glVertex3f(0.75, 0.25, 0.00);
glVertex3f(0.75, 0.75, 0.00);
glVertex3f(0.25, 0.75, 0.00);
glEnd();
glFlush();
}
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
int main(void)
{
auxInitDisplayMode(AUX_SINGLE|AUX_RGB);
auxInitPosition(100.0, 100.0, 250.0, 250.0);
auxInitWindow("OpenGL");
init();
auxMainLoop(display);
return 0;
}
结果发现屏幕上什么都没画,但是如果把display函数中的内容般到main中,显示正常,为什么?谢谢
这个问题确实比较奇怪,看不出哪里有问题,但是加上对auxReshapeFunc的调用后,即使resize不做什么都可以正确绘制,把代码改成下面这样就可以了
我想这个问题不必深究,应该是和aux库有关的,而aux现在基本已经被glut取代了
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.00);
glVertex3f(0.75, 0.25, 0.00);
glVertex3f(0.75, 0.75, 0.00);
glVertex3f(0.25, 0.75, 0.00);
glEnd();
glFlush();
}
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1, 0.0, 1, -1.0, 1.0);
}
void CALLBACK resize( GLsizei w, GLsizei h )
{
}
int main(void)
{
auxInitDisplayMode(AUX_SINGLE|AUX_RGB);
auxInitPosition(100.0, 100.0, 250.0, 250.0);
auxInitWindow("OpenGL");
init();
auxReshapeFunc( resize );
auxMainLoop(display);
return 0;
}