Newbie
Newbie

Reputation: 1163

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;
    }
}

Upvotes: 9

Views: 18268

Answers (1)

Novikov
Novikov

Reputation: 4489

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

Upvotes: 11

Related Questions