Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the screen refresh rate?

Is this even possible? Since ive noticed v-sync doesnt work on my laptop at all, so i am building FPS limiter "manually" and now i would like to use the FPS limit the user has set to his screen.

Edit: i mean the monitor hz rate.

Edit3: heres the code i got working (i think... anything wrong there?):

DEVMODE lpDevMode;
memset(&lpDevMode, 0, sizeof(DEVMODE));
lpDevMode.dmSize = sizeof(DEVMODE);
lpDevMode.dmDriverExtra = 0;

if(EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &lpDevMode) == 0){
    framerate_limit = 60; // default value if cannot retrieve from user settings.
}

On demand, here is my v-sync enabling code jay.lee asked for:

PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL; // global

...

wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");

v_sync_enabled = 0;
if(wglSwapIntervalEXT != NULL){
    if(wglSwapIntervalEXT(1) != FALSE){
        v_sync_enabled = 1;
    }
}
like image 521
Newbie Avatar asked Nov 05 '10 22:11

Newbie


1 Answers

The Win32 EnumDisplaySettings function could be what you're looking for. The refresh rate is held in lpDevMode->dmDisplayFrequency.

like image 166
Novikov Avatar answered Oct 01 '22 03:10

Novikov