UV Mapping
Right now I have a height map for my game, and i am trying to take the X and Z coordinates and turn them into UV cordiates.
Here is the picture of what i am currently getting
Here is the code that makes the UV and then renders them.
I don't see why its not working correcly, I did some of the math out by hand and it should have worked...
Also, X,Y,Z are floats, U,V are GLfloats, I have tried a few combinations of variable types.
Here is the picture of what i am currently getting
Here is the code that makes the UV and then renders them.
I don't see why its not working correcly, I did some of the math out by hand and it should have worked...
Also, X,Y,Z are floats, U,V are GLfloats, I have tried a few combinations of variable types.
PHP Code:
- (void) makeUVCoordinates
{
int i,j;
float textureSizes[5];
textureSizes[0] = 4;
textureSizes[1] = 2;
textureSizes[2] = 1;
textureSizes[3] = 1;
textureSizes[4] = 4;
for( i = 0; i < levelx*levely*2; i++ )
{
for ( j = 0; j < 3; j++)
{
triangles[i].vertex[j].u = triangles[i].vertex[j].x / textureSizes[triangles[i].t];
triangles[i].vertex[j].v = triangles[i].vertex[j].z / textureSizes[triangles[i].t];
}
}
}
- (void) renderLevel
{
int i,j;
glView* gv = (glView*)[self superview];
for( i = 0; i < levelx*levely*2; i++ )
{
glBindTexture( GL_TEXTURE_2D, gv->texture[triangles[i].t] );
glBegin( GL_TRIANGLES ); // Draw a triangle
for ( j = 0; j < 3; j++)
{
glVertex3f( triangles[i].vertex[j].x, triangles[i].vertex[j].y, triangles[i].vertex[j].z );
glTexCoord2f( triangles[i].vertex[j].u, triangles[i].vertex[j].v );
}
glEnd();
}
}
I would _really_ recommend you to call glTexCoord2f before glVertex3f - as you do it now, each vertex gets the texcoords of the next vertex. This should produce what you're seeing.
Quote:Originally posted by Jake
Ah...., that could be why
![]()
show us the results!
Quote:Originally posted by skyhawk
show us the results!
Ok... remember these are VERY beta and don't have any shading or cool effects

, that could be why
