我正在尝试在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
有人可以告诉我这里做错了吗?
答案 0 :(得分:1)
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);
}
答案 1 :(得分:1)
您尚未链接到-lGL
LIBS + = -lGLU
并在您的代码中包含glu.h文件。
包括“GL / glu.h”