Results 1 to 9 of 9

Thread: Textures + Multiple QGLWidgets

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question Textures + Multiple QGLWidgets

    Hello all...

    I'm working a project where I have a QWorkspace containing many sub-classed QGLWidgets, and I'm running into problems. Before I get into those, I'd like to ask some generic questions (which may give me some insight on my below problems):

    1. With multiple QGLContexts, will I need to bind the same textures to each QGLWidget to get the texture to show up, or do they share texture data?

    Now, what I'm currently doing is loading the textures into OGL from my QMainWindow widget - not from any of my QGLWidgets. I am doing this because I want all current and future QGLWidgets to know about whatever textures I am loading. I can envision two scenarios if this is incorrect:

    1. I need to go to at least one QGLWidget and load the texture, which all other current and future QGLWidgets would then know about

    2. I need to go to all current QGLWidgets and load the texture, then all future QGLWidgets would need to load the texture(s) when they are initialized

    Personally, I'd like to be able to do it externally to my QGLWidgets and be done with it.

    With my current method, I load in my texture... but when I display it, I get a white model (no textures).

    Here's what I'm doing. This first section is where I load in the texture:
    Qt Code:
    1. GLuint texture;
    2. glGenTextures(1, &texture);
    3. glBindTexture(GL_TEXTURE_2D, texture);
    4. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    5. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    6. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    7. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    8. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    9. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    10. int depth;
    11. if(T.GetBPP() == 24)
    12. {
    13. depth = GL_RGB;
    14. }
    15. else
    16. {
    17. depth = GL_RGBA;
    18. }
    19. glTexImage2D(GL_TEXTURE_2D, 0, depth, T.GetWidth(), T.GetHeight(), 0, depth, GL_UNSIGNED_BYTE, T.GetData());
    To copy to clipboard, switch view to plain text mode 
    As I'm just trying to make the thing "work" for now, I've simplified it - it's not really very usable beyond one texture.

    texture - This holds my unique texture ID. I make sure it is unique through the use of glGenTextures()

    T - This is a texture class I use... it decoded a bitmap file and holds the important data from it (I'd rather use this than the Qt equivalent loader for this application. I've checked that it has valid data).

    I have glEnable(GL_TEXTURE_2D) in my initializeGL() function

    That covers the loading of the texture. Now when I draw the model:
    Qt Code:
    1. ...
    2. const Triangle * T = &TT->GetOList()[i]->GetConst();
    3. assert(T);
    4. if(T->GetTextureNumber() != 0xFFFFFFFF)
    5. {
    6. glBindTexture(GL_TEXTURE_2D, T->GetTextureNumber());
    7. }
    8. glBegin(GL_TRIANGLES);
    9. for(char j = 0; j < 3; j++)
    10. {
    11. if(renderMode == GL_RENDER)
    12. {
    13. //glColor3ubv(!j?Yellow:j==1?Red:Green);
    14. if(T->GetTextureNumber() != 0xFFFFFFFF)
    15. {
    16. glTexCoord2fv((*T).GetTexture(j)->GetConst().GetFloatStyle());
    17. }
    18. }
    19. glNormal3fv((*T)[j].GetNormal().GetFloatStyle());
    20. glVertex4fv((*T)[j].GetConst().GetFloatStyle());
    21. }
    22. glEnd();
    23. ...
    To copy to clipboard, switch view to plain text mode 
    I tried to display just the interesting portion of the draw code... basically, for each triangle, I do textures, then normals, then the vertex. I bind the texture before the glBegin() function.

    I'm starting to run out of ideas on what I'm missing
    Last edited by jacek; 13th July 2006 at 11:45. Reason: post date has been changed to restore thread order
    Life without passion is death in disguise

Similar Threads

  1. Opengl - Textures - Qt
    By Alex63 in forum Installation and Deployment
    Replies: 1
    Last Post: 29th June 2006, 09:32
  2. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23
  3. Multiple shortuts for the action
    By Lemming in forum Qt Programming
    Replies: 6
    Last Post: 6th April 2006, 22:29
  4. Replies: 25
    Last Post: 15th January 2006, 00:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.