I'm wondering how to go about increasing the speed of my program. The question is what is the fastest way to draw pixels across the entire screen in one loop?
Kazzmir told me to lock the bitmap like so, but is this correct or am I supposed to draw onto a bitmap instead?
al_lock_bitmap(al_get_target_bitmap(), ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE); for(int y = 0; y < SCREEN_HEIGHT_Y; y++) { for(int x = 0; x < SCREEN_WIDTH_X; x++) { al_draw_pixel(x,y, COLOR); } } al_unlock_bitmap(al_get_target_bitmap());
You aren't allowed to use al_draw_pixel on a locked bitmap AFAIK (maybe that has changed though.) You should use al_put_pixel. Experiment with al_put_pixel+locking and ALLEGRO_VERTEXs+al_draw_prim+ALLEGRO_POINT_LIST.
ALLEGRO_VERTEXs+al_draw_prim+ALLEGRO_POINT_LIST
I'm not sure what you mean? Can you give an example?
Sure.
ALLEGRO_VERTEX my_100_pixels[100]; for (int i = 0; i < 100; i++) { // initialize pixels with random x, y my_100_pixels[i].x = rand() % SCR_W; my_100_pixels[i].y = rand() % SCR_H; my_100_pixels[i].z = 0; // set the pixels color my_100_pixels[i].color = al_map_rgb_f(1, 0, 0); // red } al_draw_prim(my_100_pixels, NULL, NULL, 0, 100, ALLEGRO_PRIM_POINT_LIST);
Obviously you don't have to do random pixels, you can set their x/y/color to whatever you want, but you probably want z to be 0 if you're doing 2d.
Obviously you don't have to do random pixels, you can set their x/y/color to whatever you want, but you probably want z to be 0 if you're doing 2d.
Does this mean I can create a 3d plot. If so, how would I move the camera or rotate the world? Is it rendered using opengl or directx?
Yeah, you can do 3d, but you have to do transformations yourself as Allegro only supports 2d transformations. You can still use the al_compose_transform, al_use_transform, al_set_projection_transform with 3d transformations but al_rotate_transform etc are only 2d. Allegro 5 always renders with OpenGL or D3D. Default is D3D on Windows and OpenGL everywhere else but you can specify with al_set_new_display_flag(ALLEGRO_OPENGL/ALLEGRO_DIRECT3D).
Basically I would need to create my own camera with culling methods and what not? What (practical) use of 3d does allegro 5 have so far then?
No, you don't need to create any of that. That's all built into OpenGL and D3D. Allegro is a 2D lib but it allows you to use OpenGL or D3D directly for any 3D stuff you want to do, and you can mix 2D Allegro drawing with your own 3D drawing.
So I would use openGL methods in the allegro code?
You'd use OpenGL calls in your own code, intermixed with Allegro calls.
I'm trying to create a class where the ALLEGRO_VERTEX is a variable size at class construction but it doesn't compile, any ideas if this is possible?
C:\pixel_class.h|11|error: invalid use of non-static data member 'pixel_class::SCREEN_HEIGHT_Y'|
C:\pixel_class.h|13|error: from this location|
C:\pixel_class.h|12|error: invalid use of non-static data member 'pixel_class::SCREEN_WIDTH_X'|
C:\pixel_class.h|13|error: from this location|
C:\pixel_class.h|13|error: array bound is not an integer constant|
||=== Build finished: 5 errors, 0 warnings ===|
Make it a pointer and new/delete it.
You'd use OpenGL calls in your own code, intermixed with Allegro calls.
In a previous thread(I can't find it anymore), someone told me that you can't mix Allegro calls with OpenGL calls because the former mess up the OpenGL state. I tried drawing text with Allegro after rendering a scene with OpenGL and I got weird results...
Could you give some example code where OpenGL is mixed with allegro drawing?
As long as you're aware of the state changes, you can do it. I have several 3d mini games that draw in 3d with 2d overlays drawn with Allegro. Actually, I draw some of the 3d parts with al_draw_prim too.
Just curious, would it be faster to use a shader than al_put_pixel?
Just curious, would it be faster to use a shader than al_put_pixel?
Alex the Alligator frowns on that.
Just curious, would it be faster to use a shader than al_put_pixel?
I could only imagine a shader would be made up of the functions that render a pixel anyway.
I guess I'm just curious if a shader has some extra magic that you wouldn't otherwise get. Point list is a cool idea, though.
Depends. If your data is stored in a texture, sure. But uploading 1000 pixels to a shader ever frame isn't going to be faster (and I'm not even sure you can do it.)