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 3 of 3

Thread: How to "not streching a texture"?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    4

    How to "not streching a texture"?

    Hi,

    I am experiencing OpenGL.
    But I am stuck, I wonder if you guys could give me a hand.
    I have an image of 700x512 size and I scaled it down to 512x512 using gluScaleImage.
    And would like to map to a rectangle(square) with no streching at all.
    I have the following code segment. But it streches
    Any help is appreciated.

    Regards
    TM

    Code segment
    ============
    ...
    ...
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);

    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, imageBuffer);
    ....
    ....


    glBindTexture(GL_TEXTURE_2D, texture_id); //Texture for the frame
    glBegin(GL_QUADS);
    glTexCoord2f(1, 0); glVertex3f( 4,-1,-12);
    glTexCoord2f(1, 1); glVertex3f( 4, 1,-12);
    glTexCoord2f(0, 1); glVertex3f(-4, 1,-12);
    glTexCoord2f(0, 0); glVertex3f(-4,-1,-12);
    glEnd();

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,575

    Re: How to "not streching a texture"?

    you are drawing a square.
    if you want a rectangle with same aspect ratio as original texture, try this :
    double aspectx = 700.0/512.0;
    glTexCoord2f(1, 0); glVertex3f( 4.0*aspectx,-1,-12);
    glTexCoord2f(1, 1); glVertex3f( 4.0*aspectx, 1,-12);
    glTexCoord2f(0, 1); glVertex3f(-4.0*aspectx, 1,-12);
    glTexCoord2f(0, 0); glVertex3f(-4.0*aspectx,-1,-12);

    or this :
    double aspecty = 512/700.0;
    glTexCoord2f(1, 0); glVertex3f( 4.0*aspecty,-1,-12);
    glTexCoord2f(1, 1); glVertex3f( 4.0*aspecty, 1,-12);
    glTexCoord2f(0, 1); glVertex3f(-4.0*aspecty, 1,-12);
    glTexCoord2f(0, 0); glVertex3f(-4.0*aspecty,-1,-12);

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    4

    Re: How to "not streching a texture"?

    Thanks ZbuffeR,
    It still streches.
    But, when I try
    double aspectx = 700.0/512.0;
    glTexCoord2f(1, 0); glVertex3f( 1.0*aspectx,-1,-12);
    glTexCoord2f(1, 1); glVertex3f( 1.0*aspectx, 1,-12);
    glTexCoord2f(0, 1); glVertex3f(-1.0*aspectx, 1,-12);
    glTexCoord2f(0, 0); glVertex3f(-1.0*aspectx,-1,-12);
    It looks better,

Posting Permissions

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