Skip to main content
gamedev.net
🔒 Locked

Generating Texture Coordinates...

Started by _coDer_ 3 replies 700+ views
Original Post
_coDer_
_coDer_
Hi! Well I''m writing a 3d level editor, and I''m up to texturing. My polygons are all right, vertices where they should be, etc, and I''m wondering if there''s a simple equation or some way of generating texture coordinates for these polygon faces (I need them to work with opengl, so they have to be between 0 and 1). I''ve tried all kinds of methods, nothing works. Please, ppl, I''m sooo close to finishing this editor, and this is like the only thing holding me back!!!
MatsG
MatsG
Find out what plane makes the biggest polygon and then use the plane to map it.

Ex:

max=MAX(MAX(ABS(Normal.x),ABS(Normal.y)),ABS(Normal.z));
if(max==ABS(Normal.x))ax=0;
if(max==ABS(Normal.y))ax=1;
if(max==ABS(Normal.z))ax=2;

if(ax==0)
{
u=z/TextureSize;
v=y/TextureSize;
}
if(ax==1)
{
u=x/TextureSize;
v=z/TextureSize;
}
if(ax==2)
{
u=x/TextureSize;
v=y/TextureSize;
}
_coDer_
_coDer_
But that''s the thing, I dont know the texture size yet, you insert a polygon and then specify any number of textures... I need coordinates between 0 and 1 for openGL to use... or am I just completely missing the point?!?!
MatsG
MatsG
You don''t need to have them exactly between 0-1 they are repeating ex. if you have them between 0-2 you would get the texture 4times over the surface (2 times in each direction). I''m no opengl expert but i know you could get thme to repeat maybe som GlEnable? Should be something with how the texture are addressed. I was meaning how big the texture should be in worldspace by TextureSize, sorry for the bad choice of variable name :/
fifty1
fifty1
To get your textures to repeat over the surface, you have to set the clamp modes to GL_REPEAT, like this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

The default is GL_CLAMP which uses the border pixels instead of repeating the texture.

Hope this helps.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.