Qt problem on white opengl texture



  • Hello and been following tutorials and wanted to pass them nehe qt, but when I wanted to do texture mapping texture is always blank, and tested with external libraries and feel the same, I pass my code to see if they find the problem

    Tutorial5.h
    @#ifndef TUTORIAL5_H
    #define TUTORIAL5_H

    #include <QGLWidget>
    #include <QTimer>
    #include <QDebug>
    #include <Qimage>
    #include <QString>
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include "SOIL.h"

    class Tutorial5 : public QGLWidget
    {
    Q_OBJECT
    public:
    explicit Tutorial5(QGLWidget *parent = 0);

    signals:

    public slots:

    private slots:
    void myUpdate();

    private:
    void initializeGL();
    void resizeGL(int ancho, int alto);
    void paintGL();
    void loadTextures();

    QTimer myTimer;
    GLfloat rotPiramide;
    GLfloat rotCuadrado;
    GLuint texture[1];
    

    };

    #endif // TUTORIAL5_H
    @

    Tutorial5.cpp
    @
    #include "tutorial5.h"

    Tutorial5::Tutorial5(QGLWidget *parent) :
    QGLWidget(parent)
    {

    rotPiramide = 0.0f;
    rotCuadrado = 0.0f;
    connect(&myTimer, SIGNAL(timeout()), this, SLOT(myUpdate()));
    myTimer.start(0);
    

    }

    void Tutorial5::initializeGL()
    {

    loadTextures();

    glEnable( GL_BLEND );
    glShadeModel( GL_SMOOTH );
    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
    
    glClearDepth( 1.0f );
    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LEQUAL );
    
    glHint( GL_PERSPECTIVE_CORRECTION_HINT , GL_NICEST );
    

    }

    void Tutorial5::resizeGL(int ancho, int alto)
    {
    if( alto == 0)
    {
    alto = 1;
    }

    glViewport( 0, 0, (GLsizei) ancho, (GLsizei) alto );
    glLoadIdentity();
    
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    
    gluPerspective( 45.0f, (GLdouble)ancho / (GLdouble)alto, 0.1f, 100.0f );
    
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    

    }

    void Tutorial5::paintGL()
    {

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glLoadIdentity();
    
    glTranslatef( -1.5f, 0.0f, -6.0f );
    
    
    glEnable(GL_TEXTURE_2D);
    glBindTexture (GL_TEXTURE_2D, texture[0]);
    glBegin( GL_QUADS );
    
     glTexCoord2f(0.0f, 0.0f); glVertex3f (-1.0f,-1.0f, 1.0f);  // izquierdo inferior de la textura y el Quad
     glTexCoord2f (1.0f, 0.0f); glVertex3f (1.0f,-1.0f, 1.0f);  // inferior derecha de la textura y el Quad
     glTexCoord2f (1.0f, 1.0f); glVertex3f (1.0f, 1.0f, 1.0f);  // superior derecha de la textura y el Quad
     glTexCoord2f (0.0f, 1.0f); glVertex3f (-1.0f, 1.0f, 1.0f);  // superior izquierda de la textura y el Quad
    glEnd();
    

    }

    void Tutorial5::myUpdate()
    {
    rotPiramide += 0.2f;
    rotCuadrado -= 0.15f;
    updateGL();
    }

    void Tutorial5::loadTextures()
    {
    QImage t;
    QImage b;

    b.load("/Data/nehe.bmp");
    
    
    t = QGLWidget::convertToGLFormat( b );
    glGenTextures( 1, &texture[0] );
    glBindTexture( GL_TEXTURE_2D, texture[0] );
    glTexImage2D( GL_TEXTURE_2D, 0, 3, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    

    }
    @



  • Which tutorial is this from please? This is teaching legacy OpenGL coding



  • BTW in Qt 5.2 you will be able to use "QOpenGLTexture":http://doc-snapshot.qt-project.org/qt5-stable/qopengltexture.html#details


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.