Skip to content

Instantly share code, notes, and snippets.

@mmozeiko

mmozeiko/test.c Secret

Created July 30, 2017 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmozeiko/9b661cf8f48b56945984d518a9cd6310 to your computer and use it in GitHub Desktop.
Save mmozeiko/9b661cf8f48b56945984d518a9cd6310 to your computer and use it in GitHub Desktop.
Timing pixel format functions
#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