Sign in to follow this  

indexed arrays tex mapping problem

This topic is 4593 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

Hi, Recently i was playing with glDrawElements() and i run at problem how to pass different texture coordinates to one vertex. It could be handy when i use it in more than one triangle ;). Right now i'm using simple array of texture coordinates and i have only one coordinate for each vertex which basicly screw my texture mapping on my models. Any solution to this problem needed :)

Share this post


Link to post
Share on other sites
You need to have a one-to-one mapping of vertices to uvs, normals, colors, any other per-vertex attributes. So if you have a vertex and you need to have two different texture coordinates for it, you need to duplicate the vertex. And make sure that the right triangle/quad/whatever in the index array uses the duplicated vertex's index instead of the original one.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Kalidor
You need to have a one-to-one mapping of vertices to uvs, normals, colors, any other per-vertex attributes. So if you have a vertex and you need to have two different texture coordinates for it, you need to duplicate the vertex. And make sure that the right triangle/quad/whatever in the index array uses the duplicated vertex's index instead of the original one.


Nope. Only for the normals and colors. That is what the multiple texture units are for - so you can have multiple textures blended in one pass. Please recheck your sources. Kali is on the right track. I got to go or I'd post more :( (soz)

Share this post


Link to post
Share on other sites
Thanks for replies,
I don't have problem with multitexturing, only with mapping one texture, i will show you guys how it look like in my basic heightmap:
Free Image Hosting at www.ImageShack.us
The texture is mirrored and it looks pretty bad at borders of quads, i'm using texture coordinates like that ( view from above ):
Free Image Hosting at www.ImageShack.us

I need to know if there is a way to better design placement of texture coordinate or i have to make more vertices like Kalidor said ( in this case it looks to me like it dont differ from using regular vertex arrays - in the end you need to make the same number of vertices )

Share this post


Link to post
Share on other sites
You should use texture coords like this if your useing indexed arrays

0,0 1,0 2,0 3,0
0,1 1,1 2,1 3,1
0,2 1,2 2,2 3,2
0,3 1,3 2,3 3,3

Make sure that your texture has the correct Wrapping setup! don't use Clamp

But that should work. =D

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Nope. Only for the normals and colors. That is what the multiple texture units are for - so you can have multiple textures blended in one pass. Please recheck your sources. Kali is on the right track. I got to go or I'd post more :( (soz)
Yes, multi-texturing is for using multiple textures at once, not multiple texture coordinates within the same texture unit. But texture coordinates for each texture unit are separate per-vertex attributes, so if you want to have a vertex with different texture coordinates within the same texture unit, you need to duplicate it. In my previous post I was talking about texture coordinates within the same texture unit, I should've made that clearer.

As for the OP's mirroring problem, Xero-X2 is right. Set up your texture's wrap modes to GL_REPEAT and either have the texcoords for the entire terrain span from 0 to the number of times you want the terrain to repeat, or have them go from 0 to 1 and use the texture matrix to scale by the amount you want to repeat.

Share this post


Link to post
Share on other sites
Quote:
Original post by Xero-X2
You should use texture coords like this if your useing indexed arrays

0,0 1,0 2,0 3,0
0,1 1,1 2,1 3,1
0,2 1,2 2,2 3,2
0,3 1,3 2,3 3,3

Make sure that your texture has the correct Wrapping setup! don't use Clamp

But that should work. =D

Thanks, that was that solution i was searching for :D

Share this post


Link to post
Share on other sites

This topic is 4593 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this