Results 1 to 7 of 7

Thread: Texture Mapping - I need help!

  1. #1
    Member Contributor
    Join Date
    Jul 2001
    Location
    Camarillo, CA, USA
    Posts
    58

    Texture Mapping - I need help!

    Could someone explain the very basics of texture mapping? I think I know what it is, but Im probably wrong. Please dont say "goto nehe's website, tutorial #6" because Ive been there. Id like to get other opinions, please.

    All I am trying to do it put a picture on the floor in my first-person game.

    Please help...

    =( ~Jesse
    PROGRAMMERS SHALL RULE THE WORLD

  2. #2
    Member Newbie
    Join Date
    Oct 2001
    Location
    Beijing, China
    Posts
    37

    Re: Texture Mapping - I need help!

    Try to get a CG set, which can simplify many opengl procedures.

    For example, to define a floor texture in your game you may write your code like this (in Delphi):

    uses
    CGTexture;

    var
    t: TCGTexture;
    ...

    procedure paint;
    Begin
    t.create;
    t.LoadJPG('floor.jpg');
    ...
    t.enable;
    gl_begin(gl_quads);
    gltexcoords(0,1); glvertex3f(10,0,10);
    gltexcoords(1,1); glvertex3f(10,0,-10);
    gltexcoords(1,0); glvertex3f(-10,0,-10);
    gltexcoords(0,0); glvertex3f(-10,0,10);
    gl_end;
    t.disable;
    ...


    That's OK. You can see your textured floor now. It's so easy, isn't it?
    Of course you can add some lights and other effects to your 3D model. With CG unit you will find other procedures are alse simplified.

    coco.cool@263.net

    [This message has been edited by Dong Ke (edited 10-23-2001).]

  3. #3
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: Texture Mapping - I need help!

    Hi !

    I am not sure what you are after here, do you want to know what texture mapping is or how to use it as a programmer ?

    Amyway, have a look at the OpenGL faq: http://www.opengl.org/developers/faq....html#indx0210

    It explains the basics, the "Red Book" or the "OpenGL super bible" explains all the details of texture mapping (both are available on line).

    Mikael

  4. #4
    Member Contributor
    Join Date
    Jul 2001
    Location
    Camarillo, CA, USA
    Posts
    58

    Re: Texture Mapping - I need help!

    I'm just loking for someone who can explain to me HOW to map textures.. I know what it is =)

    I just ned someone to break it down into newbie-terms =)

    ~Jesse

    PS Newbie to openGL, been proggin C/C++ for about 4 years. Just ta let ya know =)
    PROGRAMMERS SHALL RULE THE WORLD

  5. #5
    Member Contributor
    Join Date
    Jul 2001
    Location
    Camarillo, CA, USA
    Posts
    58

    Re: Texture Mapping - I need help!

    I'm just loking for someone who can explain to me HOW to map textures.. I know what it is =)

    I just ned someone to break it down into newbie-terms =)

    ~Jesse

    PS Newbie to openGL, been proggin C/C++ for about 4 years. Just ta let ya know =)
    PROGRAMMERS SHALL RULE THE WORLD

  6. #6
    Member Contributor
    Join Date
    Oct 2001
    Posts
    67

    Re: Texture Mapping - I need help!

    There's a few things you'll need to do...

    1) Somehow you need to get your texture data into memory, i.e. you need to load your texture somehow. There are a TON of ways to do this -- pick the one that suits you best (I usually use a class I wrote many years ago to load bitmaps). I'll assume you're able to do this, and that you have a variable "data" which points to the actual texture pixel data and variables "width" and "height" which refer to the texture's width and height, respectively (these MUST be a power of two).

    2) Put these "magic" lines somewhere before you want to do texture mapping. This is just about the minimal work you need to do to do texturing:
    Code :
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
    glEnable(GL_TEXTURE_2D);
    3) Before every vertex of the polygon you want to texture map, specify the vertex's texture coordinate. You do this by using glTexCoordXX. For example, to draw a textured quad:
    Code :
    glBegin( GL_QUADS );
     
    	glTexCoord3f(1.0f, 0.0f, 0.0f);
    	glVertex2f( 0.5f, -0.5f);
     
    	glTexCoord3f(1.0f, 1.0f, 0.0f);
    	glVertex2f( 0.5f,  0.5f);
     
    	glTexCoord3f(0.0f, 1.0f, 0.0f);
    	glVertex2f(-0.5f,  0.5f);
     
    	glTexCoord3f(0.0f, 0.0f, 0.0f);
    	glVertex2f(-0.5f, -0.5f);
     
    glEnd();
    Note that this will try and texture map ALL polygons rendered after enabling GL_TEXTURE_2D. If you only want to texture map a few polygons (instead of all of them), you'll need to enable and disable texturing appropriately.

    Hope this helps!

    -- sec

  7. #7
    Member Contributor
    Join Date
    Jul 2001
    Location
    Camarillo, CA, USA
    Posts
    58

    Re: Texture Mapping - I need help!

    LOL omg..

    Thats all I wanted to know!! Thank you SO much sir! Ive been in and out of forums looking for the answer.. You are my God!
    ~Jesse

    =)
    =)
    PROGRAMMERS SHALL RULE THE WORLD

Similar Threads

  1. Texture mapping ::: 3D Face Mapping
    By 3render3 in forum OpenGL: General
    Replies: 2
    Last Post: 03-24-2013, 06:49 PM
  2. projective texture mapping and shadow mapping
    By phoenix_gl in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-08-2012, 08:00 PM
  3. Replies: 0
    Last Post: 01-09-2005, 05:53 PM
  4. Replies: 1
    Last Post: 01-09-2005, 05:50 PM
  5. Texture Mapping / Environmental Mapping.
    By imported_Andrew in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-09-2000, 01:20 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