1
當試圖在QT上繪製一個OpenGL小部件時,窗口顯示結束而失真。 所有這些都是屏幕被清除。QT和OpenGL的奇怪行爲
Screenshot http://img508.imageshack.us/img508/9950/screenshotofd.png
#include "glwidget.h"
// Mainwidget is a sub-class of GLWidget
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
}
void GLWidget::resizeGL(int width,int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
GLWidget::~GLWidget()
{
;
}
#include <QtGui>
#include "mainwidget.h"
MainWidget::MainWidget()
{
//this->showFullScreen();
derp = 100;
}
void MainWidget::paintGL()
{
glClearColor(0, 0, 0, 0);
//drawTriangle(0, 0, 100, 100, derp, 0);
derp = rand()%500;
}
void MainWidget::initializeGL()
{
this->resizeGL(800, 600);
}
void MainWidget::drawTriangle(int x1,int y1, int x2, int y2, int x3, int y3)
{
glBegin(GL_TRIANGLES);
glVertex3f(x1, y1, 0.0f);
glVertex3f(x2, y2, 0.0f);
glVertex3f(x3, y3, 0.0f);
glEnd();
}
#include <QtGui>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{
QGridLayout *layout = new QGridLayout;
QTimer *timer = new QTimer(this);
MainWidget *View = new MainWidget();
layout->addWidget(View, 0, 0);
setLayout(layout);
connect(timer, SIGNAL(timeout()), View, SLOT(paintGL()));
timer->start(50);
}
啊,這是有道理的。謝謝一堆。 – Naberius 2011-04-06 19:31:11