DEV Community

Audi Nugraha
Audi Nugraha

Posted on

Snippets

Get screen dimension.

RECT rect;
GetWindowRect(wnd, &rect);
#define SCREEN_WIDTH  rect.right
#define SCREEN_HEIGHT rect.bottom
Enter fullscreen mode Exit fullscreen mode

Is keyboard key or mouse button down?

See: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes

GetAsyncKeyState(VK_SPACE)
Enter fullscreen mode Exit fullscreen mode

Get mouse location.

POINT point;
GetCursorPos(&point);
#define MOUSE_X point.x
#define MOUSE_Y point.y
Enter fullscreen mode Exit fullscreen mode

Load texture from file (using GDI+).

ULONG_PTR token;
GdiplusStartupInput gsi = { .GdiplusVersion = 1 };
GdiplusStartup(&token, &gsi, 0);
// ...
GpBitmap* bitmap;
GdipCreateBitmapFromFile(L"texture.jpg", &bitmap);
BitmapData data = {};
GdipBitmapLockBits(bitmap, 0, 0, PixelFormat32bppARGB, &data);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data.Width, data.Height, 0, GL_BGRA, GL_UNSIGNED_BYTE, data.Scan0);
GdipBitmapUnlockBits(bitmap, &data);
GdipDisposeImage(bitmap);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)