Jump to content
  • Advertisement
Sign in to follow this  
Enderdil

2D Game, sprites, texturing

This topic is 4089 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

Hi! I am creating a 2D game that will use sprites. I have encountered some difficulties displaying them. My sprites are stored in bmp files and looks like this (blue-transparent): sprites I have tried to display them in different ways. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, {1}); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, {1}); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, {2}); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, {2}); 1-GL_NEAREST 2-GL_REPEAT (does not matter anyway when 1-GL_NEAREST) nearest repeat 1-GL_LINEAR 2-GL_CLAMP linear clamp 1-GL_LINEAR 2-GL_REPEAT linear repeat How do I display these textures to get same result as on last picture but without those lines? Would antialiasing help?

Share this post


Link to post
Share on other sites
Advertisement
If you are scaling the sprite, and it sure looks like your are, then you really need to allow a little room on the sprite page around it. That way the blend function won't access 'bad' pixels you don't want. That is what it seems like to me, without seeing more code.

Share this post


Link to post
Share on other sites
It may help for some sprites to be displayed correctly but the other may cause problems (half transparent sprites, I mean border items)

border item sprite
The bottom part of the sprite can NOT be transparent becouse it wouldn't be sticked to the ground (there would be a line). And if there wasn't transparent line then there will apear a line on the top of the sprite

Share this post


Link to post
Share on other sites
I could but it wouldn't solve the problem with tiles like this border item sprite
I've tried a lot of things and I got bored coz I can't find the answer. I'm now creating other parts of code and waiting for some helpful soul to solve this. [dead]

Share this post


Link to post
Share on other sites
Are all your tiles in individual textures, or is the example image in your first post a single texture containing multiple tiles?

I'd suggest a wrap mode of CLAMP_TO_EDGE and offset your texture coords inwards by half a texel.


const float texelSizeU = 1.0f / texture.width;
const float texelSizeV = 1.0f / texture.height;

const float halfUTexel = texelSizeU * 0.5f;
const float halfVTexel = texelSizeV * 0.5f;

glTexCoord2f(0+halfUTexel, 0+halfVTexel);
glVertex2f(...)
glTexCoord2f(1.0f-halfUTexel, 0+halfVTexel);
glVertex2f(...)
glTexCoord2f(1.0f-halfUTexel, 1.0f-halfVTexel);
glVertex2f(...)
glTexCoord2f(0+halfUTexel, 1.0f-halfVTexel);


Although I think just usign CLAMP_TO_EDGE everywhere should have a similar effect.

Btw, when testing texture alignment issues it's usually best to make a text texture which obviously shows which texels come from where. I usually use a checkerboard pattern with the edge squares coloured differently for each edge. This particularly helps when you've got colours bleeding in unexpected places.

Share this post


Link to post
Share on other sites
Each sprite is stored in separate bitmap. I have followed your tips but still the lines are visible (just as the second pic [1-GL_LINEAR;2-GL_CLAMP] in my 1st post)

Share this post


Link to post
Share on other sites
Did you try a test texture with a checkerboard pattern and/or primary coloured edges? What did that show? It'd give you/us a good indication of where exactly something is going wrong rather than just random guessing. Make sure to make it low-res too, half the resolution of the actual sprite is usually a good size.

Share this post


Link to post
Share on other sites
I can give you my sources. Cutted some things out.
http://www.speedyshare.com/569816712.html
I will test now your last advice but I doubt I'll make anyting, coz after 3 days of messing with this I'm out of ideas [dead]

Share this post


Link to post
Share on other sites
GL_CLAMP_TO_EDGE fixed these things for me when I had the same problem. Are you using the 0.375 offset to draw at pixel centers?


glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0.375, 0.375, 0.0);




OpenGL correctness

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!