openGL window crash
i am working on openGL in Vc6 every time i run the following simple code output window crashes
#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开发者_Python百科);
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;
}
i don't know what is going wrong any boby please help
You are using OpenGL functions before you have an OpenGL context (which is a requirement to call any GL functions at all). The context is created by glutCreateWindow
, but your first call to GL functions happens in init()
. To fix this, you could move your init()
call right below the glutCreateWindow
call.
精彩评论