gpt4 book ai didi

qt - QGLWidget 在 Mac OS X Lion 下无法正常工作

转载 作者:行者123 更新时间:2023-12-01 08:07:41 27 4
gpt4 key购买 nike

如您所见——我不知道为什么它根本不起作用。

当程序运行时,它看起来像这样:broken display

我正在使用来自 macports 的 qt4-mac(v4.8.2)。看来这个包是预编译的。

这是来源:

主要.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:

#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:

#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/AGL.framework/下的 GL 实现。有关详细信息,请参阅此帖子:Why glOrtho() works under Mac but gluOrtho2D() doesn't?

关于qt - QGLWidget 在 Mac OS X Lion 下无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12209727/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com