Qt 的 OpenGL 示例抱怨一些错误并且无法运行

发布于 2025-01-03 14:15:08 字数 1506 浏览 1 评论 0原文

我正在尝试在 ubuntu 10.04 中运行 OpenGL 示例。我勇敢地编译了如下 Qt 代码,结果非常棒。

./configure -prefix /home/user/Software/qt-4.7.4-openGL-without-opengl-graphics -xplatform linux-g++-32  -little-endian -opensource -debug-and-release -fast -exceptions -accessibility -stl -no-qt3support -xmlpatterns -multimedia -audio-backend  -svg -webkit-debug -script -scripttools -declarative -qt-zlib -qt-libpng -qt-libjpeg -qt-libmng -qt-libtiff  -make translations -make tools -make libs -opengl desktop -lglut

但出于对成功编译的满足,我尝试运行这些示例,但有些示例无法运行。首先,2dpainting 示例在打印以下内容后退出。

hijackWindow() context created for Window(0xbf8b0f2c) 1 
QGLPixelBuffer: Unable to find a context/format match - giving up.
QGLWindowSurface: Failed to create valid pixelbuffer, falling back 
QGLWindowSurface: Using plain widget as window surface QGLWindowSurface(0x8bf4990) 
hijackWindow() context created for Widget(0x8be5ab0) 2 
Vertex shader for simpleShaderProg (MainVertexShader & PositionOnlyVertexShader)  failed to compile
Fragment shader for simpleShaderProg (MainFragmentShader & ShockingPinkSrcFragmentShader) failed to compile
QGLShaderProgram: shader programs are not supported 
The program has unexpectedly finished.

盒子示例甚至没有被编译,给出以下错误。

qtbox.cpp: In member function 'virtual void QtBox::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)':
qtbox.cpp:327: error: 'gluPerspective' was not declared in this scope

有人可以告诉我我在这里做错了什么吗?

I am trying to run the OpenGL examples in ubuntu 10.04. I bravely compiled the Qt code as follows and it went fantastic.

./configure -prefix /home/user/Software/qt-4.7.4-openGL-without-opengl-graphics -xplatform linux-g++-32  -little-endian -opensource -debug-and-release -fast -exceptions -accessibility -stl -no-qt3support -xmlpatterns -multimedia -audio-backend  -svg -webkit-debug -script -scripttools -declarative -qt-zlib -qt-libpng -qt-libjpeg -qt-libmng -qt-libtiff  -make translations -make tools -make libs -opengl desktop -lglut

But then out of satisfaction I got from successful compilation I tried running the examples and some won't run. As a start the 2dpainting example quits after printing the following.

hijackWindow() context created for Window(0xbf8b0f2c) 1 
QGLPixelBuffer: Unable to find a context/format match - giving up.
QGLWindowSurface: Failed to create valid pixelbuffer, falling back 
QGLWindowSurface: Using plain widget as window surface QGLWindowSurface(0x8bf4990) 
hijackWindow() context created for Widget(0x8be5ab0) 2 
Vertex shader for simpleShaderProg (MainVertexShader & PositionOnlyVertexShader)  failed to compile
Fragment shader for simpleShaderProg (MainFragmentShader & ShockingPinkSrcFragmentShader) failed to compile
QGLShaderProgram: shader programs are not supported 
The program has unexpectedly finished.

And box example does not even get compiled, giving the following error.

qtbox.cpp: In member function 'virtual void QtBox::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)':
qtbox.cpp:327: error: 'gluPerspective' was not declared in this scope

Could some one tell me what I am doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月棠 2025-01-10 14:15:08

您还没有链接到-lGL

LIBS += -lGLU

并在代码中包含 glu.h 文件。

包含“GL/glu.h”

You have not linked to -lGL

LIBS += -lGLU

and include the glu.h file in your code.

include "GL/glu.h"

心凉怎暖 2025-01-10 14:15:08

GluPerspective 是 GLU 库的一部分,从较新的 (3.x?) 版本的 OpenGL 开始不受支持。更新示例的一个简单方法是编写您自己的替换,如下所示:

#include <QtOpenGL>

void gluPerspective(double fovy,double aspect, double zNear, double zFar)
{
 // Start in projection mode.
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 double xmin, xmax, ymin, ymax;
 ymax = zNear * tan(fovy * M_PI / 360.0);
 ymin = -ymax;
 xmin = ymin * aspect;
 xmax = ymax * aspect;
 glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}

GluPerspective is part of the GLU library, and not supported as of newer (3.x?) versions of OpenGL. An easy way to update the example is to write your own replacement, something like this:

#include <QtOpenGL>

void gluPerspective(double fovy,double aspect, double zNear, double zFar)
{
 // Start in projection mode.
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 double xmin, xmax, ymin, ymax;
 ymax = zNear * tan(fovy * M_PI / 360.0);
 ymin = -ymax;
 xmin = ymin * aspect;
 xmax = ymax * aspect;
 glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文