views:

1240

answers:

1

I have some problems mapping a texture to a triangle strip. I think I still don't fully understand the texture coordinates.

I have a 512x512 texture, and I'm trying to map the 320x64 part of it on a triangle strip.

Here is my code:

static const Vertex3D bg_vertex [] = 
{
    {  0,    0,     0}, {  0,   64,     0}, { 64,    0,     0},
    { 64,   64,     0}, {128,    0,     0}, {128,   64,     0},
    {192,    0,     0}, {192,   64,     0}, {256,    0,     0},
    {256,   64,     0}, {320,    0,     0}, {320,   64,     0}
};

static const GLfloat bg_texcoords [] =
{
    {1.000, 0.000}, {1.000, 0.125}, {0.875, 0.000}, {0.875, 0.125}, {0.750, 0.000}, {0.750, 0.125},
    {0.625, 0.000}, {0.625, 0.125}, {0.500, 0.000}, {0.500, 0.125}, {0.375, 0.000}, {0.375, 0.125}
};

glBindTexture (GL_TEXTURE_2D, bg1Texture);
glEnable(GL_TEXTURE_2D);

glColor4f (1.0, 1.0, 1.0, 1.0);
glTexCoordPointer(2, GL_FLOAT, 0, bg_texcoords);
glVertexPointer(3, GL_FLOAT, 0, &bg_vertex);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 12);

When I run the code, it displays a distorted image of the original texture on the triangle strips.

Can someone please tell me what am I doing wrong?

Thanks

+2  A: 

OK, it works now when I removed the extra braces from the texture coordinates:

static const GLfloat bg_texcoords [] =
{
    1.000, 0.000, 1.000, 0.125, 0.875, 0.000, 0.875, 0.125, 0.750, 0.000, 0.750, 0.125,
    0.625, 0.000, 0.625, 0.125, 0.500, 0.000, 0.500, 0.125, 0.375, 0.000, 0.375, 0.125
};

Now it maps the texture perfectly on the triangles

Istvan