Hello,
This might be an idiotic question, but is it possible to use an RGB array consisting of 3 or 4 bytes per pixel and get it on screen using allegro 4 or 5 in a simple manner (be it windows or a linux based os) ?
I have browsed the wiki and googled around but i could not find an example or anything refering to this way of using Allegro. And if this is unclear, i would use
the following to manipulate the pixels in the array ; (y_pos * (width * bpp) + (x_pos * bpp))
This might be an idiotic question, but is it possible to use an RGB array consisting of 3 or 4 bytes per pixel and get it on screen using allegro 4 or 5 in a simple manner (be it windows or a linux based os) ?
Yes, it is not very hard in either version. Also, it depends on how often you need to do it.
Allegro 4
Allegro 5
I left out setting up a display with either one, but I thought the tutorials should at least be able to show you how to do that. Check out the Allegro 4 Wiki Tutorial, and the Allegro 5 Tutorials.
Ah, nice ! Thank you for that.
I was looking for a library which allows one to do that in a simple and clean way so i wanted to make sure before i dive into Allegro, as a certain simple media library made that ordeal look like a hell to me.
Things to keep in mind - draw_trans_sprite is using memory blending and al_draw_bitmap is using hardware acceleration and also unlocking a locked region can be slow because it has to upload to the gpu in case of a video bitmap.
If you have no control over how the RGB pixel data gets created (memory location, RGB ordering, "pitch" between different lines), SDL has a very handy function which avoids duplicating the image in memory : SDL_CreateRGBSurfaceFrom()
It exists both in SDL 1.2 and SDL 2.0
The typical usage is :
obtain your pixel data
call mySurface = SDL_CreateRGBSurfaceFrom(), it creates a fake Surface which actually points to your pixel data
draw mySurface on screen. ex: SDL_BlitSurface() with SDL 1.2. SDL can easily display an image of any RGB ordering into a screen mode with any RGB ordering.
Free_surface(mySurface) to free the fake Surface
dispose of the original pixel data.