Sign in to follow this  

2D Game, sprites, texturing

This topic is 3723 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
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
I have solved this. It is for sure not the best solution but it works. Dropped my FPS to 25-30~ on 1280x1024 resolution.
My sprites are 32x32 and I got 15 of them in a row and 11 in a column. That's why I'm changing it to render on 480x352 viewport.
var
data:array [1..512*512*3]of byte;
Begin
glViewPort(1,1,480,352);

// RENDERING HERE !

glBindTexture(GL_TEXTURE_2D,screenTex);
glReadPixels(1,1,512,512,GL_RGB,GL_UNSIGNED_BYTE,@data);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,@data);
//Creating a texture of the screen
//glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); << Maybe helps
glViewPort(0,0, Clientwidth, Clientheight);//Let's set my viewport back
glBindTexture(gl_Texture_2d, screenTex);//Not necessary probably ?
glBegin(GL_QUADS); //SCREEN QUAD!
//The texture is 512x512 but our screen was 480x352 so we have to adjust TexCoord!
glTexCoord2f(0,0);
glVertex3f(0,0,1);
glTexCoord2f(0,1-(160/512));//512-160=352
glVertex3f(0,352,1);
glTexCoord2f(1-(32/512),1-(160/512));//512-480=32
glVertex3f(480,352,1);
glTexCoord2f(1-(32/512),0);
glVertex3f(480,0,1);
glEnd;

Oh, and the first textures are being created with
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
becouse the screenTexture is interpolated later.

Feel free to comment, optimize, add your two cents, or show any better method.
Finally ... [cool]

Share this post


Link to post
Share on other sites

This topic is 3723 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this