#include "GameLib.h"
int main() {
GameLib game;
game.Open(640, 480, "Title", true);
while (!game.IsClosed()) {
game.Clear(COLOR_BLACK);
// ...draw here...
game.Update();
game.WaitFrame(60);
}
}
Build: g++ -o game.exe main.cpp -mwindows
Open(w, h, title, center=false, resizable=false) → 0=OKIsClosed() window closed?Update() flush frame & poll inputWaitFrame(fps) frame rate limitGetWidth() / GetHeight() framebuffer sizeGetFramebuffer() raw pixel pointer (uint32_t*), index as fb[y*W+x]WinResize(w, h) resize client areaSetMaximized(bool) maximize (resizable only)GetDeltaTime() frame delta (s, double)GetFPS() / GetTime() FPS & elapsed timeSetTitle(title) change title (UTF-8)ShowFps(bool) FPS in titlebarShowMouse(bool) show/hide cursorShowMessage(text, title, btns) message boxButtons: MESSAGEBOX_OK / MESSAGEBOX_YESNO
Returns: MESSAGEBOX_RESULT_OK / _YES / _NO
Clear(color=BLACK) fill clip rect (no blend)SetPixel(x, y, color) draw pixel (alpha blend)GetPixel(x, y) read pixelSetClip(x, y, w, h) set clip rectClearClip() reset to full screenGetClip(&x,&y,&w,&h) / GetClipX/Y/W/H()Screenshot(filename) save BMPDrawLine(x1, y1, x2, y2, color)DrawRect(x, y, w, h, color) outlineFillRect(x, y, w, h, color)DrawCircle(cx, cy, r, color)FillCircle(cx, cy, r, color)DrawEllipse(cx, cy, rx, ry, color)FillEllipse(cx, cy, rx, ry, color)DrawTriangle(x1,y1, x2,y2, x3,y3, color)FillTriangle(x1,y1, x2,y2, x3,y3, color)DrawText(x, y, text, color)DrawNumber(x, y, number, color)DrawTextScale(x, y, text, color, w, h)DrawPrintf(x, y, color, fmt, ...)DrawPrintfScale(x, y, color, w, h, fmt, ...)DrawTextFont(x, y, text, color, fontSize)DrawTextFont(x, y, text, color, fontName, fontSize)DrawPrintfFont(x,y, color, size, fmt,...)DrawPrintfFont(x,y, color, name, size, fmt,...)GetTextWidthFont(text, [fontName,] fontSize)GetTextHeightFont(text, [fontName,] fontSize)CreateSprite(w, h) → ID (-1=fail)LoadSprite(file) PNG/JPG/BMP/GIF/TIFFLoadSpriteBMP(file) BMP 8/24/32-bitFreeSprite(id)DrawSprite(id, x, y) opaque fast pathDrawSpriteEx(id, x, y, flags)DrawSpriteRegion(id, x, y, sx, sy, sw, sh)DrawSpriteRegionEx(id, x,y, sx,sy,sw,sh, flags)DrawSpriteScaled(id, x, y, w, h, flags=0)DrawSpriteRotated(id, cx, cy, angle, flags=0)DrawSpriteFrame(id, x,y, fW,fH, idx, flags=0)DrawSpriteFrameScaled(id, x,y, fW,fH, idx, w,h, flags=0)DrawSpriteFrameRotated(id, cx,cy, fW,fH, idx, angle, flags=0)Set/GetSpritePixel(id, x, y [,color])GetSpriteWidth(id) / GetSpriteHeight(id)Set/GetSpriteColorKey(id [,color])| Flag | Val | Effect |
|---|---|---|
SPRITE_FLIP_H | 1 | Horizontal flip |
SPRITE_FLIP_V | 2 | Vertical flip |
SPRITE_COLORKEY | 4 | Color key transp. |
SPRITE_ALPHA | 8 | Per-pixel alpha |
COLORKEY_DEFAULT = 0xFFFF00FF (magenta). Flags combinable with |
IsKeyDown(key) held downIsKeyPressed(key) just pressed (edge)IsKeyReleased(key) just released (edge)GetMouseX() / GetMouseY() logical posIsMouseDown(btn) / IsMousePressed(btn)IsMouseReleased(btn)GetMouseWheelDelta() since last UpdateIsActive() window focused?MOUSE_LEFT=0 MOUSE_RIGHT=1 MOUSE_MIDDLE=2
KEY_LEFT/RIGHT/UP/DOWN KEY_A ~ KEY_Z KEY_0 ~ KEY_9 KEY_F1 ~ KEY_F12 KEY_SPACE KEY_ENTER KEY_ESCAPE KEY_TAB KEY_SHIFT KEY_CONTROL KEY_BACK
All mapped to Windows Virtual Key Codes.
PlayWAV(file, repeat, volume) → channel ID, -1/-2/-4=failPlayPCM(pcm, nch, nsamp, rate, repeat, volume) → channel ID, -1/-2/-4=failStopWAV(channel) → 1=successIsPlaying(channel) → 1/0SetVolume(channel, volume) 0~1000StopAll() stop all WAVSetMasterVolume(volume) 0~1000, returns actualGetMasterVolume()PlayMusic(file, loop) MP3/MIDI/WAV → trueStopMusic()IsMusicPlaying()PlayBeep(freq, duration, repeat, volume) async, returns channel IDWAV and Music are independent, can play simultaneously. Volume range: 0~1000.
CreateTilemap(cols, rows, tileSize, tilesetId) → IDLoadTilemap(file, tilesetId) from .glmSaveTilemap(file, mapId) to .glmFreeTilemap(mapId)SetTile(mapId, col, row, tileId) -1=emptyGetTile(mapId, col, row)GetTilemapCols/Rows(mapId) / GetTileSize(mapId)WorldToTileCol(mapId, x) / WorldToTileRow(mapId, y)GetTileAtPixel(mapId, x, y)FillTileRect(mapId, col, row, cols, rows, tileId)ClearTilemap(mapId, tileId=-1)DrawTilemap(mapId, x, y, flags=0)Scroll: DrawTilemap(id, -camX, -camY). Supports COLORKEY/ALPHA flags.
SetScene(scene) switch next frameGetScene() current sceneIsSceneChanged() 1st frame of new scene?GetPreviousScene()Use enum { MENU, PLAY, OVER }. Initial=0, first frame IsSceneChanged()=true.
Button(x, y, w, h, text, color) → true on clickCheckbox(x, y, text, &checked) toggleRadioBox(x, y, text, &value, index) mutual exclusiveToggleButton(x, y, w, h, text, &toggled, color)GameLib::SaveInt(file, key, value)GameLib::SaveFloat(file, key, value)GameLib::SaveString(file, key, value)GameLib::LoadInt(file, key, def=0)GameLib::LoadFloat(file, key, def=0.0f)GameLib::LoadString(file, key, def="")GameLib::HasSaveKey(file, key)GameLib::DeleteSaveKey(file, key)GameLib::DeleteSave(file)File: GAMELIB_SAVE header + key=value lines. UTF-8 paths.
GameLib::Random(min, max) int [min,max]GameLib::RectOverlap(x1,y1,w1,h1, x2,y2,w2,h2)GameLib::CircleOverlap(cx1,cy1,r1, cx2,cy2,r2)GameLib::PointInRect(px, py, x, y, w, h)GameLib::Distance(x1, y1, x2, y2) → floatDrawGrid(x, y, rows, cols, size, color)FillCell(gx, gy, row, col, size, color)
COLOR_BLACK
COLOR_WHITE
COLOR_RED
COLOR_GREEN
COLOR_BLUE
COLOR_YELLOW
COLOR_CYAN
COLOR_MAGENTA
COLOR_ORANGE
COLOR_PINK
COLOR_PURPLE
COLOR_GRAY
COLOR_DARK_GRAY
COLOR_LIGHT_GRAY
COLOR_DARK_RED
COLOR_DARK_GREEN
COLOR_DARK_BLUE
COLOR_SKY_BLUE
COLOR_BROWN
COLOR_GOLD
COLOR_TRANSPARENT
COLOR_RGB(r, g, b) opaque colorCOLOR_ARGB(a, r, g, b) with alphaCOLOR_GET_A/R/G/B(color) extract channelWhen alpha < 255, SetPixel & all primitives auto alpha-blend.