问题描述
我尝试使用开始使用OpenGl进行编程,并且以下代码到目前为止:
I have attempted to start programming with OpenGl using this tutorial, and have the following code so far:
#include <gl/glut.h> // Include the GLUT header file
void display (void)
{
}
int main(int argc, char **argv)
{
glutInit(&argc, argv); // Initialize GLUT
// Set up a basic display buffer (only single buffered for now)
glutInitDisplayMode (GLUT_SINGLE);
glutInitWindowSize (500, 500); // Set the width and height of the window
glutInitWindowPosition (100, 100); // Set the position of the window
// Set the title for the window
glutCreateWindow("Your first OpenGL Window!");
glutDisplayFunc(display);
glutMainLoop();
glClearColor(1.f, 0.f, 0.f, 1.f); // Clear the background of our window to red
return 0;
}
我在Eclipse中构建和运行项目,发生(没有窗口弹出或任何东西)。任何人都可以告诉我我可能做错了什么?
I build and run the project in Eclipse, it compiles all fine, but nothing happens (no windows pop up or anything). Can anybody tell me what I could be doing wrong?
推荐答案
glutInitDisplayMode (GLUT_SINGLE);
您还需要定义所需的framebuffer格式,即添加 GLUT_RGBA
,至少(你可能还需要一个深度缓冲区)。并且只有少数情况下,一个不想要双缓冲区。所以: glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
You also need to define the kind of framebuffer format you want, i.e. add a GLUT_RGBA
, at least (and you probably also want a depth buffer). And there are only few cases where one not wants a double buffer. So: glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
然后你的显示功能不会被调用,除非你在 glutCreateWindow
后添加 glutDisplayFunc(display);
b
Then your display function will not be called, unless you add a glutDisplayFunc(display);
after glutCreateWindow
.
glutMainLoop();
glClearColor(1.f, 0.f, 0.f, 1.f);
glutMainLoop不返回。即使是这样,glClearColor在程序的那个地方没有效果。
glutMainLoop does not return. And even if it did, glClearColor had no effect at that place in the program.
这篇关于在C ++中开始使用OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!