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)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay