GLUT工作正常,但OpenGL没有做任何事情 [英] GLUT is working fine but OpenGL is not doing anything
问题描述
完全相同的代码片段正在另一台机器上工作,但它不适合我。 GLUT在打开创建的窗口时工作得很好,但窗口中没有显示线段,这意味着opengl存在问题。它甚至不会改变窗口的背景颜色。
The exact same code snippet is working on another machine but its not working properly for me. The GLUT is working absolutely fine as it open the created window but the line segment is not shown on the window which means there is a problem with opengl. It is not even changing the background color of the window.
我甚至用测试应用程序在我的windows上测试opengl,它的工作正常。
I even test the opengl on my windows with a testing application and its working fine.
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
void init(void){
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 400.0, 0.0, 400.0);
}
void linesegment(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex2i(180, 15);
glVertex2i(10, 145);
glEnd();
glFlush();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(50, 50);
glutInitWindowSize(400, 400);
glutCreateWindow("Testing Open GL");
init();
glutDisplayFunc(linesegment);
glutMainLoop();
return 0;
}
推荐答案
您正在遇到由合成图形系统(Windows中的Aero,MacOS X上的Quartz Extreme以及Linux / X11上的各种程序)引入的相当新类别的问题。问题的要点是,合成本身是双缓冲的:窗口总是有一个离屏(后退)缓冲区。当一个程序显示它已完成绘图时,合成器会将其集成到屏幕图像中。
Most likely you're running into the rather new class of problems introduced by compositing graphics systems (Aero in Windows, Quartz Extreme on MacOS X and a multitude of various programs on Linux/X11). The gist of the problem is, that compositing is inherently double buffered: There's always an offscreen (back) buffer for the window to be drawn. And when a program indicates that it's finished with drawing the compositor will integrate it into the on-screen image.
然而这带来了一些警告。最重要的是,单个缓冲绘图不知何故需要表明它已完成。虽然从实现者的角度来看OpenGL的 glFinish
调用应该足够了,但大多数合成系统对它并不敏感。您必须创建一个双缓冲窗口像素格式并进行缓冲区交换,以使合成器呈现您的图像。
This however brings a few caveats. Most importantly, single buffered drawing somehow needs to indicate that it's finished. While OpenGL's glFinish
call should suffice from a implementors point of view, most compositing systems are not sensitive to it. You'll have to create a double buffered window pixel format and do a buffer swap to make the compositor present your image.
所以对于您的程序:
- 中用
GLUT_DOUBLE
替换GLUT_SINGLE
c $ c> glutInitDisplayMode - 用
替换
glFlush
> glutSwapBuffers
- replace
GLUT_SINGLE
withGLUT_DOUBLE
inglutInitDisplayMode
- replace
glFlush
withglutSwapBuffers
这篇关于GLUT工作正常,但OpenGL没有做任何事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!