Results 1 to 3 of 3

Thread: Switching textures in opengl??

  1. #1
    Join Date
    Aug 2006
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Switching textures in opengl??

    Hi!
    Im using qt and opengl to show data from a buffer as textures in opengl. The buffer has several sub images that I want to switch between. The problem is that It wont switch.
    My QGLWidget has a method for updating the gl content where a pointer to the beginning of the buffer as argument. Then the textures made.
    Qt Code:
    1. void GLWidget::setTexture(unsigned char *_data, float transfer, int dispChannelOne, int dispChannelTwo, int dispChannelThree)
    2. {
    3. displayChannels = dispChannelOne + dispChannelTwo + dispChannelThree;
    4. channelOne = dispChannelOne;
    5. channelTwo = dispChannelTwo;
    6. channelThree = dispChannelThree;
    7. textureData = _data;
    8.  
    9. glEnable(GL_TEXTURE_2D);
    10. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    11.  
    12. // Update the texture for channel one
    13. if(channelOne == 1) {
    14. glBindTexture(GL_TEXTURE_2D, texture[0]);
    15. glTexImage2D(GL_TEXTURE_2D, 0,
    16. GL_LUMINANCE,
    17. 512, 512, 0,
    18. GL_LUMINANCE,
    19. GL_UNSIGNED_BYTE,
    20. textureData+0*512*512);
    21. }
    22. // Update the texture for channel two
    23. if(channelTwo == 1) {
    24. glBindTexture(GL_TEXTURE_2D, texture[1]);
    25. glTexImage2D(GL_TEXTURE_2D, 0,
    26. GL_LUMINANCE,
    27. 512, 512, 0,
    28. GL_LUMINANCE,
    29. GL_UNSIGNED_BYTE,
    30. textureData + 1*512*512); // + subchannels * widht * height
    31. }
    32. // Update the texture for channel three
    33. if(channelThree == 1) {
    34. glBindTexture(GL_TEXTURE_2D, texture[2]);
    35. glTexImage2D(GL_TEXTURE_2D, 0,
    36. GL_LUMINANCE,
    37. 512, 512, 0,
    38. GL_LUMINANCE,
    39. GL_UNSIGNED_BYTE,
    40. textureData + 2*512*512); // + subchannels * widht * height
    41. }
    42. updateGL();
    43. }
    44. void GLWidget::paintGL()
    45. {
    46.  
    47. // Clear color buffer
    48. glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
    49. glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
    50. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    51. //glClear( GL_COLOR_BUFFER_BIT );
    52.  
    53. // Set up the camera and projection
    54. // Select and setup the projection matrix
    55. glMatrixMode( GL_PROJECTION );
    56. glLoadIdentity();
    57.  
    58. gluOrtho2D( -1.0f, 1.0f, -1.0f, 1.0f );
    59. glViewport( 0, 0, 512, 512);
    60. if(hasTexture) {
    61. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    62. glEnable(GL_TEXTURE_2D);
    63. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    64. if(channelOne == 1 && channelTwo == 0)
    65. glBindTexture(GL_TEXTURE_2D, texture[0]);
    66. if(channelOne == 0 && channelTwo == 1)
    67. glBindTexture(GL_TEXTURE_2D, texture[1]);
    68. }
    69. glBegin( GL_QUADS );
    70. glTexCoord2f( 1.0f, 0.0f );
    71. glVertex2f( -1.0f, -1.0f );
    72.  
    73. glTexCoord2f( 0.0f, 0.0f );
    74. glVertex2f( 1.0f, -1.0f );
    75.  
    76. glTexCoord2f( 0.0f, 1.0f );
    77. glVertex2f( 1.0f, 1.0f );
    78.  
    79. glTexCoord2f( 1.0f, 1.0f );
    80. glVertex2f( -1.0f, 1.0f );
    81. glEnd();
    82. }
    To copy to clipboard, switch view to plain text mode 
    I can se the second texture but cannot switch to the first.
    Last edited by Randulf; 18th September 2006 at 16:51.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Switching textures in opengl??

    Qt Code:
    1. if(channelOne == 1 && channelTwo == 0)
    To copy to clipboard, switch view to plain text mode 
    Maybe this condition is never met?

  3. #3
    Join Date
    Aug 2006
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Switching textures in opengl??

    Found the problem, it only took me 4 hours : )

    When generating the textures glTexParameteri must be set for all textures.

Similar Threads

  1. Opengl - Textures - Qt
    By Alex63 in forum Installation and Deployment
    Replies: 1
    Last Post: 29th June 2006, 09:32
  2. help on openGL context
    By mickey in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2006, 19:21
  3. Qt's optimized OpenGL context switching
    By sverhoff in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 16:40
  4. Example OpenGL project?
    By brcain in forum Qt Tools
    Replies: 9
    Last Post: 23rd February 2006, 21:17
  5. problems with Opengl
    By SlawQ in forum Qt Programming
    Replies: 4
    Last Post: 12th February 2006, 22:49

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.