Message Board


Message Board > C/C++ > OpenGL purple anti-aliased textures

June 1, 2008, 10:28
Htbaa
Perl
368 posts

Alright. For most images I get a purple border around them, which is currently delaying the release of screenshots or a demo of 2dsupershoot.



When using SDL software rendering I'm not having this problem. But with OpenGL I do, and it's supposed to be in the part of converting the SDL_Surface to a texture.

When converting a SDL_Surface to a texture I copy all pixels, including alpha value. If the image has alpha blended pixels (like the SDL_Surfaces from SDL_TTF) then that value is used. Otherwise, if the color is the same as the colorkey then it's being blended so the color won't be visible.

This is my spritesheet.


I really have no idea why the purple border is there. I thought it had to do something with how glClear was setup but that doesn't matter at all. Any suggestions?
____________
blog.htbaa.com
#
June 1, 2008, 11:11
(. )( .)
top pussy
447 posts

I'd say alpha blending isn't working.

The problem could be the graphic files or the code. Quadruple check both?
____________
gay
#
June 1, 2008, 11:15
Sandman
F3n!x0r
1194 posts

Could you paste the code for conversion?

Did you enable blending and set an appropriate blend function?
For example:
C code:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
June 1, 2008, 11:17
Htbaa
Perl
368 posts

I just had a moment to think whilst under the shower, and this fixed my problem.

C++ code:
// Get pixeldata
Uint32 pixel = get_pixel32(this->graphic, x, y);

// Get R G and B from pixel
Uint8 r,g,b,a;
SDL_GetRGBA(pixel, this->graphic->format, &r, &g, &b, &a);

// Set pixel to black transparent if the color is the
// same as the colorkey
if(pixel == this->graphic->format->colorkey) {
        r = g = b = a = 0x00;
}
// Otherwise use the provided alpha value
else {
        a = static_cast<int>(a);
}


Before all I did was this:

C++ code:
a = (pixel == this->graphic->format->colorkey) ? 0 : static_cast<int>(a);


The last part worked for SDL_TTF created SDL_Surfaces. It all works now. So I think later today some screenshots and perhaps a little demo!
____________
blog.htbaa.com
#

Message Board > C/C++ > OpenGL purple anti-aliased textures

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!