PDA

View Full Version : Texture mapping with repitition



04-23-2003, 05:45 PM
This is probably a very simple question with a simple solution, and here it goes.

I have created a wall which I now want to have covered with tiles. I have a 256x256 ppm file and want it to be repeated over the wall. Currently, the pattern just get's stretched to fit.

The code i'm using for a section of the wall is as follows:

glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();

glTexImage2D (GL_TEXTURE_2D, 0, 3, width1, height1,
0, GL_RGB, GL_UNSIGNED_BYTE, data1);

// First facet of the cube = front
// Paste the texture on, facing right side up
glBegin (GL_POLYGON);
glTexCoord2i (0, 1);
glVertex3f (-SIZE, -SIZE, SIZE);

glTexCoord2i (1, 1);
glVertex3f (SIZE, -SIZE, SIZE);

glTexCoord2i (1, 0);
glVertex3f (SIZE, SIZE, SIZE);

glTexCoord2i (0, 0);
glVertex3f (-SIZE, SIZE, SIZE);
glEnd ();

// Second facet of the cube = right side
glBegin (GL_POLYGON);
glTexCoord2i (0, 1);
glVertex3f (SIZE, -SIZE, SIZE);
glTexCoord2i (1, 1);
glVertex3f (SIZE, -SIZE, -SIZE);
glTexCoord2i (1, 0);
glVertex3f (SIZE, SIZE, -SIZE);
glTexCoord2i (0, 0);
glVertex3f (SIZE, SIZE, SIZE);
glEnd ();

// back
glBegin (GL_POLYGON);
glTexCoord2i (1, 1);
glVertex3f (-SIZE, -SIZE, -SIZE);
glTexCoord2i (1, 0);
glVertex3f (-SIZE, SIZE, -SIZE);
glTexCoord2i (0, 0);
glVertex3f (SIZE, SIZE, -SIZE);
glTexCoord2i (0, 1);
glVertex3f (SIZE, -SIZE, -SIZE);
glEnd ();

// left
glBegin (GL_POLYGON);
glTexCoord2i (0, 1);
glVertex3f (-SIZE, -SIZE, -SIZE);
glTexCoord2i (1, 1);
glVertex3f (-SIZE, -SIZE, SIZE);
glTexCoord2i (1, 0);
glVertex3f (-SIZE, SIZE, SIZE);
glTexCoord2i (0, 0);
glVertex3f (-SIZE, SIZE, -SIZE);
glEnd ();

// top
glBegin (GL_POLYGON);
glTexCoord2i (0, 1);
glVertex3f (-SIZE, SIZE, SIZE);
glTexCoord2i (1, 1);
glVertex3f (SIZE, SIZE, SIZE);
glTexCoord2i (1, 0);
glVertex3f (SIZE, SIZE, -SIZE);
glTexCoord2i (0, 0);
glVertex3f (-SIZE, SIZE, -SIZE);
glEnd ();

// bottom
glBegin (GL_POLYGON);
glTexCoord2i (0, 1);
glVertex3f (-SIZE, -SIZE, SIZE);
glTexCoord2i (0, 0);
glVertex3f (-SIZE, -SIZE, -SIZE);
glTexCoord2i (1, 0);
glVertex3f (SIZE, -SIZE, -SIZE);
glTexCoord2i (1, 1);
glVertex3f (SIZE, -SIZE, SIZE);
glEnd ();

glPopMatrix ();
glPopAttrib();

I have tried changing the glTexCoord2i() but that didn't do the repitition.

So, what should I do to change this?

Thanks in advance for any help!

Perspective
04-23-2003, 06:23 PM
here is a hint using your code




glBegin (GL_POLYGON);
glTexCoord2i (0, 50);
glVertex3f (-SIZE, -SIZE, SIZE);

glTexCoord2i (50, 50);
glVertex3f (SIZE, -SIZE, SIZE);

glTexCoord2i (50, 0);
glVertex3f (SIZE, SIZE, SIZE);

glTexCoord2i (0, 0);
glVertex3f (-SIZE, SIZE, SIZE);
glEnd ();

JanHH
04-24-2003, 07:08 PM
but this will only work when texture repeating is enabled (instead of clamping). something like glTexParamter...(GL_REPEAT_T/_S), i don't know the exact syntax at the moment.