[英]OpenGL “black screen” frustration
我仍在嘗試找出為什么我只能看到典型的“黑屏”。 我只渲染一個矩形,但是什么也沒發生。
#include "expwidget.h"
#include <iostream>
ExpWidget::ExpWidget(QObject *parent) :
QGLWidget(QGLFormat(QGL::DoubleBuffer), (QWidget *) parent)
{
QGLFormat fmt = this->format();
fmt.setDepth(true);
this->setFormat(fmt);
}
void ExpWidget::initializeGL() {
QGLWidget::initializeGL();
std::cout << "inicializace...\n";
glClearColor(0.0f,0.0f,0.0f,0.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
}
void ExpWidget::paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(1, 0, .5);
glBegin(GL_QUADS);
glVertex3f(-1.0f,-1.0f,-5.0f);
glVertex3f(1.0f,-1.0f,-5.0f);
glVertex3f(1.0f,1.0f,-5.0f);
glVertex3f(-1.0f,1.0f,-5.0f);
glEnd();
glFlush();
}
void ExpWidget::resizeGL(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-2.0, 2.0, -2.0, 2.0, 0.0, -30.0);
glMatrixMode(GL_MODELVIEW);
}
過去我也遇到過類似的問題,但是我並沒有聲稱自己是專家。
調用glFrustum
的形式為glFrustum(left, right, bottom, top, near, far)
near
和far
必須同時為正和非零。 ( http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml )
因此,根據您的情況,我建議將您的通話更改為:
glFrustum(-2.0, 2.0, -2.0, 2.0, 1.0, 30.0);
另外,您的坐標應具有負Z值以在此視圖中渲染。
http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml :
nearVal, farVal
Specify the distances to the near and far depth clipping planes. Both distances must be positive.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.