我想在我的电脑上用OpenGL创建一个程序。我用这个代码
#include "stdafx.h"
#include <GL/glut.h>
bool bFullsreen = false;
int nWindowID;
void display(void)
{
//Clear all pixels
glClear(GL_COLOR_BUFFER_BIT);
//draw white polygon (rectangle) with corners at
// (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glEnd();
// Don't wait start processing buffered OpenGL routines)
//glFlush();
glutSwapBuffers();
}
void init(void)
{
//select clearing (background) color
glClearColor(0.0, 0.0, 0.0, 0.0);
//initialize viewing values
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
void keyboardFunc(unsigned char key, int x, int y) {
switch (key) {
case 'f':
bFullsreen = !bFullsreen;
if (bFullsreen)
glutFullScreen();
else {
glutSetWindow(nWindowID);
glutPositionWindow(100, 100);
glutReshapeWindow(640, 480);
}
break;
}
}
void idleFunc(void) {
glutPostRedisplay();
}
int _tmain(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,100);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
nWindowID = glutCreateWindow("Hello World");
init();
glutDisplayFunc(display);
glutKeyboardFunc(keyboardFunc);
glutIdleFunc(idleFunc);
glutMainLoop();
return 0;
}
当我在我的电脑上运行时,它没有显示任何内容,只显示背景。喜欢这张图片:
但是当我切换到全屏模式时,它会正确显示。我搜索了一下,发现GLUT_Single
改为GLUT_DOUBLE
,glFlush()
改为glutSwapBuffers()
,但它对我不起作用。
我使用的是带有NVIDIA GForce 7300 LE的Windows 10。当我在其他PC上运行我的程序时,它运行正常。所以 我的问题是什么?是关于我的显卡还是我的代码不正确?和 我该如何修理它?