我正在使用Vc6中的openGL 每次我运行以下简单代码输出窗口崩溃
#include <stdio.h>
#include <gl/glut.h>
//#include <gl/glaux.h>
void display(void)
{
glColor3f(255.0f,255.0f,255.0f);
glBegin(GL_QUADS);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,5.0f,0.0f);
glVertex3f(5.0f,5.0f,0.0f);
glVertex3f(5.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glEnd();
glFlush();
}
void init(void)
{
glViewport(0,0,400,400);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,4/3,4.0,1000.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(2.0,2.0,2.0,1.0,2.0,1.0,0.0,1.0,0.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc,argv);
init();
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowPosition(400,400);
glutInitWindowSize(400,400);
glutCreateWindow("Trial");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
我不知道出了什么问题,请帮忙
答案 0 :(得分:5)
在使用OpenGL上下文之前,您正在使用OpenGL函数(根本不需要调用任何GL函数)。上下文由glutCreateWindow
创建,但您对GL函数的第一次调用发生在init()
中。要解决此问题,您可以将init()
电话转移到glutCreateWindow
电话下方。