Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Texture Mapping

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    28

    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:

    Code :
    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();
    }

    Code :
    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);
    }

    Code :
    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.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	1.jpg 
Views:	21 
Size:	9.6 KB 
ID:	2483   Click image for larger version. 

Name:	2.jpg 
Views:	22 
Size:	12.6 KB 
ID:	2484   Click image for larger version. 

Name:	3.jpg 
Views:	19 
Size:	2.2 KB 
ID:	2485  
    Last edited by Atomic_Sheep; 09-21-2017 at 11:47 PM.

  2. #2
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    420
    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    28
    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.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	White Corner.jpg 
Views:	4 
Size:	6.2 KB 
ID:	2492  

  4. #4
    Intern Newbie
    Join Date
    May 2012
    Posts
    30
    You're missing code that sets up your camera with GL_PROJECTION.

  5. #5
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    28
    Ah right, thanks for that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •