How to get the screen refresh rate?
13,355
The Win32 EnumDisplaySettings
function could be what you're looking for. The refresh rate is held in lpDevMode->dmDisplayFrequency
.
Author by
Newbie
Updated on June 05, 2022Comments
-
Newbie almost 2 years
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; } }