Results 1 to 3 of 3

Thread: problem with bindTexture

  1. #1
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default problem with bindTexture

    Hi,
    I' trying to do a minimal OpenGL Image Viewer. Here's the code:
    Qt Code:
    1. class ImageWidget : public QGLWidget
    2. {
    3. QPixmap pixmap;
    4. public:
    5. ImageWidget(const QPixmap &_pixmap, const IO& _io, QWidget *parent=0)
    6. : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
    7. , pixmap(_pixmap)
    8. {
    9. }
    10. void resizeGL(int w, int h)
    11. {
    12. glViewport(0, 0, w, h);
    13. }
    14. void paintGL()
    15. {
    16. glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
    17. glLoadIdentity();
    18.  
    19. glMatrixMode(GL_PROJECTION);
    20. glPushMatrix();
    21. glLoadIdentity();
    22.  
    23. glOrtho(0, width(), 0, height(), -1, 1);
    24. glMatrixMode(GL_MODELVIEW);
    25. glPushMatrix();
    26. glLoadIdentity();
    27.  
    28. bindTexture ( pixmap, GL_TEXTURE_2D, GL_RGBA );
    29. glBegin (GL_QUADS);
    30. glTexCoord2f (0.0, 0.0); glVertex3f (10.0, 10.0, 0.0);
    31. glTexCoord2f (1.0, 0.0); glVertex3f (width()-10, 10.0, 0.0);
    32. glTexCoord2f (1.0, 1.0); glVertex3f (width()-10, height()-10, 0.0);
    33. glTexCoord2f (0.0, 1.0); glVertex3f (10.0, height()-10, 0.0);
    34. glEnd ();
    35. /*glBegin(GL_TRIANGLES);
    36. glColor3ub(255, 0, 0);
    37. glVertex2d(0, 0);
    38. glColor3ub(0, 255, 0);
    39. glVertex2d(width(),0);
    40. glColor3ub(0, 0, 255);
    41. glVertex2d(width()/2, height());
    42. glEnd();*/
    43. }
    44. };
    To copy to clipboard, switch view to plain text mode 
    The problem is I just see a white rectangle instead of the image. The commented code draws a triangle just fine, so I seem to have set up the viewport correctly.
    I'm probably making some very simple mistake, so I'm thankful for any suggestions!

    btw. Should I move any code from paintGL() to initGL()? I'm not sure if I have to make all of these calls every time I render the scene.

  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: problem with bindTexture

    Do you enable texturing with glEnable( GL_TEXTURE_2D ) anywhere in your code?

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

    spud (6th January 2008)

  4. #3
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem with bindTexture

    That's it!

Similar Threads

  1. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  3. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.