Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] Lit (fog?) on sprite

This thread is locked; no one can reply to it. rss feed Print
[A5] Lit (fog?) on sprite
anto80
Member #3,230
February 2003
avatar

Hello all,

I'm trying to port my old Allegro 4 code with AllegroGL to Allegro 5.
This concerns the drawing of a 'lit' sprite (the equivalent of draw_lit_sprite in allegro 4.2)

With AllegroGL I was doing this :

#SelectExpand
1glLoadIdentity(); 2glTranslatef(fx, fy, 0.0); 3glScalef(fScaleX, fScaleY, 0); 4if (fRot360 != 0.0f) glRotated(fRot360, 0, 0, 1); 5 6glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 7glBindTexture(GL_TEXTURE_2D, m_texSprite); 8 9if (fLitLevel >= 1e-2) 10{ 11 glFogi( GL_FOG_MODE, GL_LINEAR ); 12 float fogCol[] = {fLitR, fLitG, fLitB, 1.0f}; 13 14 glFogfv( GL_FOG_COLOR, fogCol ); 15 glFogf( GL_FOG_DENSITY, 1.0 ); 16 17 glFogf( GL_FOG_START, -fLitLevel ); 18 glFogf( GL_FOG_END, (1.0 - fLitLevel)); 19 20 glHint( GL_FOG_HINT, GL_FASTEST ); 21 glEnable( GL_FOG ); 22 { 23 glColor3f(1, 1, 1); 24 DrawTheQuadWithGL_QUADS(...) 25 } 26 27 glDisable( GL_FOG ); 28} 29else 30{ 31 glColor4f(1.0f, 1.0f, 1.0f, fAlpha); 32 DrawTheQuadWithGL_QUADS(...) 33}

If I understand correctly the Allegro 5 documentation, managing alpha layer is done by using al_draw_tinted_xx_bitmap.
However I can't find how to lit(fog) a sprite.

#SelectExpand
1if (fAlpha < 1.0f) 2{ 3 al_draw_tinted_scaled_rotated_bitmap(m_bmpSprite, 4 al_map_rgba_f(1.0f*fAlpha, 1.0f*fAlpha, 1.0f*fAlpha, fAlpha), 5 cx, cy, fx, fy, fScaleX, fScaleY, fRot360, 0x00); 6} 7else 8{ 9 if (fLitLevel > 0.0f) 10 { 11 // ??? 12 } 13 else 14 { 15 al_draw_scaled_rotated_bitmap(m_bmpSprite, cx, cy, fx, fy, 16 fScaleX, fScaleY, fRot360, 0x00); 17 } 18}

One more question:
Is it faster to continue on using glLoadIdentity / glTranslatef / glScalef / glRotated or to switch to various Allegro 5 methods using _scaled_ / _rotated_ ?

Thank you in advance for your help.

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Todd Cope
Member #998
November 2000
avatar

al_draw_tinted_*() just sets the color of each vertex to the passed tint color. This works in conjunction with the currently set blender to get the final result.

You cannot achieve the lit sprite effect you are talking about using Allegro functions unless you use a shader.

anto80 said:

Is it faster to continue on using glLoadIdentity / glTranslatef / glScalef / glRotated or to switch to various Allegro 5 methods using scaled / rotated ?

I can't say for certain (don't have time to look at Allegro's code), but just considering A5 has to apply the current transformation and then translate, scale, and rotate, your OpenGL code is probably a bit faster.

beoran
Member #12,636
March 2011

I think it's possible to draw lights using Allegro5 using a trick: draw one or more white or grayscale circle with an alpha 0.5 or so over the part you want to give a highlight. For fog, you could use a suitable half-transparent fog sprite in the same manner. But yes, for "real" fog you will need OpenGL or shaders.

anto80
Member #3,230
February 2003
avatar

Thank you for your feedback.

I also thought about drawing a filled rectangle with color and transparency. But I agree with you it won't work if the target sprite is not rectangular.

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

Go to: