SimpleGFX  1.0
Simple Graphics Library for C Programming Education
SimpleGFX API Quick Reference

Setup & Cleanup

int gfx_init(int width, int height); // Returns 0 on success, -1 on failure
void gfx_close(); // Clean up and close window
void gfx_close()
Close the graphics window and free resources.
Definition: simplegfx.c:120
int gfx_init(int width, int height)
Initialize the graphics window with specified dimensions.
Definition: simplegfx.c:34

Display Control

void gfx_clear(); // Fill window with white
void gfx_present(); // Show your drawings on screen
void gfx_delay(int ms); // Pause for milliseconds
void gfx_present()
Display all drawn graphics on the screen.
Definition: simplegfx.c:108
void gfx_delay(int ms)
Pause program execution for specified milliseconds.
Definition: simplegfx.c:115
void gfx_clear()
Clear the entire graphics window to white.
Definition: simplegfx.c:67

Drawing Pixels

void gfx_putpixel(int x, int y); // Black pixel
void gfx_putpixel_color(int x, int y, int r, int g, int b); // Colored pixel (RGB 0-255)
void gfx_putpixel(int x, int y)
Draw a single black pixel at the specified coordinates.
Definition: simplegfx.c:72
void gfx_putpixel_color(int x, int y, unsigned char r, unsigned char g, unsigned char b)
Draw a single pixel with custom RGB color.
Definition: simplegfx.c:77

Drawing Shapes

void gfx_line(int x1, int y1, int x2, int y2); // Line from (x1,y1) to (x2,y2)
void gfx_rect(int x, int y, int w, int h); // Rectangle outline
void gfx_circle(int cx, int cy, int r); // Circle outline (center + radius)
void gfx_circle(int cx, int cy, int r)
Draw a circle outline.
Definition: simplegfx.c:96
void gfx_line(int x1, int y1, int x2, int y2)
Draw a line between two points.
Definition: simplegfx.c:85
void gfx_rect(int x, int y, int w, int h)
Draw a rectangle outline.
Definition: simplegfx.c:91

Text

void gfx_drawtext(int x, int y, const char *text); // Draw text string
void gfx_drawtext(int x, int y, const char *text)
Draw text at the specified position.
Definition: simplegfx.c:101

Typical Program Structure

#include "gfx/simplegfx.h"
int main() {
// 1. Initialize
if (gfx_init(640, 480) != 0)
return 1;
// 2. Draw things
gfx_circle(320, 240, 100);
gfx_drawtext(250, 220, "Hello!");
// 3. Display and wait
gfx_delay(3000);
// 4. Clean up
return 0;
}
int main()
Definition: simple.c:35
Simple cross-platform graphics library for C programming education.

Color Examples

// RGB values range from 0-255
gfx_putpixel_color(x, y, 255, 0, 0); // Red
gfx_putpixel_color(x, y, 0, 255, 0); // Green
gfx_putpixel_color(x, y, 0, 0, 255); // Blue
gfx_putpixel_color(x, y, 255, 255, 0); // Yellow
gfx_putpixel_color(x, y, 255, 0, 255); // Magenta
gfx_putpixel_color(x, y, 0, 255, 255); // Cyan
gfx_putpixel_color(x, y, 255, 255, 255); // White
gfx_putpixel_color(x, y, 0, 0, 0); // Black

Coordinates

  • Origin (0, 0) is at the top-left corner
  • X increases going right
  • Y increases going down
(0,0) ────────→ X
Y

Common Patterns

Animation Loop

for (int frame = 0; frame < 100; frame++) {
// ... draw frame ...
gfx_delay(16); // ~60 FPS
}

Filled Circle (Manual)

for (int y = cy - r; y <= cy + r; y++) {
for (int x = cx - r; x <= cx + r; x++) {
int dx = x - cx;
int dy = y - cy;
if (dx*dx + dy*dy <= r*r) {
gfx_putpixel(x, y);
}
}
}

Grid Pattern

for (int y = 0; y < height; y += 10) {
for (int x = 0; x < width; x += 10) {
gfx_putpixel(x, y);
}
}

📚 Full Documentation

This quick reference covers the basics. For comprehensive documentation:

View Source Documentation

Generate HTML Documentation

Beautiful, searchable HTML documentation with examples, parameter descriptions, and modern styling:

# 1. First-time setup (download CSS theme)
cd doxygen
bash setup-doxygen.sh
# 2. Generate docs (from doxygen folder)
doxygen Doxyfile
# 3. View in browser
cd ..
xdg-open docs/html/index.html # Linux
open docs/html/index.html # Mac
start docs\html\index.html # Windows

See README.md - Generating API Documentation for more details.


SimpleGFX v1.0 - Simple Graphics Library for C Programming Education Made with ❤️ for students learning C