Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » _al_wgl_get_display_mode not returning format

Credits go to Edgar Reynaldo, Elias, Peter Wang, and Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
_al_wgl_get_display_mode not returning format
tobing
Member #5,213
November 2004
avatar

During some implementation of enumerating display modes I accidentally found, that _al_wgl_get_display_mode does not set the format field in ALLEGRO_DISPLAY_MODE... which seems to be by design, but I would suggest to set the format at least to ALLEGRO_PIXEL_FORMAT_ANY to have the field be initialized.

I put in this code:

#SelectExpand
1 switch(dm.dmBitsPerPel) 2 { 3 case 32: 4 mode->format = ALLEGRO_PIXEL_FORMAT_ANY_32_WITH_ALPHA; 5 break; 6 case 24: 7 mode->format = ALLEGRO_PIXEL_FORMAT_ANY_24_NO_ALPHA; 8 break; 9 case 16: 10 mode->format = ALLEGRO_PIXEL_FORMAT_ANY_16_WITH_ALPHA; 11 break; 12 default: 13 mode->format = format; 14 break; 15 }

so the caller can at least identify the number of bits for the color values of the selected display format. The parameter format is the result of some routine trying to indentify the pixel format - in my case that value was 0, because the format couldn't be identified.

Elias
Member #358
May 2000

I just tried ex_display_options, it displays the correct color size (32 in my case). Is there another way to see the problem?

--
"Either help out or stop whining" - Evert

tobing
Member #5,213
November 2004
avatar

I'm using something like this

    const int n_display_modes = al_get_num_display_modes();
    for(int i=0; i<n_display_modes; ++i)
    {
        ALLEGRO_DISPLAY_MODE mode;
        al_get_display_mode(i, &mode);
        if(addElement(mode.width, mode.height))
        {
            if(write_log)
                gfw_log(2,1, "display mode %d: %d x %d at %d Hz, format %d = %d bits", i, mode.width, mode.height, mode.refresh_rate, mode.format, 8*al_get_pixel_size(mode.format));
        }
    }

and there it turns out that mode.format is uninitialized, if the current display was created with ALLEGRO_OPENGL.

Edit: I have modified the proposed change a bit, to only set a format when there's nothing else set. A patch is attached.

Another edit: I'll bump this a last time now, maybe someone is willing to look at it and add it, or tell me that it's not going to be added and maybe why. :o

Edgar Reynaldo
Member #8,592
May 2007
avatar

tobing
Member #5,213
November 2004
avatar

Peter Wang
Member #23
April 2000

The 24 bit case looks weird, doesn't it? I'm not familiar with this part of the API though.

Trent Gamblin
Member #261
April 2000
avatar

I'm not sure this is helpful, but I'll say something. When we were first implementing this stuff I noticed this too... IIRC the explanation I got from Milan and/or Elias was that OpenGL displays don't actually have a color depth (on Windows only?) or that you can't detect it. I didn't and still don't understand that... but I think that's why it is this way. Not sure if that's true or not, but it'd be nice to find out so we can do what's appropriate.

Your patch seems fine to me but I'm hesitant to apply it because I don't understand that "doesn't have a color depth" tidbit I got when I asked a few years ago.

EDIT: Ah, I think it's come back to me. They said you can't get a pixel format, not a color depth. So if that's the case the patch should be ok.

tobing
Member #5,213
November 2004
avatar

Yes, I have tried to find out from the documentation, you can find out the color depth but not the pixel format. That's where the constants with ANY come in handy.

Thanks for looking at this.

Trent Gamblin
Member #261
April 2000
avatar

I've applied your patch. Thanks!

tobing
Member #5,213
November 2004
avatar

Thanks from my side. 8-)

Go to: