2011-03-04 166 views
1

我每天我運行下面簡單的代碼輸出窗口崩潰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; 

} 

我不知道時間是怎麼回事不對任何工作欽傑基於OpenGL在VC6 請幫

+2

爲什麼地球上你還在使用VC6? – 2011-03-04 18:04:51

+0

,我還包括正確的標題'glut.h''gluax.h' – sumanta 2011-03-04 18:11:22

+1

它在哪裏崩潰?確切的線路是什麼? – 2011-03-04 18:13:24

回答

5

在OpenGL上下文之前(這是要求調用任何GL函數)之前,您正在使用OpenGL函數。上下文由glutCreateWindow創建,但您首次調用GL函數發生在init()。要解決此問題,您可以將init()呼叫移動到glutCreateWindow呼叫的下方。