PDA

View Full Version : problem with bindTexture



spud
6th January 2008, 13:57
Hi,
I' trying to do a minimal OpenGL Image Viewer. Here's the code:


class ImageWidget : public QGLWidget
{
QPixmap pixmap;
public:
ImageWidget(const QPixmap &_pixmap, const IO& _io, QWidget *parent=0)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
, 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();*/
}
};
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.

jacek
6th January 2008, 15:15
Do you enable texturing with glEnable( GL_TEXTURE_2D ) anywhere in your code?

spud
6th January 2008, 15:50
That's it!