Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt problem on white opengl texture
Qt 6.11 is out! See what's new in the release blog

Qt problem on white opengl texture

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pablovalo
    wrote on last edited by
    #1

    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 );
    

    }
    @

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

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

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3

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

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved