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)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay