I am working on a Blasteroids clone in Allegro 5 (Win32, MSVC), courtesy of Head First C's last C Lab Project.
So far I've gotten to the point of successfully drawing the spaceship on the display, and I can move it around as well with transformations.
However, when I wanted to add an FPS display in the top right corner, I've hit a roadblock. Apparently, when using al_draw_textf() to display the current FPS, it uses the already set transformations from the spaceship. So when I move the ship, the FPS display moves with it.
I am using separate functions to move the spaceship and to draw the FPS, and they are in different files as well (but the same thread).
I'm guessing this has to do with bitmaps, and everything that I draw on the screen and want to have behaving independently from other objects has to be drawn to their respective bitmaps. (Please correct me if I'm wrong.)
I've gone through the several example programs bundled with Allegro but couldn't find a clean-cut solution as the code in those included extra noise/features that made it difficult to extract the only information that I need. Also learned about hardware and software rendering, and now got confused on which one to use (to be honest I have no idea which one I'm using right now either).
Now unfortunately I don't know too much about bitmaps, hardware/software rendering, etc. to solve this myself, so I ask for your help.
Drawing from spaceship.c:
Relevant parts of main.c:
Any help would be greatly appreciated!
Make a new identity transform, and use it for your fps code. To allegro it does not matter if you have drawing code on different places. All of them share the same transformation. If you change it on one part of your code, all the next drawing calls will use the new one.
By making a new identity transform, you are resetting the transform. It does not matter you lost the previous one because your spaceship will create a new one in its drawing code.
By the looks of it, you are using hardware rendering. Software rendering uses the CPU, and Hardware uses the GPU. Allegro 4 used software, Allegro 5 by default uses hardware. If you try really hard, you can use software on 5… but it will be really slow.
Thank you for your answer!
I added a new transformation and everything works perfectly now. Apparently I was wrong with the bitmap theory.
I'm guessing this also means that I don't need to create a bitmap for each asteroid/blast, I just need separate transformations for each of them, which is really good news.
More specifically, there are two active transformations in use at any one time. They are linked to the target bitmap. When you change the target bitmap, you change the transformations. There is a view transform, and a projection transform for each bitmap.
You can draw each asteroid with it's own transformation, but you can achieve the same thing through regular allegro functions like al_draw_rotated_bitmap and the like...