Rendering a 2d Array

I have had this program for a while...

I am creating a ray tracing program that needs to create the entire screen pixel by pixel. I used to do this in Allegro 4 by drawing in a bitmap that was the buffer and bliting it to the screen.

As a baseline test in Allegro 4 I would typically just make every pixel on the screen a random color like so...
for(int i = 0; i < width; i++)
for(int j = 0; j < height; j++)
putpixel(buffer, i, j, makecol(rand()%255, rand()%255, rand()%255));
I would do this every frame and could get about 200fps on a powerful computer...

However in Allegro 5 it seems just doing this to the screen is very slow probably about 15 - 30 fps?

I am wondering what is the fastest way to create an entire bitmap pixel by pixel then bliting it to the screen??


I believe the fastest way is to access the memory directly by locking the bitmap, something like this:


for (int y = 0; y != height; ++y) {
    uint8_t *ptr = (uint8_t *)lr->data + y * lr->pitch;
    for (int x = 0; x != width; ++x) {
        *ptr++ = red;
        *ptr++ = green;
        *ptr++ = blue;
        *ptr++ = alpha


Thread #613750. Printed from