Sign in to follow this  
silverphyre673

A new one about texture mapping...

Recommended Posts

OK, let's just assume I have a texture loaded into memory successfully, with the ID stored in the GLuint "texture_id". If I'm drawing triangle strips according to the following algorithm, then how would I want to make my glTexCoord2f() calls so that the texture will be displayed properly? Here is the algorithm used for rendering:
void RenderHeightmap(const HeightMap * height_map)
{
    glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
    for (float y = 0.0f; y < (float)height_map->Height() - 1; ++y)
    {
        glBegin(GL_TRIANGLE_STRIP);
        for ( float x = 0.0f; x < (float)height_map->Width(); ++x)
        {
                //Where do the glTexCoord2f()s go?
                glVertex3f(x, y, height_map->GetTileInfo((int)x, (int)y).height);
                glVertex3f(x, y + 1.0f, height_map->GetTileInfo((int)x, (int)(y + 1.0f)).height);
        }
        glEnd();
    }
}
And here is a screenshot of the results, in wireframe mode: Image hosted by Photobucket.com Hopefully, with your help, it will be textured soon! Thanks.

Share this post


Link to post
Share on other sites
It should look like this:


glTexCoord2f(x/height_map->Width(), y/height_map->Height())
glVertex3f(x, y, height_map->GetTileInfo((int)x, (int)y).height);

glTexCoord2f(x/height_map->Width(),(y+1)/height_map->Height())
glVertex3f(x, y + 1.0f, height_map->GetTileInfo((int)x, (int)(y + 1.0f)).height);

Share this post


Link to post
Share on other sites

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