-
-
Save mmozeiko/9b661cf8f48b56945984d518a9cd6310 to your computer and use it in GitHub Desktop.
Timing pixel format functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
int main() | |
{ | |
HWND wnd = CreateWindowA("STATIC", "test", WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | |
NULL, NULL, NULL, NULL); | |
if (!wnd) | |
{ | |
printf("CreateWindow error\n"); | |
return 0; | |
} | |
HDC dc = GetDC(wnd); | |
if (!dc) | |
{ | |
printf("GetDC error\n"); | |
return 0; | |
} | |
PIXELFORMATDESCRIPTOR pfd = | |
{ | |
.nSize = sizeof(pfd), | |
.nVersion = 1, | |
.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL, | |
.iPixelType = PFD_TYPE_RGBA, | |
.cColorBits = 24, | |
.iLayerType = PFD_MAIN_PLANE, | |
}; | |
LARGE_INTEGER f, t1, t2; | |
QueryPerformanceFrequency(&f); | |
QueryPerformanceCounter(&t1); | |
int pf = ChoosePixelFormat(dc, &pfd); | |
if (!pf) | |
{ | |
printf("ChoosePixelFormat error\n"); | |
return 0; | |
} | |
BOOL set = SetPixelFormat(dc, pf, &pfd); | |
if (!set) | |
{ | |
printf("SetPixelFormat error\n"); | |
return 0; | |
} | |
QueryPerformanceCounter(&t2); | |
printf("%.3f\n", (double)(t2.QuadPart - t1.QuadPart)/f.QuadPart); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment