Changsheng_S
2016-01-07 04:55
采纳率: 100%
浏览 2.0k

OpenGL初学,请问我这段代码有错吗?为什么在窗口显示不出来

#include
#include
#include
#include
#include

const GLint screenWidth = 640;
const GLint screenHeight = 480;

void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)screenWidth, 0.0, (GLdouble)screenHeight);
}
void checkerboard(void)
{
for(GLint i = 0; i < 8; i++)
{
for(GLint j = 0; j < 8; j++)
{
if((i+j)%2 == 0)
{
glColor3f(0.0f, 0.0f, 0.0f);
}
else
{
glColor3f(1.0f, 1.0f, 1.0f);
}
glRecti(30*j, 30*i, 30*(j+1), 30*(i+1));
}
}
glFlush();
}

void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
checkerboard();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(screenWidth, screenHeight);
glutInitWindowPosition(0, 0);
glutCreateWindow("chess");
glutDisplayFunc(myDisplay);

myInit();
glutMainLoop();

}

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题