Sign in to follow this  

Blending&textures problem.

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

I'm creating a 2D game and I want to use some transparent sprites, but the blending doesn't work for me the way I want it to work. I've made a 2x2 texture to test it. CODE! texlist[1]:=255; //1 R texlist[2]:=0; /// 1 G texlist[3]:=0; /// 1 B texlist[4]:=255; //1 A texlist[5]:=0; /// 2 R texlist[6]:=255; //2 G texlist[7]:=0; /// 2 B texlist[8]:=255; //2 A texlist[9]:=0; /// 3 R texlist[10]:=0; // 3 G texlist[11]:=255;//3 B texlist[12]:=255;//3 A texlist[13]:=255;//4 R texlist[14]:=0; // 4 G texlist[15]:=255;//4 B texlist[16]:=0; // 4 A gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, 2,2, GL_RGBA, GL_BYTE, @texlist); END OF CODE! The output was 1 on this pic: http://img222.imageshack.us/img222/2118/rgbajm9.jpg But I want it to work as shown on second pic - I want the entire transparent pixel not to be visible. I've been trying almost everything. The key is probably the glAlphaFunc or glBlendFunc glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5); // modyfying this value changes the radius of that transparent circle. glBlendFunc(GL_ONE,GL_ONE); glEnable(GL_BLEND); additional pic http://img233.imageshack.us/img233/8564/50869792ov3.jpg

Share this post


Link to post
Share on other sites
It didn't change anything. I have later figured that blending doesn't matter here anyway.

But well I have changed glAlphaFunc(GL_GREATER, 0.8); to 0.8 as it has given best results and loaded some sprites. Take a look.

http://img219.imageshack.us/img219/2397/charsei4.png
http://img127.imageshack.us/img127/7311/closeer2.png

My looks like pasted in paint :|. How do I make it so that edges blends or w/e is happening there

Share this post


Link to post
Share on other sites
I got some better results using

//glEnable(GL_ALPHA_TEST);
//glAlphaFunc(GL_GREATER, 0.1);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
I didn't know that turning alpha test off may improve this :P

http://i14.photobucket.com/albums/a311/Enderdil/sprite.jpg?t=1191145705

But now anyone knows how to get rid of those lines?

Edit. Where can I get newer OpenGL libraries for Delphi?
coz ... [Error] main.pas(114): E2003 Undeclared identifier: 'GL_MIRRORED_REPEAT'

[Edited by - Enderdil on September 30, 2007 7:35:20 AM]

Share this post


Link to post
Share on other sites
Those are most likely edge artifacts from the texture/sprite itself. Have you checked the sprite images themselves to assert that the edges of them are clean? If they are, then its some GL border issue or such, and I'm drawing a blank.

Share this post


Link to post
Share on other sites
Sprites are 100% fine, but OpenGL tries to repeat those textures probably. I've managed to disable repeating by
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
but then other textures looks worse (eg. ground sprites)
http://i14.photobucket.com/albums/a311/Enderdil/GL_CLAMP.jpg?t=1191182304
I thought that solution for this would be adding a property for each texture telling to CLAMP or to REPEAT but what if my sprite looks like that!
http://i14.photobucket.com/albums/a311/Enderdil/compare.jpg?t=1191182897
Notice the lines at the top and bottom on the repeating one.

EDIT;
I've been thinking on creating textures using:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
then drawing everything I want
http://i14.photobucket.com/albums/a311/Enderdil/grainy.jpg?t=1191188107
and then SMOTHING THE ENTIRE SCREEN just like textures are being smothed when using
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Is there any easy way (glEnable ?) or would I have to copy the screen as a testure and draw it on one quad on the screen ?

[Edited by - Enderdil on September 30, 2007 4:54:17 PM]

Share this post


Link to post
Share on other sites

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