Skip to content

Instantly share code, notes, and snippets.

@mmozeiko mmozeiko/test.c Secret
Created Jul 30, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.