Texture Mapping

Hi,

I’m trying to map a basic texture of a box to a quad.

However all I’m seeing is what is in image 1.

If I draw a dot of 1 pixel size in the image, then I start seeing what is in image 2.

My code is:

void gl::initializeGL()
{
    LoadGLTexture();

    #ifndef QT_OPENGL_ES_2
        glEnable(GL_TEXTURE_2D);
    #endif
    glClearColor(0, 0, 0, 0); //black background with 0 alpha

    BuildList();
}

void gl::paintGL()
{
    glClearColor(0, 0, 0, 0); //black background with 0 alpha
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //Draw Background texture
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glCallList(m_iBackgroundSquare);
}
void gl::BuildList()
{
    //Background display list
    m_iBackgroundSquare = glGenLists(1);
    glNewList(m_iBackgroundSquare, GL_COMPILE); //New Compiled box Display List
        glBegin(GL_QUADS);
            //Bottom Left
            glTexCoord2f(-1.0f, -1.0f);
            glVertex2f(-1.0f, -1.0f);

            //Bottom Right
            glTexCoord2f(1.0f, -1.0f);
            glVertex2f(300,-1.0f);

            //Top Right
            glTexCoord2f(1.0f, 1.0f);
            glVertex2f(300, 300);

            //Top Left
            glTexCoord2f(0.0f, 1.0f);
            glVertex2f(0.0f, 300);
        glEnd();
    glEndList();
}

I re-used the code from another program that I have that loads images just fine, no idea why I’m getting such wierd results all of a sudden.

The image I’m trying to display is in image 3.

So to me it looks like the mapping went awry and it’s massively zoomed in.

Try these things:

Use white color for each vertex.
Use texture replace environment mode. If I remember well, the default mode is to modulate. See this old thread for example.

Also, consider moving to a modern version of OpenGL. What you are using is really old.

Well, at least now I understand that the blob is appropriate behaviour. With a white single pixel box on each corner of the image I get the result as can be seen in the attachment. So obviously, the image is just massively stretched. If I change all the 300 values to 1.0f, then everything works as expected.

Wonder what the difference is between my other program that works fine with the full blown values specified. Must be some transformation matrix somewhere implemented somehow that I forgot about.

You’re missing code that sets up your camera with GL_PROJECTION.

Ah right, thanks for that.