Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problems with AllegroGL tga loading and usage.

This thread is locked; no one can reply to it. rss feed Print
Problems with AllegroGL tga loading and usage.
Albin Engström
Member #8,110
December 2006
avatar

RAWR! me angry.

anyway: i'm having a problem with loading tga files and using them, the problem is that the alpha channeled pixels are replaced with solid white when i create the texture.(i think, or it could be that i don't save the tga files properly, gah, it could be anything!).

Any ideas of why this might happen??
(see the attachments)

GullRaDriel
Member #3,861
September 2003
avatar

You are not loading the texture correctly.

Show us your loading tga code and your display code (both allegro && allegro_gl). Or attach a full example that we can work on.

Hah, myself having the same problem and it was solved: Blitting TGA with ALPHA channel (OGL)Read the thread, the answer is inside.

It is a matter of how you load && display.
_
EDIT:

1/* init gfx code should have this inside */
2 
3 allegro_gl_use_alpha_channel( TRUE );
4 glBlendFunc( GL_SRC_ALPHA, GL_ONE );
5 
6
7/*display code should look like this*/
8 /* binding the texture */
9 glBindTexture( GL_TEXTURE_2D, mytexture );
10 
11 glEnable( GL_BLEND );
12 
13 glBegin( GL_QUADS );
14 /*If we set the color to white here, then the textured quad won't be*/
15 /*tinted red or half-see-through or something when we draw it based on*/
16 /*the last call to glColor*().*/
17 glColor3f( r, g, b );
18 
19 /*Draw our four points, clockwise.*/
20 glTexCoord2f( 0, 1 );
21 glVertex3f( x, y, 0 );
22 glTexCoord2f( 1, 1 );
23 glVertex3f( x + w, y, 0 );
24 glTexCoord2f( 1, 0 );
25 glVertex3f( x + w, y + h, 0 );
26 glTexCoord2f( 0, 0 );
27 glVertex3f( x, y + h , 0 );
28 glEnd();
29 
30 glDisable( GL_BLEND );
31 
32 
33 /*binding the default texture*/
34 glBindTexture( GL_TEXTURE_2D, 0 );
35
36 allegro_gl_flip();

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Milan Mimica
Member #3,877
September 2003
avatar

allegro_gl_make_texture_ex(AGL_TEXTURE_HAS_ALPHA | AGL_TEXTURE_RESCALE, bmp, GL_RGBA8);

make sure that bmp is 32 bpp color depth.

GullRaDriel
Member #3,861
September 2003
avatar

(*spr) -> handles[ it ] = allegro_gl_make_texture( (*spr) -> spr[ it ] );

Is working like a charm for me, using the sets I gave before.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Archon
Member #4,195
January 2004
avatar

Do you need to turn on GL_ALPHA_TEST ?

GullRaDriel
Member #3,861
September 2003
avatar

Yes.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Milan Mimica
Member #3,877
September 2003
avatar

Also, since AGL 0.4.1: you can do:

bmp = load_tga();
allegro_gl_set_video_bitmap_format(GL_RGBA8);
vbmp = create_video_bitmap(bmp->w, bmp->h);
blit(bmp, vbmp, 0, 0, 0, 0, vbmp->w, vbmp->h);
set_alpha_blender();
draw_trans_sprite(screen, vbmp, x, y);

GullRaDriel
Member #3,861
September 2003
avatar

Nice trick , I take note :)

Albin: Is it working now ?

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Albin Engström
Member #8,110
December 2006
avatar

No, it isn't :/, i'm going to rewrite the whole thing and then i'll write here again.

Go to: