SimpleGFX  1.0
Simple Graphics Library for C Programming Education
simplegfx.h File Reference

Simple cross-platform graphics library for C programming education. More...

Go to the source code of this file.

Macros

#define GFX_VERSION   "1.0"
 

Functions

void gfx_clear ()
 Clear the entire graphics window to white. More...
 
int gfx_init (int width, int height)
 Initialize the graphics window with specified dimensions. More...
 
Pixel Operations

Functions for drawing individual pixels

void gfx_putpixel (int x, int y)
 Draw a single black pixel at the specified coordinates. More...
 
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. More...
 
Geometry Functions

Functions for drawing basic shapes

void gfx_circle (int cx, int cy, int r)
 Draw a circle outline. More...
 
void gfx_line (int x1, int y1, int x2, int y2)
 Draw a line between two points. More...
 
void gfx_rect (int x, int y, int w, int h)
 Draw a rectangle outline. More...
 
Text Functions

Functions for drawing text

void gfx_drawtext (int x, int y, const char *text)
 Draw text at the specified position. More...
 
Display Control

Functions for controlling the display and timing

void gfx_close ()
 Close the graphics window and free resources. More...
 
void gfx_delay (int ms)
 Pause program execution for specified milliseconds. More...
 
void gfx_present ()
 Display all drawn graphics on the screen. More...
 

Detailed Description

Simple cross-platform graphics library for C programming education.

Author
Sukesh Ashok Kumar
Version
1.0

A beginner-friendly graphics library that works on Windows (GDI) and Linux (X11). Provides basic drawing primitives for learning C programming with visual feedback.

Macro Definition Documentation

◆ GFX_VERSION

#define GFX_VERSION   "1.0"

Library version string

Function Documentation

◆ gfx_circle()

void gfx_circle ( int  cx,
int  cy,
int  r 
)

Draw a circle outline.

Draws only the border of a circle, not filled.

Parameters
cxX-coordinate of the circle center
cyY-coordinate of the circle center
rRadius of the circle in pixels
gfx_circle(320, 240, 100); // Circle at center with radius 100
void gfx_circle(int cx, int cy, int r)
Draw a circle outline.
Definition: simplegfx.c:96

◆ gfx_clear()

void gfx_clear ( )

Clear the entire graphics window to white.

Erases everything on the screen and fills it with white color.

◆ gfx_close()

void gfx_close ( )

Close the graphics window and free resources.

Call this before your program exits to properly clean up. Should be the last graphics function you call.

return 0;
void gfx_close()
Close the graphics window and free resources.
Definition: simplegfx.c:120

◆ gfx_delay()

void gfx_delay ( int  ms)

Pause program execution for specified milliseconds.

Useful for keeping the window open or creating animations.

Parameters
msDelay duration in milliseconds (1000 ms = 1 second)
gfx_delay(3000); // Wait 3 seconds
void gfx_delay(int ms)
Pause program execution for specified milliseconds.
Definition: simplegfx.c:115

◆ gfx_drawtext()

void gfx_drawtext ( int  x,
int  y,
const char *  text 
)

Draw text at the specified position.

Renders text using the default system font in black color.

Parameters
xX-coordinate where text starts
yY-coordinate of the text baseline
textThe null-terminated string to draw
gfx_drawtext(50, 50, "Hello, World!");
void gfx_drawtext(int x, int y, const char *text)
Draw text at the specified position.
Definition: simplegfx.c:101

◆ gfx_init()

int gfx_init ( int  width,
int  height 
)

Initialize the graphics window with specified dimensions.

Creates a graphics window where you can draw shapes and pixels. Must be called before any other graphics functions.

Parameters
widthWindow width in pixels
heightWindow height in pixels
Returns
0 on success, -1 on failure (display unavailable, etc.)
if (gfx_init(640, 480) != 0) {
return 1; // Failed to create window
}
int gfx_init(int width, int height)
Initialize the graphics window with specified dimensions.
Definition: simplegfx.c:34

◆ gfx_line()

void gfx_line ( int  x1,
int  y1,
int  x2,
int  y2 
)

Draw a line between two points.

Draws a straight line connecting point (x1, y1) to point (x2, y2).

Parameters
x1X-coordinate of the start point
y1Y-coordinate of the start point
x2X-coordinate of the end point
y2Y-coordinate of the end point
gfx_line(0, 0, 100, 100); // Diagonal line
void gfx_line(int x1, int y1, int x2, int y2)
Draw a line between two points.
Definition: simplegfx.c:85

◆ gfx_present()

void gfx_present ( )

Display all drawn graphics on the screen.

Call this after drawing operations to make them visible. This updates the window with everything you've drawn since the last present.

gfx_circle(100, 100, 50);
gfx_present(); // Now the circle appears on screen
void gfx_present()
Display all drawn graphics on the screen.
Definition: simplegfx.c:108

◆ gfx_putpixel()

void gfx_putpixel ( int  x,
int  y 
)

Draw a single black pixel at the specified coordinates.

Parameters
xX-coordinate of the pixel (0 = left edge)
yY-coordinate of the pixel (0 = top edge)
gfx_putpixel(100, 50); // Draw black pixel at (100, 50)
void gfx_putpixel(int x, int y)
Draw a single black pixel at the specified coordinates.
Definition: simplegfx.c:72

◆ gfx_putpixel_color()

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.

Allows you to specify any color using Red, Green, Blue components. Each component ranges from 0 (none) to 255 (full intensity).

Parameters
xX-coordinate of the pixel
yY-coordinate of the pixel
rRed component (0-255)
gGreen component (0-255)
bBlue component (0-255)
gfx_putpixel_color(100, 50, 255, 0, 0); // Red pixel
gfx_putpixel_color(100, 51, 0, 255, 0); // Green pixel
gfx_putpixel_color(100, 52, 0, 0, 255); // Blue pixel
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

◆ gfx_rect()

void gfx_rect ( int  x,
int  y,
int  w,
int  h 
)

Draw a rectangle outline.

Draws only the border of a rectangle, not filled.

Parameters
xX-coordinate of the top-left corner
yY-coordinate of the top-left corner
wWidth of the rectangle in pixels
hHeight of the rectangle in pixels
gfx_rect(50, 50, 200, 100); // 200x100 rectangle at (50, 50)
void gfx_rect(int x, int y, int w, int h)
Draw a rectangle outline.
Definition: simplegfx.c:91