![]() |
|
fastest way to plot pixels A5 |
verthex
Member #11,340
September 2009
![]() |
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());
|
Trent Gamblin
Member #261
April 2000
![]() |
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.
|
verthex
Member #11,340
September 2009
![]() |
Trent Gamblin said: ALLEGRO_VERTEXs+al_draw_prim+ALLEGRO_POINT_LIST I'm not sure what you mean? Can you give an example?
|
Trent Gamblin
Member #261
April 2000
![]() |
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.
|
verthex
Member #11,340
September 2009
![]() |
Trent Gamblin said: 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?
|
Trent Gamblin
Member #261
April 2000
![]() |
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).
|
verthex
Member #11,340
September 2009
![]() |
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?
|
Trent Gamblin
Member #261
April 2000
![]() |
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.
|
verthex
Member #11,340
September 2009
![]() |
So I would use openGL methods in the allegro code?
|
Trent Gamblin
Member #261
April 2000
![]() |
You'd use OpenGL calls in your own code, intermixed with Allegro calls.
|
verthex
Member #11,340
September 2009
![]() |
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? 1#include <allegro5/allegro.h>
2#include <allegro5/allegro_primitives.h>
3
4class pixel_class
5{
6 private:
7
8 int SCREEN_HEIGHT_Y;
9 int SCREEN_WIDTH_X;
10 ALLEGRO_VERTEX pixels[SCREEN_HEIGHT_Y*SCREEN_WIDTH_X];
11
12 public:
13
14 pixel_class(){}
15 ~pixel_class(){}
16 pixel_class(int sw, int sh)
17 {
18 SCREEN_HEIGHT_Y = sh;
19 SCREEN_WIDTH_X = sw;
20 }
21};
C:\pixel_class.h|11|error: invalid use of non-static data member 'pixel_class::SCREEN_HEIGHT_Y'|
|
Trent Gamblin
Member #261
April 2000
![]() |
Make it a pointer and new/delete it.
|
J-Gamer
Member #12,491
January 2011
![]() |
Trent Gamblin said: 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... " There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo |
Trent Gamblin
Member #261
April 2000
![]() |
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.
|
Mark Oates
Member #1,146
March 2001
![]() |
Just curious, would it be faster to use a shader than al_put_pixel? -- |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Mark Oates said: Just curious, would it be faster to use a shader than al_put_pixel? Alex the Alligator frowns on that. They all watch too much MSNBC... they get ideas. |
verthex
Member #11,340
September 2009
![]() |
Mark Oates said: 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.
|
Mark Oates
Member #1,146
March 2001
![]() |
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. -- |
Trent Gamblin
Member #261
April 2000
![]() |
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.)
|
|