![]() |
|
Rotate sprite while using alpha channel |
Evilish
Member #8,610
May 2007
|
I'm using Dev-C++ to create a small game, and I've had a lil trouble finding out a fast way of rendering this. I know that after using set_alpha_blender, I can draw a image onto the buffer with an alpha channel using draw_trans_sprite, but I wanna know if there is anyway of doing this with the rotate_/pivot_ sprite functions? One idea I had was to draw to a third buffer the rotated sprite, then draw the alpha channel directly to that as well, but it's very slow and I can't use depth with that anymore... Oh and hello btw, my first post here, ^_^ - Evilish |
Ceagon Xylas
Member #5,495
February 2005
![]() |
You could create a temporary bitmap, rotate the original bitmap and blit it to the temporary one. Then draw the temporary bitmap onto your buffer with the specified blender. BITMAP *original=load_bitmap(...); //15x38 BITMAP *temp=create_bitmap(max(original->w,original->h), max(original->w,original->h)); //See below clear_to_color(temp,bitmap_mask_color(temp)); rotate_sprite(temp,original,0,0,angel); set_trans_blender(...); draw_trans_sprite(buffer,temp,...); //*if you've never used max, it's just a function that returns //the higher value of two numbers. So, max(20,44), would return 40 For the note, OpenLayer does things like this verrry easily. |
Kris Asick
Member #1,424
July 2001
|
Don't use max(). Instead, calculate the length of the diagonal of your sprite and use that. Otherwise you might clip the corners off depending on the shape of the sprite! sqrt(sprite->w*sprite->w+sprite->h*sprite->h) Then one method you can do is to pre-draw a set of rotations to a bunch of bitmaps, then all you do is choose which of those frames to draw mid-game. Sure, it doesn't look as smooth as doing the rotations on the fly, but to really get alpha-blended plus rotated quality you should be doing hardware acceleration, either yourself or with Openlayer or AllegroGL. You also must be using 32-bit colour bitmaps. Allegro doesn't support alpha channels in any other colour depth. (However, you might still be able to get away with drawing a 32-bit alpha-blended sprite onto a 15/16/24-bit surface. Just make sure to disable colour conversions when you load the sprites you plan to draw in this fashion, otherwise they will be converted automatically to be 100% compatable with the current screen format, and thus might lose their alpha channel.) --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
|