PDA

View Full Version : One texture... multiple quads?


Jones
2006.07.10, 05:51 PM
I'm in a situation where I want to stretch one texture over an entire cube (if possible). So say to myself "Well, I'll test if it's possible with some simple quads."

Here's the code I tried out:

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(0, 0);
glVertex2i(16, 0);
glVertex2i(16, 16);
glVertex2i(0, 16);
glEnd();

glBegin(GL_QUADS);
glTexCoord2i(1, 0);
glVertex2i(16, 0);
glVertex2i(32, 0);
glVertex2i(32, 16);
glVertex2i(16, 16);
glEnd();

glBegin(GL_QUADS);
glTexCoord2i(1, 1);
glVertex2i(0, 16);
glVertex2i(16, 16);
glVertex2i(32, 32);
glVertex2i(0, 32);
glEnd();

glBegin(GL_QUADS);
glTexCoord2i(0, 1);
glVertex2i(16, 16);
glVertex2i(32, 16);
glVertex2i(32, 32);
glVertex2i(16, 32);
glEnd();

What it was *supposed* to do was draw four quads like this:

1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4

With one texture stretched over ALL of them. Funnily enough, I didn't even see the quads at all...

So, I tried this:

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(0, 0);
glTexCoord2i(0.5, 0);
glVertex2i(16, 0);
glTexCoord2i(0.5, 0.5);
glVertex2i(16, 16);
glTexCoord2i(0, 0.5);
glVertex2i(0, 16);
glEnd();

glBegin(GL_QUADS);
glTexCoord2i(0.5, 0);
glVertex2i(16, 0);
glTexCoord2i(1, 0);
glVertex2i(32, 0);
glTexCoord2i(1, 0.5);
glVertex2i(32, 16);
glTexCoord2i(0.5, 0.5);
glVertex2i(16, 16);
glEnd();

glBegin(GL_QUADS);
glTexCoord2i(0, 0.5);
glVertex2i(0, 16);
glTexCoord2i(0.5, 0.5);
glVertex2i(16, 16);
glTexCoord2i(0.5, 1);
glVertex2i(32, 32);
glTexCoord2i(0, 1);
glVertex2i(0, 32);
glEnd();

glBegin(GL_QUADS);
glTexCoord2i(0.5, 0.5);
glVertex2i(16, 16);
glTexCoord2i(1, 0.5);
glVertex2i(32, 16);
glTexCoord2i(1, 1);
glVertex2i(32, 32);
glTexCoord2i(0.5, 1);
glVertex2i(16, 32);
glEnd();


And it worked, only my texture was ity-ity-bity. Tiny. I thought it was because I had supplied floats to an int function, so I turned all my TexCoord2i's to TexCoord2f's. And it got a bit bigger, but still not the right size... what could be going wrong?

Thanks for any help!

(Note: Everything is setup right, with texturing enable and stuff. The function I use to load the texture is one of my own, and I'm pretty sure it works fine. I can supply it if it'll help solve this.

Thanks!

kordova
2006.07.11, 03:43 AM
You can apply a texture over any number of polygons.

The following (with a slight vertex change in the third quad) works for me.
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 0);
glTexCoord2f(0.5, 0);
glVertex2i(16, 0);
glTexCoord2f(0.5, 0.5);
glVertex2i(16, 16);
glTexCoord2f(0, 0.5);
glVertex2i(0, 16);
glEnd();

glBegin(GL_QUADS);
glTexCoord2f(0.5, 0);
glVertex2i(16, 0);
glTexCoord2f(1, 0);
glVertex2i(32, 0);
glTexCoord2f(1, 0.5);
glVertex2i(32, 16);
glTexCoord2f(0.5, 0.5);
glVertex2i(16, 16);
glEnd();


glBegin(GL_QUADS);
glTexCoord2f(0, 0.5);
glVertex2i(0, 16);
glTexCoord2f(0.5, 0.5);
glVertex2i(16, 16);
glTexCoord2f(0.5, 1);
glVertex2i(16, 32);
glTexCoord2f(0, 1);
glVertex2i(0, 32);
glEnd();


glBegin(GL_QUADS);
glTexCoord2f(0.5, 0.5);
glVertex2i(16, 16);
glTexCoord2f(1, 0.5);
glVertex2i(32, 16);
glTexCoord2f(1, 1);
glVertex2i(32, 32);
glTexCoord2f(0.5, 1);
glVertex2i(16, 32);
glEnd();

Does your code render a texture on one quad without issue?

Jones
2006.07.12, 02:58 AM
Your code change fixed an alignment issue I was having, so thanks!

I realize now that I'm simply drawing the image smaller than it really is, just a simple addition error. :wacko:

If I tried to do the same, but over a cube, do you think it would work?

unknown
2006.07.12, 06:11 AM
yes, unless you get more addition wrong.

kordova
2006.07.12, 02:10 PM
Your code change fixed an alignment issue I was having, so thanks!

I realize now that I'm simply drawing the image smaller than it really is, just a simple addition error. :wacko:

If I tried to do the same, but over a cube, do you think it would work?
You can enable a texture over any primitives. The only issue you might have is at the seams where the texture top meets the texture bottom and such.

Give it a try.

KittyMac
2006.07.12, 03:12 PM
You can enable a texture over any primitives. The only issue you might have is at the seams where the texture top meets the texture bottom and such.

And to eliminate such seams, use GL_CLAMP_TO_EDGE for GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T modes.

kordova
2006.07.12, 05:14 PM
And to eliminate such seams, use GL_CLAMP_TO_EDGE for GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T modes.Well, I meant seams related to the image itself not wrapping well, but good pointer.