Jump to content
  • Advertisement
Sign in to follow this  
jvkao

Sprite selection glTexCoord

This topic is 4657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In the sprite engine I am putting together, I am intending to use sheets of sprites (so that one 'character' object has all of its frames of animation in one texture). The current frame of animation is then selected with texture coordinates. All frame dimensions are a power-of-two, as is the entire sheet itself. The question I have is: Am I going to be able to get the required precision using glTexCoord, or is it going to leak pixels from adjacent frames? The main requirement of the engine is that it can draw hundreds of thousands of sprites in real time, so you can understand my concern with having to do a lot of context switching or multiple passes. Anybody got a better solution?

Share this post


Link to post
Share on other sites
Advertisement
What does GL_CLAMP do? I have the technical description
but not the understanding...

(my books haven't arrived yet!)

Share this post


Link to post
Share on other sites
GL_CLAMP repeats the border pixels if you specify a texture coordinate outside the range of 0-1.
But it wont help your problem when you are using sprites inside the image.
I think you will have to use a small offset when using the sprites like if the first one is between 0.2 and 0.6 you can use 0.2001 and 0.5999.Maybe that may help.I had this same problem with a terrain I was coding it was also using a big texture which had all tiles inside it like grass mud rock etc.And I had leaks too.

Share this post


Link to post
Share on other sites
Ok, it shouldn't be a problem to do that. Each 'character'
object describes the frames of animation in a structure
like this:


struct region {
GLfloat x;
GLfloat y;
GLfloat w;
GLfloat h;
};

struct npc {
uint16 n_frames;
struct region *frames;
...
};


So it should be possible to specify exact sizes at compile
time:


static region npc_frames[] = {
{ 0, 128, 0.2001, 0.2999, },
{ 128, 256, 0.4001, 0.3999, },
...
};


It'll be interesting to see how it turns out.

Share this post


Link to post
Share on other sites
Yes, that's a given. We're not using any form of texture filtering
either. It's going to look very 1990!

Share this post


Link to post
Share on other sites
If you set your MIN and MAG filters to NEAREST you should be able to select exact texels with careful use of TexCoord. Don't worry about setting CLAMP, you should never hit the border.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!