PDA

View Full Version : Automatic texture generation coordinates



Brian Jones
12-13-2002, 08:59 PM
I am just using glTexGen to display a simple bitmap, to see how it works, yet, nothing gets display properly. So I was wondering if anyone could help.

Render a simple square bitmap at vertices:
glVertex3f(-50.0f, 50.0f, -100.0f);
glVertex3f(-50.0f, -50.0f, -100.0f);
glVertex3f(50.0f, -50.0f, -100.0f);
glVertex3f(50.0f, 50.0f, -100.0f);

(2D texture)

If you could please just show me how to use the gltexGen function to place texture coordinates on those vertex coordinate, just the steps involved, and I will pick up from there. No need for showing me how to bind or glTexParameteri anything.

Thank you.

mdog1234
12-13-2002, 09:59 PM
I may be wrong so dont take my word for it but i believe texGeni and texGenf are soley used for environment mapping. At least thats the only thing i use them for

31337
12-13-2002, 10:10 PM
Texture coordinates can be assigned however you want them to be assigned... Whatever you think would be the best method for texturing your object.

Brian Jones
12-13-2002, 10:43 PM
No, they can be used for stuff other than environmental mapping. Please post an example. I tried everything. EYE_LINEAR, OBJECT_LINEAR, EYE_PLANE, OBJECT_PLANE, it's doesn't work for some reason.

Bob
12-14-2002, 03:27 AM
What do you mean it doesn't work? It always work, the way you code it that is (assuming there's no errors). YOU post some code, and/or least say what you are trying to do and what is wrong now. I can think or several things that can be wrong with automatic texture coordinate generation.

Brian Jones
12-14-2002, 09:23 AM
I'm trying to draw a texture mapped square.
Like this:
void DrawSquare()
{
glBegin(GL_QUADS);

// glTexCoord2f(0.0f, 0.0f);
glVertex3f(-30.0f, -30.0f, 0.0f);

// glTexCoord2f(1.0f, 0.0f);
glVertex3f(30.0f, -30.0f, 0.0f);

// glTexCoord2f(1.0f, 1.0f);
glVertex3f(30.0f, 30.0f, 0.0f);

// glTexCoord2f(0.0f, 1.0f);
glVertex3f(-30.0f, 30.0f, 0.0f);

glEnd();
}

I've setup the automatic generation stuff like this:

GLfloat xequal[] = {1.0f, 0.0f, 0.0f, 0.0f};
GLfloat yequal[] = {0.0f, 1.0f, 0.0f, 0.0f};
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);

glTexGenfv(GL_S, GL_EYE_PLANE, xequal);
glTexGenfv(GL_T, GL_EYE_PLANE, yequal);

glEnable(GL_TEXTURE_GEN_S);

glEnable(GL_TEXTURE_GEN_T);

Please tell me what I did wrong

[This message has been edited by Brian Jones (edited 12-14-2002).]

Brian Jones
12-14-2002, 09:56 AM
Also the bmp image is 512x256 dimensions, if thats relevant.

Bob
12-14-2002, 10:09 AM
There's nothing wrong with that code. What exactly is the problem? Does it not give you what you want? If so, you better tell us what you want.

[This message has been edited by Bob (edited 12-14-2002).]

Brian Jones
12-14-2002, 10:51 AM
It doesn't give me what I want. I only displays a small line.

Brian Jones
12-14-2002, 10:54 AM
Ok, I changed the code to something else, it displays the bitmap, but not how I want it. It's displayed 4 times in a single square, this time. 2 times on the x axis, 2 times on the y axis.v I want it to be displayed once on each axis I changed it to this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

GLfloat xequal[] = {1.0f/30.0f, 0.0f, 0.0f, 0.0f};
GLfloat yequal[] = {0.0f, 1.0f/30.0f, 0.0f, 0.0f};

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);

glTexGenfv(GL_S, GL_EYE_PLANE, xequal);
glTexGenfv(GL_T, GL_EYE_PLANE, yequal);

glEnable(GL_TEXTURE_GEN_S);

glEnable(GL_TEXTURE_GEN_T);

[This message has been edited by Brian Jones (edited 12-14-2002).]

Bob
12-14-2002, 11:15 AM
So, you want the texture to fit exactly on the quad?

Well, the quad is 60x60 units large, so you have to scale the texture coordinates by 1/60 along the S and T axes. You then get the texture coordinate (0,0) in the middle of the quad, so you have to offset it by -0.5 along both axes. You can do that with the texture matrix.

Bob
12-14-2002, 11:17 AM
Hmm, pressed submit before I was done with my post.

Basically, something like this.



GLfloat xequal[] = {1.0f/60.0f, 0.0f, 0.0f, 0.0f};
GLfloat yequal[] = {0.0f, 1.0f/60.0f, 0.0f, 0.0f};
glTexGenfv(GL_S, GL_EYE_PLANE, xequal);
glTexGenfv(GL_T, GL_EYE_PLANE, yequal);

glMatrixMode(GL_TEXTURE);
glTranslatef(-0.5, -0.5, 0);
glMatrixMode(GL_MODELVIEW);

Maybe you can put the translation in the object plane equation, don't know.

Brian Jones
12-14-2002, 11:59 AM
Wow, thanks. It worked. I'm not saying it wouldn't have worked. It's just I never knew I had to modify the texture matrix stack. I haven't reached that section in the Red Book yet. It works with the object plane too. Thanks again.

[This message has been edited by Brian Jones (edited 12-14-2002).]