Hi,
I' trying to do a minimal OpenGL Image Viewer. Here's the code:
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.Code:
{ QPixmap pixmap; public: , pixmap(_pixmap) { } void resizeGL(int w, int h) { glViewport(0, 0, w, h); } void paintGL() { glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, width(), 0, height(), -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); bindTexture ( pixmap, GL_TEXTURE_2D, GL_RGBA ); glBegin (GL_QUADS); glTexCoord2f (0.0, 0.0); glVertex3f (10.0, 10.0, 0.0); glTexCoord2f (1.0, 0.0); glVertex3f (width()-10, 10.0, 0.0); glTexCoord2f (1.0, 1.0); glVertex3f (width()-10, height()-10, 0.0); glTexCoord2f (0.0, 1.0); glVertex3f (10.0, height()-10, 0.0); glEnd (); /*glBegin(GL_TRIANGLES); glColor3ub(255, 0, 0); glVertex2d(0, 0); glColor3ub(0, 255, 0); glVertex2d(width(),0); glColor3ub(0, 0, 255); glVertex2d(width()/2, height()); glEnd();*/ } };
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.