PDA

View Full Version : Stretching textures?



hetunt
01-27-2010, 11:09 PM
I made a small game that is using glortho to zoom out of the screen. This is a problem because it makes the textures look extremely small, sometimes to the point where you cannot see them. I can see the quads just fine, and the textures are indeed being applied to the quads.

I used glortho to set the left of the screen to 0, the top to 0, the bottom to 768, and the right to 1024. So, does anyone know of a function or a method to stretch the textures out to fit the quads?
Thanks!

Iulian B
01-28-2010, 05:24 AM
I wrote some explanation about glOrtho (and glViewport) here http://www.opengl.org/discussion_boards/...0728#Post270728 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=52341&Number=2707 28#Post270728) . I know it's not exactly on the subject, but maybe it helps a bit.

What would help even more would be for you to paste some representative code, more to the point, any call that affects the Projection and modelview matrices and an example of how you draw one quad, with vertex and texture coords.

hetunt
01-28-2010, 09:49 PM
Basically, I'm doing this:

<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glOrtho(0,1024,768,0,-1,1);
glBindTexture(GL_TEXTURE_2D,texture);
glBegin(GL_QUADS);
glTexCoord2d(x,y2);
glVertex3f(x,y2,1);
glTexCoord2d(x2,y2);
glVertex3f(x2,y2,1);
glTexCoord2d(x2,y);
glVertex3f(x2,y,1);
glTexCoord2d(x,y);
glVertex3f(x,y,1);
glEnd();
SwapBuffers(hdc);[/QUOTE]</div>

Where x, x2, y, and y2 are the coordinates of the actor. Again, the textures are loaded and applied correctly, and the quads are visible, but when using glortho as I do in the above code, the textures get far to small to be seen, and the quad ends up being a blank gray square. Basically, I'm trying to stretch this extremely small texture to be the size of the quad when I'm using glortho as I did above.

Any help is greatly appreciated!

ZbuffeR
01-29-2010, 01:17 AM
You don't have to manually scale the texture coords.

Iulian B
01-29-2010, 02:05 AM
To draw a 2d quad that stretches from x1,y1 to x2,y2 and has a texture stretched on it's entire face, try this

<div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
glBegin(GL_QUADS);

glTexCoord2f(0.f,1.f);
glVertex2f(x1,y1);

glTexCoord2f(0.f,0.f);
glVertex2f(x1,y2);

glTexCoord2f(1.f,0.f);
glVertex2f(x2,y2);

glTexCoord2f(1.f,1.f);
glVertex2f(x2,y1);

glEnd();
[/QUOTE]</div>

Now, no matter what the values for x1,y1,x2,y2, you will get the entire texture stretched between those 2 points. That is because texture coordinates are normalized, i.e. (0,0) is the lower left corner and (1,1) is the top right corner

hetunt
01-29-2010, 02:56 AM
Wow... that worked. I can't believe it was that simple, because now I feel stupid.

Well, thanks for the help!