QGLWidget在Mac OS X Lion下无法正常工作 [英] QGLWidget not working correctly under Mac OS X Lion
问题描述
如您所见-我不知道为什么它根本不起作用.
As you see -- I have no idea why it's not working at all.
程序运行时将如下所示:
When the program run, it will look like this:
我正在使用来自Macports的qt4-mac(v4.8.2).似乎该软件包已预先编译.
I'm using qt4-mac(v4.8.2) from macports. It seems that the package was pre-compiled.
这是来源:
main.cpp:
#include <iostream>
#include <QApplication>
#include "GLPlayerWindow.hpp"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
GLPlayerWindow window;
window.show();
window.resize(800, 600);
return app.exec();
}
GLPlayerWindow.hpp:
GLPlayerWindow.hpp:
#ifndef __GLPLAYERWINDOW__HPP__DEFINED__
#define __GLPLAYERWINDOW__HPP__DEFINED__
#include <string>
#include <QGLWidget>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QTimer>
#include <SimpleAV_SDL.h>
class GLPlayerWindow : public QGLWidget
{
Q_OBJECT
public:
GLPlayerWindow(QWidget *parent = NULL);
~GLPlayerWindow();
protected slots:
void paintGL();
protected:
void initializeGL();
void resizeGL(int w, int h);
void keyPressEvent(QKeyEvent *event);
};
#endif
GLPlayerWindow.cpp:
GLPlayerWindow.cpp:
#include <iostream>
#include "GLPlayerWindow.hpp"
#include <GL/glu.h>
GLPlayerWindow::GLPlayerWindow(QWidget *parent)
: QGLWidget(parent) {
setMouseTracking(true);
}
GLPlayerWindow::~GLPlayerWindow() {
}
void GLPlayerWindow::initializeGL() {
glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_POLYGON_SMOOTH);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(1.0f, 0.0f, 0.0f, 0);
}
void GLPlayerWindow::resizeGL(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, 0, h); // set origin to top left corner
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void GLPlayerWindow::paintGL() {
glClear(GL_COLOR_BUFFER_BIT);
return;
}
void GLPlayerWindow::keyPressEvent(QKeyEvent* event) {
}
.pro文件:
QT += opengl
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += link_pkgconfig
PKGCONFIG += libavcodec libavformat libavutil libswscale SimpleAV_SDL sdl SDL_mixer gl glu
# LIBS += `pkg-config --libs SimpleAV_SDL SDL_mixer sdl`
# CFLAGS += -g -O2 -Wall -W `pkg-config --cflags SimpleAV_SDL SDL_mixer sdl`
CFLAGS += -g -O2 -Wall -W
# Input
HEADERS += GLPlayerWindow.hpp
SOURCES += GLPlayerWindow.cpp main.cpp
推荐答案
好的,如果您在Mac下遇到相同的问题 ,请尝试在/System/Library/Frameworks/下链接GL实现AGL.framework/.有关详细信息,请参见此帖子:为什么glOrtho()在Mac上可运行但gluOrtho2D ()不是吗?
Ok guys if you are facing the same issue under Mac, try to link the GL implementation under /System/Library/Frameworks/AGL.framework/ . See this post for detail: Why glOrtho() works under Mac but gluOrtho2D() doesn't?
这篇关于QGLWidget在Mac OS X Lion下无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!