SDL Surface to OpenGL Texture Problem

Started by
1 comment, last by TreveonMaxwell 12 years, 12 months ago
OK!

I'm attempting to load a Sprite sheet as a texture for use in OpenGL

When you use glTexCoord2f you have to pass in the X and Y values as floats right? So I got to thinking I'd make a quick class that would do this for me. I'm sure I have the math right cause I tested my theory on one frame and it worked but well not so well when I printed the rest of the sheets values out to see if I was right...

Anyways I assume the math is something like the frameWidth / TextureWidth for the top X value and frameHeight / TextureHeight for the top Y.
You should add the frame height and width for the bottom coordinates..is that about right?

If you have multiple frames and animations shouldn't I multiply those values by the frame/animation number?

I hope that makes sense if not I'm gonna have to go into more detail I guess.
Advertisement
It's been a little while since I coded up my utility functions for this, but if I remember correctly, there might be some trickery with different coordinate systems between SDL and OpenGL. I seem to remember having upside-down textures on my first go-round.

OK!

I'm attempting to load a Sprite sheet as a texture for use in OpenGL

When you use glTexCoord2f you have to pass in the X and Y values as floats right? So I got to thinking I'd make a quick class that would do this for me. I'm sure I have the math right cause I tested my theory on one frame and it worked but well not so well when I printed the rest of the sheets values out to see if I was right...

Anyways I assume the math is something like the frameWidth / TextureWidth for the top X value and frameHeight / TextureHeight for the top Y.
You should add the frame height and width for the bottom coordinates..is that about right?

If you have multiple frames and animations shouldn't I multiply those values by the frame/animation number?

I hope that makes sense if not I'm gonna have to go into more detail I guess.
Ya know now that you mention it....
I'll do some more research on this topic. I originally wanted to create a class for this and post it on the site but it didn't work like I wanted it to. Hence the noob post. I'll post something when I figure this out. It'd be nice to have a way to make sprite sheets for 2d frame animation easier in SDL/OGL

This topic is closed to new replies.

Advertisement