Results 1 to 2 of 2

Thread: Understanding of glTexCoord*

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2009
    Posts
    2

    Understanding of glTexCoord*

    Hi opengl'ers

    i began to code in c++ with SDL and then started to use OpenGL.
    After some lessons i started to learn texture mapping.

    It was really easy to put a texture on a simple quad. After that i tried to figure out how glTexCoord2f is really working.

    The first time i thought for glTexCoord2f the two parameters stand for the (x,y) coordinate which should be the same as the glVertex method to match. But it wasnt.

    Then i've read something about representating the part of the texture in percentage. As parameters are between 0 and 1, 1 stand for 100% of the texture width/height, but i dont get it. What does that mean.

    As ONE glTexCoord is always mapped to a point in a GL_QUADS area, how is glTexCoord interpreted by OpenGL?

    I have a 256x256 *.bmp texture. And i have 256x256 Quad which is simply put on window with 4 glVertex3f method calls.
    When i use standard parameters for glTexCoord2f, like (0,1), (1,1), (0,0) and (1,0), then texture is mapped perfectly on the Quad.

    But i tried to only map a part of the texture to this quad, changing the glTexCoord parameters. I tried to map the top half of the texture (means from 0,0 to 256,12 on the 256x256 Quad. This didnt work, i got a texture on the full quad in one color, the text/logo on the texture just disappered. When i tried to use parameters for glTexCoord greater than 1.0 then i got a strange dashed lines texture.

    Im still confused, how is glTexCoord really working?
    How can i map the half or any part of a texture on simple quad (like blitting a part of an image on a surface, or just stretch the texture on the full quad).

    Thanks for any help.

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Understanding of glTexCoord*

    glTexCoord2f - means float.

    If you want half of the quad you should use following texcoords:
    (0.0f, 0.5f), (1.0f, 0.5f), (1.0f, 0.0f), (0.0f, 0.0f)

    No matter how big the texture is, it's coordinates are always in range 0.0f-1.0f.
    So, 0.5f is half of texture, 2.0f is texture repeated twice.

    The only exception are rectangular textures specified using GL_TEXTURE_RECTANGLE instead of GL_TEXTURE_2D.

Similar Threads

  1. Am I understanding this right?
    By Klamath in forum COLLADA
    Replies: 3
    Last Post: 12-01-2016, 03:15 AM
  2. glTexCoord and glNormal
    By imported_kospanak in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 07-08-2008, 01:22 AM
  3. Display lists and glTexCoord
    By imported_huntc in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 07-07-2005, 04:00 AM
  4. glVertex & glTexCoord
    By dimensionX in forum OpenGL ES
    Replies: 3
    Last Post: 09-30-2004, 10:23 AM
  5. glTexCoord coordinates
    By delic in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-06-2002, 10:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean