Reputation: 6756
I am still trying to figure out, why i see only typical "black screen". I render just one rectangle, but nothing happened.
#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);
}
Upvotes: 0
Views: 1841
Reputation: 524
I've faced a similar problem in the past, but I don't claim to be an expert.
Calls to glFrustum
are in the form glFrustum(left, right, bottom, top, near, far)
near
and far
must both be positive and non-zero. (http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml)
so in your case I would recommend changing your call to:
glFrustum(-2.0, 2.0, -2.0, 2.0, 1.0, 30.0);
Also, your coordinates should have negative Z to render in this view.
Upvotes: 2
Reputation: 1719
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.
Upvotes: 1