I want to draw a very large amount of triangles (up to 600000). What I did first was to:
al_init(); display = al_create_display();
and then loop through my triangles and
al_draw_triangle(); each one.
Finally I did
This was not very fast though. I read that it helps to draw to a bitmap on hold first and then draw that bitmap to the display. I tried to do this in the following fashion (sketched):
al_init(); display = al_create_display(); bitmap = al_create_bitmap(); al_set_target_bitmap(bitmap); al_hold_bitmap_drawing(1); for every triangle: al_draw_triangle(); al_hold_bitmap_drawing(0); al_set_target_bitmap(al_get_backbuffer(display)); al_draw_bitmap(bitmap, 0, 0, 0); al_flip_display();
This is just as fast as the previous method though. How can I correctly buffer my triangles to reduce the amount of draws? What is the most efficient way to draw many primitives in Allegro 5?
Thanks for all answers
You'll get better performance from al_draw_vertex_buffer and al_draw_indexed_buffer.
Also, al_hold_bitmap_drawing does not do what you think it does. It pauses BITMAP drawing, not drawing in general. There is currently no way to batch primitive drawing, except through the API.
If you need something more advanced, there is DX and OpenGL.
Thanks for the suggestion.
I'm not sure how to use al_draw_vertex_buffer. It seems like I pick a vertex for each triangle and then create a small bitmap which has the triangle and a transparent background. Then I set that triangle as the texture for that vertex.
Is that how it works?
The texture is optional. Set a coordinate and a color for every vertex and then pass it to the function. I'll give a better example in a little bit.
Ah yes I see now that vertex buffers are exactly what I need, I read that transferring the data to the GPU is the problem and the vertex buffer description says it solves exactly that.
I just need to figure out how exactly to use it, maybe Ill do it tomorrow or see it in your example if you post one.
Thx a lot
Simplest way to do it is to use an array of ALLEGRO_VERTEX to initialize it with.