Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DisKordLeader

OpenGL Texture alignment on OpenGL

This topic is 6647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, ive got all my objects texture map coordinates into the program anf i can see the texture map on the object in all its glory. Now, how can i move the texture map along the surface of the object for alignment? i thought that just by adding to the texcoords it would change the alignment, but it doesn''t? Does anyone have an idea? Thanks Martin W

Share this post


Link to post
Share on other sites
Advertisement
You could try mucking about with the texture matrix (yes, there is a texture matrix).

Just make it current (using glMatrixMode(...), and you can simply apply the functions glTranslatef(...), glRotatef(...), and glScalef(...), etc to move the textures around. Cool, huh?

(I haven''t tried this for ages, so don''t kill me if it doesn''t work, OK )

-------------
squirrels are a remarkable source of protein...

Share this post


Link to post
Share on other sites
the following code (provided I don't screw up) should cause a texture to scroll across a quad.

        
void Render()
{
static float dtx = 0.0f;
static float dty = 0.0f;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(0.0f, 0.0f, -5.0f);

glBindTexture(GL_TEXURE_2D, &MyTex);
glBegin(GL_QUADS);
glTexCoord2f(dtx, dty );
glVertex3f (-1.0f, -1.0f );
glTexCoord2f(1.0f + dtx, dty );
glVertex3f ( 1.0f, -1.0f );
glTexCoord2f(1.0f + dtx, 1.0f + dty);
glVertex3f ( 1.0f, 1.0f );
glTexCoord2f(dtx, 1.0f + dty);
glVertex3f (-1.0f, 1.0f );
glEnd();

dtx += 0.1f;
dty += 0.2f;

if (dtx == 1.0f)
dtx = 0.0f;
if (dty == 1.0f)
dty = 0.0f;

SwapBuffers(hDC);
}


Apologies if I have buggered up, but you should get the gist.

ps - Isn't the automatic formatting of my code flattering?

Edited by - poontardis on August 30, 2000 5:34:12 AM

Share this post


Link to post
Share on other sites
The above response is right on, but more simply put is that to align a texture on a surface all you have to do is adjust the values in your glTexCoord function.

if you want the texture to be displayed once on the given polygon then you use texcoord values from 0.0f to 1.0f. For example:

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); // Bottom left of texture
glVertex3f(-1.0f, -1.0f, -1.0f);// bottom left
glTexCoord2f(0.0f, 1.0f); // top left of texture
glVertex3f(-1.0f, 1.0f, -1.0f);// top left
glTexCoord2f(1.0f, 1.0f); // top right of texture
glVertex3f( 1.0f, 1.0f, -1.0f);// top right
glTexCoord2f(1.0f, 0.0f); // bottom right of texture
glVertex3f( 1.0f, -1.0f, -1.0f);// bottom right
glEnd();

now if you were wanting to display the texture once on the polygon starting with the middle of it (ie. half way on the x axis of the texture) you would simply replace the x values on all the TexCoord functions like this:

glBegin(GL_QUADS);
glTexCoord2f(0.5f, 0.0f); // Bottom middle of texture**
glVertex3f(-1.0f, -1.0f, -1.0f);// bottom left
glTexCoord2f(0.5f, 1.0f); // top middle of texture**
glVertex3f(-1.0f, 1.0f, -1.0f);// top left
glTexCoord2f(1.5f, 1.0f); // top middle oftexture
glVertex3f( 1.0f, 1.0f, -1.0f);// top right
glTexCoord2f(1.5f, 0.0f); // bottom middle of texture
glVertex3f( 1.0f, -1.0f, -1.0f);// bottom right
glEnd();

Now you are probably asking "how can you have a point at 1.5 on a texture?" Well that is because the textures are repeated.



Share this post


Link to post
Share on other sites
Ionut Costica ->

yes, the texture matrix is independant of the texcoords you set up in your display list. The texture matrix manipulates (transforms, etc...) the texcoords from the oringinal position you set in the display list.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!