Hey,

I'm just trying to setup a minimal example trying to draw a textured quad and already failing on this one. Code looks like this:

Qt Code:
  1. class Foo : public QGLWidget
  2. {
  3. public:
  4. Foo( QWidget* parent ) : QGLWidget( parent )
  5. {
  6. }
  7.  
  8. void initializeGL( )
  9. {
  10. glDisable( GL_LIGHTING );
  11. glEnable( GL_TEXTURE_2D );
  12. glViewport( 0, 0, width( ), height( ) );
  13.  
  14. glMatrixMode( GL_PROJECTION );
  15. glLoadIdentity( );
  16.  
  17. gluPerspective( 45.0f, (GLfloat)width( ) / (GLfloat)height( ), 0.1f, 100.0f );
  18.  
  19. glMatrixMode( GL_MODELVIEW );
  20. glLoadIdentity( );
  21.  
  22. texId = bindTexture( "test.png" );
  23. }
  24.  
  25. void paintGL( ) override
  26. {
  27. glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
  28. glClear( GL_COLOR_BUFFER_BIT );
  29.  
  30. glLoadIdentity();
  31. glTranslatef( 0.0f, 0.0f, -6.0f );
  32. //drawTexture( rect( ), texId);
  33. glBegin( GL_QUADS );
  34. glTexCoord2f( 0.0f, 0.0f );
  35. glVertex3f( -1.0f, 1.0f, 0.0f );
  36. glTexCoord2f( 1.0f, 0.0f );
  37. glVertex3f( 1.0f, 1.0f, 0.0f );
  38. glTexCoord2f( 1.0f, 1.0f );
  39. glVertex3f( 1.0f, -1.0f, 0.0f );
  40. //glColor3f( 0.0f, 1.0f, 0.0f );
  41. glTexCoord2f( 0.0f, 1.0f );
  42. glVertex3f( -1.0f, -1.0f, 0.0f );
  43. glEnd( );
  44. }
  45.  
  46. private:
  47. GLuint texId;
  48. };
  49.  
  50. /*
  51.  * Application entry point.
  52.  */
  53. int main( int argc, char **argv )
  54. {
  55. QApplication app(argc, argv);
  56.  
  57. QMainWindow *window = new QMainWindow( );
  58. window->setFixedSize( 800, 600 );
  59. window->setWindowTitle( QString::fromUtf8( "test" ) );
  60.  
  61. QWidget *centralWidget = new QWidget( window );
  62. QVBoxLayout* layout = new QVBoxLayout( centralWidget );
  63. Foo* foo = new Foo( centralWidget );
  64. layout->addWidget( foo );
  65.  
  66. window->setCentralWidget( centralWidget );
  67. window->show( );
  68.  
  69. return app.exec( );
  70. }
To copy to clipboard, switch view to plain text mode 

I've also tried to manually bind the texture with glGenTexture, glBindTexture and converting the QImage to a OpenGL format and I've tried to experiment with drawTexture but nothing works. If I comment in the glColor line, my quad is rendered green, so it's definitely in my viewport. Am I maybe missing some other state variable or might this be a GL context problem?

Can I somehow double check that bindTexture worked as expected? Because texId will be 0 no matter if I input a valid or invalid filename. Are there any constraits about the texture's size? Because mine is 609x731.