How do I bind a texture in QtGui OpenGL?



  • Hello all,

    I'm newish to OpenGL, but not C++. I am wanting to learn more about OpenGL. I was able to follow along with the triangle example for QtGui's OpenGL stuff. However, I cannot figure out how to add a texture to OpenGL. I know how to do it via OpenGL in general and in Qt 4.8 you could use the bindTexture() function of a QGLWidget. However, since with Qt 5.0 they recommend you don't use that for new programs, I'd like to avoid using it. My hope is to be able to do something like the qt cube example (available here: http://qt-project.org/doc/qt-4.8/opengl-cube.html) but with using the QOpenGL classes instead of QGL classes. Can anyone help me with the texture binding information so I can use that instead? Thanks ahead of time.



  • Hi,

    bindTexture(image) does something like that:
    @
    QImage gl_image=convertToGLFormat(image);

    glGenTextures(1, &texture_id);
    glBindTexture(GL_TEXTURE_2D, texture_id);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gl_image.width(), gl_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, gl_image.bits());
    @
    "convertToGLFormat()":http://qt-project.org/doc/qt-5.0/qtopengl/qglwidget.html#convertToGLFormat being a static method of QGLWidget, look at the source code to see how it transforms the QImage to fit OpenGL format.

    Hope it helps.



  • Thank you for your reply. But we don't have access to glBindTextures in QOpenGLFunctions. How do I get access to it? I've added gl/GL.h and gl/GLu.h to my includes and still don't have access to the function. I'm trying to use the new OpenGL library included with GtGUI which doesn't support QGLWidgets. Since they say not to use QGLWidgets for new projects, I'd like to listen to them.

    EDIT: Nevermind, I stand corrected, including those files does allow me to use those functions. I'm not sure why it didn't the first time, but now that I've done it again, they're letting me. I'm leaving the above in case you were in the middle of commenting again.


  • Moderators

    I Qt5.2 will have a lot of updates in that area, thanks to Sean's work. I'm not into using QOpenGL so I did not follow the announcements closely, but here is the latest post: "link":http://lists.qt-project.org/pipermail/development/2013-March/010190.html.


Log in to reply
 

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