SimpleGFX  1.0
Simple Graphics Library for C Programming Education
GFX Chapter - Simple Graphics Library for C

A beginner-friendly graphics library designed for students learning C programming.

This lightweight library makes it easy to create visual programs and see your code come to life! Perfect for learning basic C programming concepts while drawing shapes and creating simple graphics.

No complex setup required - just a few simple functions to get started with graphics programming.

Why Use This Library?

  • Perfect for Beginners: No prior graphics programming experience needed
  • Learn by Doing: See immediate visual results from your C code
  • Cross-platform: Works on both Windows and Linux
  • Simple API: Just a handful of easy-to-understand functions
  • No Complex Dependencies: Uses built-in system graphics (GDI on Windows, X11 on Linux)
  • Great for Practice: Ideal for course assignments and learning exercises

Project Structure

gfx-chapter/
├── gfx/
│ ├── simplegfx.h # Graphics library header (Doxygen documented)
│ └── simplegfx.c # Graphics library implementation
├── doxygen/ # Documentation generation
│ ├── Doxyfile # Doxygen configuration
│ ├── setup-doxygen.sh # CSS theme setup script
│ └── README.md # Documentation instructions
├── circle-rgb.c # Example: RGB-filled circle
├── line-rgb.c # Example: RGB pixel drawing
├── m-*.c # Math examples (sine waves, spirals, etc.)
├── compile.sh # Linux build script
├── compile.cmd # Windows build script
├── API-QUICK-REF.md # Quick reference cheat sheet
├── output/ # Compiled executables go here
└── README.md

Getting Started - Your First Program

Here's a simple example to draw a circle:

#include "gfx/simplegfx.h"
int main() {
if (gfx_init(640, 480) != 0) { // Create a window
return 1; // Exit if failed
}
gfx_drawtext(50, 50, "Hello, World!"); // Draw Text
gfx_circle(320, 240, 100); // Draw a circle at center
gfx_present(); // Show it on screen
gfx_delay(3000); // Wait 3 seconds
gfx_close(); // Clean up
return 0;
}
int main()
Definition: simple.c:35
Simple cross-platform graphics library for C programming education.
void gfx_close()
Close the graphics window and free resources.
Definition: simplegfx.c:120
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
int gfx_init(int width, int height)
Initialize the graphics window with specified dimensions.
Definition: simplegfx.c:34
void gfx_drawtext(int x, int y, const char *text)
Draw text at the specified position.
Definition: simplegfx.c:101
void gfx_circle(int cx, int cy, int r)
Draw a circle outline.
Definition: simplegfx.c:96

That's it! Just a few lines to create a graphics program.

Available Functions

All functions are fully documented with Doxygen-compatible comments in simplegfx.h.

📄 See API-QUICK-REF.md for a printable cheat sheet!

Quick Reference:

Setup & Control:

  • gfx_init(width, height) - Create a graphics window
  • gfx_clear() - Clear the screen to white
  • gfx_present() - Display what you've drawn
  • gfx_delay(ms) - Wait for some milliseconds
  • gfx_close() - Close the window and exit

Drawing:

  • gfx_putpixel(x, y) - Draw a single black pixel
  • gfx_putpixel_color(x, y, r, g, b) - Draw a colored pixel (RGB values 0-255)
  • gfx_line(x1, y1, x2, y2) - Draw a line between two points
  • gfx_rect(x, y, w, h) - Draw a rectangle outline
  • gfx_circle(cx, cy, r) - Draw a circle outline
  • gfx_drawtext(x, y, "text") - Draw text using the default system font

How to Compile and Run

Don't worry if you're new to compiling C programs! Just follow these simple steps for your operating system.

Linux

Step 1: Install Required Libraries

First, install the X11 graphics library (you only need to do this once):

Ubuntu/Debian:

sudo apt-get install libx11-dev

Fedora/RHEL:

sudo dnf install libX11-devel

Arch Linux:

sudo pacman -S libx11

Step 2: Compile Your Program

Open a terminal in the project folder and type:

gcc circle-rgb.c gfx/simplegfx.c -o output/circle-rgb -lX11

This creates a program called circle-rgb in the output/ folder.

Step 3: Run It!

./output/circle-rgb

You should see a colorful circle appear!

Quick compile all examples (Easy!):

bash compile.sh

This automatically compiles all example files to the output/ directory.

To compile other examples manually:

gcc line-rgb.c gfx/simplegfx.c -o output/line-rgb -lX11
./output/line-rgb

