[Interest] renderPixmap and textures

Guido Seifert wargand at gmx.de
Sat Nov 10 22:45:49 CET 2012


Hi,
I try to apply a texture to a rectangle in OpenGL and get the results in
a QImage using renderPixmap. Problem is, everything seems to work, the
QGLWidget shows the desired result, but in the rendered Pixmap the
texture is not there. The code works fine under Linux, the problem is
Windows only.

Of course I read the docs:
Note that under Windows a temporary context has to be created...

I think I am doing this, but I am not too experienced (not at all) with OpenGL.

Below is my initializeGL() and paintGL(). As you can see, praktically
everything is in initializeGL(), so I am really wondering, what could I
have done wrong. Any ideas? 

Guido

---------------------------------------------------------

void GLWidget2::initializeGL(void)
{
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glColor3f(1.0f, 1.0f, 1.0f);
    int texture = bindTexture(QImage("./Nature025.jpg"),GL_TEXTURE_2D);
    glEnable(GL_TEXTURE_2D);
    glOrtho(-540.0*1.777, 540.0*1.777, -540.0, 540.0, 1.0, -1.0);
    glBindTexture(GL_TEXTURE_2D,texture);

    index = glGenLists(1);

    glNewList(index, GL_COMPILE);
    float w=800;
    float width  = w*1.777;
    float height = w;
    glBegin(GL_QUADS);
     glTexCoord2f(1.0,1.0);
     glVertex2f(-width/2.0,  height/2.0);

     glTexCoord2f(0.0, 1.0);
     glVertex2f( width/2.0,  height/2.0);

     glTexCoord2f(0.0,0.0);
     glVertex2f( width/2.0, -height/2.0);

     glTexCoord2f(1.0, 0.0);
     glVertex2f(  -width/2.0, -height/2.0);
    glEnd();
    glEndList();
}

void GLWidget2::paintGL(void)
{
    glCallList(index);
}
 



More information about the Interest mailing list