|
[AGL]How do you make texture w/ alpha channel with allegro_gl_make_texture_ex()? |
BrknPhoenix
Member #7,304
June 2006
|
I asked this question further down in a different topic, however it was kind of appended as an afterthought and wasn't the main issue, so I think it just got lost in the nether. Using either a PNG or TGA, what is necessary to assure that the alpha channel or transparency is used when the texture is bound? I read the AllegroGL manual as well as some OpenGL stuff for the final parameter for allegro_gl_make_texture_ex() but none of the combinations of things I've been trying seem to be working. I think right now I'm doing something like this on a PNG. texSprite = allegro_gl_make_texture_ex(AGL_TEXTURE_HAS_ALPHA | AGL_TEXTURE_FLIP, m_sprite, GL_RGBA) I've also used GL_ALPHA at the end, as well as a combination of the two, and nothing is getting the desired result. After the above code the texture is later blended with GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA. |
Bob
Free Market Evangelist
September 2000
|
Does your loaded bitmap contain the alpha channel you expect? The call to AGL your pasted looks correct. -- |
Matt Smith
Member #783
November 2000
|
Attach the TGA file so we can check if it does have an alpha channel saved. Some paint progs will strip it on saving, and I for one am not sure under which circumstances load_tga() will strip it on loading. |
BrknPhoenix
Member #7,304
June 2006
|
Alright, I'll post it when I get off work... And am I the only one who only sees a horizontal scrolling bar in my initial post in this topic and no code? Here's the PNG I've been using [img]http://img.photobucket.com/albums/v160/BrknPhoenix/greencursor.png[/img] I'm not even going to bother with the TGA version because I'm pretty confident already it wasn't saving the alpha in photoshop. I've read on numerous forums that Photoshop has crap Targa support, and on Adobe's site it said PS7 required a patch for it to properly save the Targa alpha channel. And I only have Photoshop Elements 4.0 And I just posted this PNG image on a forum with a non-white background and the transparency is good. So I'm guessing that something with AllegroPNG isn't getting the transparency. |
gnolam
Member #2,030
March 2002
|
Are you loading the bitmap as 32 bit? -- |
Erkle
Member #3,493
May 2003
|
Quote: Are you loading the bitmap as 32 bit? ie. Are you doing this? int old_depth = get_color_depth(); BITMAP* texSprite = load_tga("blah.tga", NULL); set_color_depth(old_depth); texSprite = allegro_gl_make_texture_ex(AGL_TEXTURE_HAS_ALPHA | AGL_TEXTURE_FLIP , m_sprite, GL_RGBA); This makes allegro load the bitmap as 32-bit. In my opinion the API should make this native somehow (ie. load_tga_ex(32, "blah.tga", NULL)) but it would require API breakage. Maybe in Allegro 5.0.
If the writing above has offended you, you've read it wrong.....fool. |
Fladimir da Gorf
Member #1,565
October 2001
|
Did you remember to enable blending in OpenGL? OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
BrknPhoenix
Member #7,304
June 2006
|
Yes, blending is enabled. And no, I'm not saving as 32 bit in targa :p That's part of the problem. I haven't been using TGA images because I can't find anything that saves 32 bit Targa's. My photoshop elements 4.0 apparently doesn't save TGA alpha channels at all, and GIMP keeps saving as 24 bit even though the targa has an alpha channel. And I'm not loading the png in 32 bit because it's not a 32 bit png... I really don't know what to do here :\ |
Milan Mimica
Member #3,877
September 2003
|
GIMP saves the alpha channel in TGA fine.
-- |
BrknPhoenix
Member #7,304
June 2006
|
Hm, I don't suppose someone could upload a Targa that they know for a fact is 32-bit with transparency so I could test it with my program? So I could know whether it's the image or the code that is my problem? |
Milan Mimica
Member #3,877
September 2003
|
here
-- |
BrknPhoenix
Member #7,304
June 2006
|
edit: Solved! The problem was that GL_DEPTH_TEST was enabled while this was being done, so objects were failing the depth test instead of being blended transparently. Well, let me post the whole of what is going on in my code, and maybe someone will spot something. Note that this code is rather poorly put together, mostly because it's the result of me deleting and re-typing over and over again to try and make things work. As for what actually happens... The image will display, but the parts that should be transparent appear as black instead. Setting up the screen initially... glMatrixMode(GL_PROJECTION); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glEnable(GL_ALPHA_TEST); allegro_gl_use_alpha_channel(TRUE); glLoadIdentity(); gluPerspective(45.0f, (GLfloat)SCREEN_WIDTH / (GLfloat)SCREEN_HEIGHT, 1.0f, 1000.0f); glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Loading the texture... int old_c_depth = get_color_depth(); set_color_depth(32); m_sprite = load_tga(filename, NULL); texSprite = allegro_gl_make_texture_ex(AGL_TEXTURE_HAS_ALPHA | AGL_TEXTURE_FLIP, m_sprite, GL_RGBA); set_color_depth(old_c_depth); Setting up the screen for 2D drawing for the mouse cursor...
The code that actually draws it...
|
|