Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. How do I bind a texture in QtGui OpenGL?
Forum Updated to NodeBB v4.3 + New Features

How do I bind a texture in QtGui OpenGL?

Scheduled Pinned Locked Moved Game Development
4 Posts 3 Posters 4.8k 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.
  • H Offline
    H Offline
    hatfarm
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tilsitt
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hatfarm
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          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