2
\$\begingroup\$

Current Situation

I have a spritesheet loaded in for a texture when drawing the specific portions of the sheet that I'd like to have on my quads I do some simple math to get their location on the sheet and normalize it.

My texture is setup like this:

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

The Problem

Where I'm facing the problem is that because I'm using a "chunk" of the total texture I can't take advantage of using 1.0 for the mapping of values to glTexCoordPointer to cause the texture to stretch over the entire face.

Looked Into

I've looked for a glTexParameterf option for scaling options but I failed to find anything.

Question

Is it possible with my current methods to stretch the texture over the face of the quad without having to load a separate image for every "sprite" of the texture? Or am I just doing everything completely wrong?

Picture that hopefully sort of clarifies: enter image description here

Thanks for any help.

edit The problem was another issue all together: Turns out it was another issue all together, I thought this didn't make sense cause it was mapping it to the vertices so it should stretch regardless and infact it does work right I was assigning the wrong the width and height values to the drawing routines calculations. And now I feel really stupid, thanks for the help Byte56. Sorry for taking up your time. The GL_CLAMP solution would be the correct answer if I hadn't made a huge fail.

\$\endgroup\$
5
  • 3
    \$\begingroup\$ How are you assigning the texture coordinates to the quad? \$\endgroup\$
    – House
    Apr 24, 2012 at 23:42
  • \$\begingroup\$ (x, y) of position in texture divided accordingly (x/width) (y/height) become x0 and y0. Then the same for with the width and height of that chunk added on become x1 and y1. Then GLfloat texture_coords[] = {x0, y0, x1, y0, x1, y1, x0, y1}; using glTexCoordPointer obviously. \$\endgroup\$
    – dennmat
    Apr 24, 2012 at 23:49
  • 1
    \$\begingroup\$ Try: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); \$\endgroup\$
    – House
    Apr 24, 2012 at 23:55
  • \$\begingroup\$ Turns out it was another issue all together, I thought this didn't make sense cause it was mapping it to the vertices so it should stretch regardless and infact it does work right I was assigning the wrong the width and height values to the drawing routines calculations. And now I feel really stupid, thanks for the help Byte56. Sorry for taking up your time. The GL_CLAMP solution would be the correct answer if I hadn't made a huge fail. \$\endgroup\$
    – dennmat
    Apr 24, 2012 at 23:57
  • \$\begingroup\$ Ah, well I was just making my comment into an answer. I guess it's moot then. Glad you solved it! \$\endgroup\$
    – House
    Apr 25, 2012 at 0:01

1 Answer 1

2
\$\begingroup\$

It looks like your assigning the textures to the vertices correctly. I don't see how you're getting the results you're getting with what you've shown us. But you may want to try this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .