necesito ayuda con opengl y qtcreator

hola amigos del foro, he copiado el codigo de un tutorial conocido y tengo este codigo:

mipanelopengl.h

#ifndef MIPANELOPENGL_H
#define MIPANELOPENGL_H

#include

class mipanelopengl : public QGLWidget
{
Q_OBJECT
public:
explicit mipanelopengl(QWidget *parent = 0);
protected:
void iniciarGL();
void pintarGL();
void resizeGL(int w, int h);
private:
int lados;
double radio;

signals:

public slots:
void cambiarlados(int s);
void cambiarradio(int r);

};

#endif // MIPANELOPENGL_H

y luego:

mipanelopengl.cpp

#include "mipanelopengl.h"
#include
#include
#include "GL/glu.h"

mipanelopengl::mipanelopengl(QWidget *parent) :
QGLWidget(parent)
{

}
void mipanelopengl::iniciarGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

}
void mipanelopengl::pintarGL()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(5.0, 5.0, 0.0);
glLineWidth(1);
glColor3f(0, 0.7f, 0.7f);
glBegin(GL_POLYGON);
glVertex2f(1.0,1.0);
glVertex2f(5.0,5.0);
glVertex2f(10.0,10.0);
glEnd();

}
void mipanelopengl::resizeGL(int width,int height)
{
double xMin = 0, xMax = 10, yMin = 0, yMax = 10;
glViewport(0,0,(GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1,1,-1,1);
if (width > height){
height = height?height:1;
double newWidth = (xMax - xMin) * width / height;
double difWidth = newWidth - (xMax - xMin);
xMin = 0.0 + difWidth / 2.0;
xMax = 10 + difWidth / 2.0;
} else {
width = width?width:1;
double newHeight = (yMax - yMin) * width / height;
double difHeight = newHeight - (yMax - yMin);
yMin = 0.0 + difHeight / 2.0;
yMax = 10 + difHeight / 2.0;
}
gluOrtho2D(xMin, xMax, yMin, yMax);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

void mipanelopengl::cambiarlados(int s)
{
lados=3;
updateGL();

}
void mipanelopengl::cambiarradio(int r)
{
radio=1;
updateGL();

}
El problema es que me muestra el widget imagenes distorsionadas y borroneadas y ningun poligono, probe desinstalando qt creator y volverlo a instalar y me sigue mostrando mal la pantalla. No se cual puede ser el problema. Espero una ayuda, se los agradeceria amablemente.

initializeGL() y paintGL() != iniciarGL() y pintarGL()

Un detalle importante, los métodos iniciarGL() y pintarGL() están mal, los nombres correctos son initializeGL() y paintGL() respectivamente, no podes traducirlos ni cambiarles el nombre porque son métodos protegidos de QGLWidget.

graciassssssssss

ya probe poniendo los metodos en ingles y me funciona perfecto, era ese mi error. muchas gracias amigo

Anuncios Google