#include <GL/glut.h>void myDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
    glFlush();
}int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(400, 400);
    glutCreateWindow("我的第一个OpenGL程序!");
    glutDisplayFunc(&myDisplay);
    glutMainLoop();
    return 0;
}
什么问题也没有,调试总是有:
'textopengl02.exe': Loaded 'D:\Program Files\OpenGL\Visual Studio 2008\Projects\textopengl02\Release\textopengl02.exe', Symbols loaded.
'textopengl02.exe': Loaded 'C:\windows\system32\ntdll.dll'
'textopengl02.exe': Loaded 'C:\windows\system32\kernel32.dll'
'textopengl02.exe': Loaded 'C:\windows\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4148_x-ww_d495ac4e\msvcr90.dll'
'textopengl02.exe': Loaded 'C:\windows\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4148_x-ww_d495ac4e\msvcp90.dll'
The program '[3452] textopengl02.exe: Native' has exited with code 0 (0x0).

解决方案 »

  1.   

    我不大清楚 glut, 但是,glut不需要设置 PROJECTION 和 MODELVIEW 矩阵么?
      

  2.   

    有glutDisplayFunc(&myDisplay);函数作用,不需要进行投影矩阵和模型操作的时候无需GL_PROJECTION和GL_MODELVIEW的作用,这只是一个简单的绘图程序!
      

  3.   

    话说你 glColor3f 试试呢
    还有你的 glRectf 的参数传大点呢
      

  4.   

    请你加上这样几句
    void reshape(GLsizei w,GLsizei h)
    {
    if(h==0)
    {
    h=1;
    }
    glViewport(0,0,w,h);
    glMatrixMode(GL_PORJECTION);
    glLoadIdentity();
    gluPerspective(60.0,(GLdouble)w/(GLdouble)h,1.0,100.0);
    gluLookAt(0.0,0.0,50.0,0.0,0.0,0.0,0.0,1.0,0.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }在调用glutCreateWindow()之后加上
    glutReshapeFunc(reshape);再试试看!