Results 1 to 15 of 15

Thread: old problem with QGLContext and render pixmap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: old problem with QGLContext and render pixmap

    take it. thanks
    Attached Files Attached Files
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: old problem with QGLContext and render pixmap

    What does plain.initGL() do?

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: old problem with QGLContext and render pixmap

    it initialize every textures....gen tex, bind....plain it's an object and onto this I put the texture...
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: old problem with QGLContext and render pixmap

    Quote Originally Posted by mickey
    it initialize every textures....gen tex, bind....
    That's the place where the problem is. Can I see it?

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: old problem with QGLContext and render pixmap

    it's very complicated. Can I mail it you? thanks
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: old problem with QGLContext and render pixmap

    Quote Originally Posted by mickey
    Can I mail it you?
    Yes, you can.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: old problem with QGLContext and render pixmap

    Here's the problematic part:
    Qt Code:
    1. void Plain::initGL() {
    2. ...
    3. glGenTextures(dimX*dimZ, tex);
    4. glGenTextures(1, &lastTex);
    5. ...
    6. glBindTexture(GL_TEXTURE_2D, lastTex );
    7. ...
    8. glBindTexture(GL_TEXTURE_2D, tex[contite]);
    9. ...
    10. }
    To copy to clipboard, switch view to plain text mode 
    Every time you invoke Plain::initGL() new textures are generated. The images are stored inside OpenGL context (represented by QGLContex) and your program receives only ID numbers of those textures (that's what you store in tex and lastTex).

    Now if you invoke initGL() for the second time (within the same context), tex and lastTex will be filled with new values --- the old textures will be still in memory, but you won't be able to access them, since those variables will hold IDs of the new textures. It's not a big problem (except for the resource leak).

    But what happens when you invoke initGL() within a different context (just like it happens during renderPixmap())? initGL() will generate new textures, that will be stored in a new context, and it will store their IDs in tex and lastTex (the same ones, since you have only one Plain object). Now when renderPixmap() ends, it destroys that temporary context and the new textures are destroyed too, but tex and lastTex still hold their IDs. The problem is that when you will try to draw something later, you will use invalid texture IDs.

    You can solve this problem like this:
    Qt Code:
    1. void GlWidget::renderPixmap(...)
    2. {
    3. plain.store();
    4. QPixmap result( QGLWidget::renderPixmap( ... ) );
    5. plain.restore();
    6. return result;
    7. }
    8. ...
    9. void Plain::store()
    10. {
    11. // copy tex and lastTex values somewhere
    12. // for example onto QValueStack
    13. }
    14.  
    15. void Plain::restore()
    16. {
    17. // restore tex and lastTex values
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 14th July 2006 at 15:31.

  8. The following user says thank you to jacek for this useful post:

    mickey (21st July 2006)

  9. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: old problem with QGLContext and render pixmap

    I'm thinking to your solution...and other troubles arise: is there a way to clean the contextGL? (in the same way when app started)
    then, I see that renderPixmap render my scene ok but don't render right texture multitextured; is it right? thanks
    Regards

  10. #9
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: old problem with QGLContext and render pixmap

    your solution is ok!! but when I save pixmap into a .jpg the texture multitextured appear gray oe black; if i don't use multitexture they appear ok! does depends it from qt3??Can i solve it? thanks
    Furthermore: the objcet appear with same lines that they aren't visible in glWidget; eg: in square textured is visible a diagonal line (only in .jpg not in glWidget) what's it???
    Last edited by mickey; 21st July 2006 at 01:25.
    Regards

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.