UV Mapping

Member
Posts: 509
Joined: 2002.05
Post: #1
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

[Image: uv.jpg]

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:
- (voidmakeUVCoordinates
{
    
int i,j;
    
float textureSizes[5];
    
    
textureSizes[0] = 4;
    
textureSizes[1] = 2;
    
textureSizes[2] = 1;
    
textureSizes[3] = 1;
    
textureSizes[4] = 4;
    
    for( 
0levelx*levely*2i++ )
    {
        for ( 
03j++)
        {    
            
triangles[i].vertex[j].triangles[i].vertex[j].textureSizes[triangles[i].t];
            
triangles[i].vertex[j].triangles[i].vertex[j].textureSizes[triangles[i].t];
        }
    }
}

- (
voidrenderLevel
{
    
int i,j;
    
    
glViewgv = (glView*)[self superview];

    for( 
0levelx*levely*2i++ )
    {
        
        
glBindTextureGL_TEXTURE_2Dgv->texture[triangles[i].t] ); 

        
glBeginGL_TRIANGLES );             // Draw a triangle
        
        
for ( 03j++)
        {    
            
glVertex3f(   triangles[i].vertex[j].xtriangles[i].vertex[j].ytriangles[i].vertex[j].); 
            
glTexCoord2ftriangles[i].vertex[j].utriangles[i].vertex[j].);
        }
        
        
glEnd();    
    }


Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #2
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. Smile
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #3
Ah....Blush, that could be whyRolleyes
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #4
Quote:Originally posted by Jake
Ah....Blush, that could be whyRolleyes


show us the results!
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #5
Quote:Originally posted by skyhawk
show us the results!

Ok... remember these are VERY beta and don't have any shading or cool effects

[Image: screen1.jpg]
[Image: screen2.jpg]
Quote this message in a reply
Post Reply