user9717641
user9717641

Reputation:

Getting pixel color from display in allegro5

I've been trying to check if pixel color is green and I've seen this:

Checking pixel color Allegro 5 C++,

but I don't have bitmap in my code.

I was searching in allegro5 documentation and it seems like there's nothing which can help me.

Is there any solution to convert display to bitmap? Or to get pixel color from display? Anyone knows how to do it? I have position of my pixel and nothing more.

Upvotes: 1

Views: 352

Answers (2)

Michael
Michael

Reputation: 1

I tried the following and i got some results

    ALLEGRO_BITMAP *bitmap;
    bitmap = al_get_backbuffer(display);
    ALLEGRO_COLOR color = al_get_pixel(bitmap,x,y);

    bool isBlack = (color.r ==0 && color.g == 0 && color.b ==0);
    if(!isBlack){
        alive=0;
        explode() or something
    }

Upvotes: 0

rcorre
rcorre

Reputation: 7218

Use al_get_backbuffer to get the display as a bitmap, then use al_get_pixel to retrieve a pixel.

Upvotes: 1

Related Questions