For math examples (require -lm flag):

gcc m-sine-wave.c gfx/simplegfx.c -o output/m-sine-wave -lX11 -lm
./output/m-sine-wave

Windows

Good news! On Windows, you don't need to install any extra libraries.

Option 1: Using MinGW (Easier for beginners)

Step 1: Install MinGW-w64 if you haven't already (download here)

Step 2: Open Command Prompt in the project folder and type:

gcc circle-rgb.c gfx/simplegfx.c -o output/circle-rgb.exe -lgdi32

Step 3: Run your program:

output\circle-rgb.exe

Quick compile all examples:

compile.cmd

Option 2: Using Visual Studio

Step 1: Open "Developer Command Prompt for VS"

Step 2: Compile:

cl /Fe:output/circle-rgb.exe circle-rgb.c gfx/simplegfx.c gdi32.lib user32.lib

Step 3: Run:

output\circle-rgb.exe

Included Examples

Basic Examples

  • simple.c - Minimal example showing basic setup and usage
  • circle-rgb.c - Beautiful filled circle with RGB gradient
  • line-rgb.c - Individual colored pixels demo

Math Examples (m-*.c files)

All math examples include comments explaining the mathematical concepts!

Learning Tips

  1. Start Simple: Begin with circle-rgb.c - just compile and run it to see graphics in action
  2. Experiment: Try changing the numbers in the examples to see what happens
  3. Read the Code: The examples are heavily commented to help you understand each step
  4. Ask Questions: If something doesn't work, check that you followed all the compilation steps
  5. Have Fun: Graphics programming is a great way to make learning C more exciting!

Troubleshooting

Linux: "cannot find -lX11" error

  • You forgot to install the X11 library. Go back to Step 1 under Linux instructions.

Windows: "gcc is not recognized" error

  • MinGW isn't installed or not in your PATH. Make sure you installed MinGW-w64 correctly.

Program compiles but window doesn't appear (Linux)

  • Make sure you're running a desktop environment with X server.

Still having issues?

  • Double-check that you're in the correct folder (GFX Chapter/)
  • Make sure all the files are in the right places (check Project Structure above)

Generating API Documentation

The library includes comprehensive Doxygen-compatible documentation with modern styling using the Doxygen Awesome CSS theme.

Prerequisites

Install Doxygen (cross-platform, works on Windows, Linux, macOS):

  • Windows: Download from doxygen.nl/download.html
    • Or use: winget install Doxygen.Doxygen
    • Or use Chocolatey: choco install doxygen
  • Linux: sudo apt-get install doxygen (Ubuntu/Debian)
  • macOS: brew install doxygen

Quick Start

1. First-time setup (download CSS theme):

Linux/Mac:

cd doxygen
bash setup-doxygen.sh

Windows:

cd doxygen
mkdir css
curl -sL https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/main/doxygen-awesome.css -o css\doxygen-awesome.css
curl -sL https://raw.githubusercontent.com/jothepro/doxygen-awesome-css/main/doxygen-awesome-sidebar-only.css -o css\doxygen-awesome-sidebar-only.css

2. Generate documentation:

Linux/Mac:

# From the project root:
doxygen doxygen/Doxyfile

Windows:

doxygen doxygen\Doxyfile

This creates HTML documentation in the docs/html/ folder.

3. View documentation:

Linux:

xdg-open docs/html/index.html

Mac:

open docs/html/index.html

Windows:

start docs\html\index.html

What's Included

The generated documentation features:

  • Modern, responsive design with sidebar navigation
  • 📚 Complete API reference with detailed descriptions
  • 💡 Code examples for every function
  • 📝 Parameter documentation with valid ranges
  • 🔍 Searchable interface for quick lookup
  • 🎨 Syntax highlighting for code blocks
  • 📱 Mobile-friendly layout
  • 🌓 Professional styling with clean typography

Documentation Structure

All functions are organized into logical groups:

  • Setup & Display Control - Initialization, clearing, presenting
  • Pixel Operations - Drawing individual pixels with colors
  • Geometry Functions - Lines, rectangles, circles
  • Text Functions - Drawing text strings

For detailed setup instructions, see the README in the doxygen/ folder

For a quick reference card, see API-QUICK-REF.md


License

MIT License

Copyright (c) 2026 Sukesh Ashok Kumar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version

Current version: 1.0


Author: Sukesh Ashok Kumar Last Updated: February 2026