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

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).]

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/faqs/technical.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

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 =)

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 =)

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:

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);

  1. 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:

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

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

=)
=)