iGraphics.h header file contains some drawing functions that can be used to draw basic graphical shapes in C++. These functions are implemented in OpenGL. Users of iGraphics do not need any knowledge of OpenGL to use it. Simply calling the drawing functions a user can draw any 2D shape on screen. This library also provides easy ways for animation, keyboard and mouse event handling.
It was originally created by Shahriar Nirjon on 2009 with limited functionalities and only for Windows. This is an extended version of the original iGraphics library with support for multiple image formats, custom fonts, sound engine, sprite management, collision detection and advanced mouse-keyboard control. The library is now cross-platform and works on both Windows and Linux. Updates will be added incrementally based on requests.
| Feature | Original iGraphics (2009) | Modern iGraphics (2025) |
|---|---|---|
| Cross-Platform Support | ❌ Windows only | ✅ Windows & Linux |
| Image Formats | ❌ BMP only | ✅ Multiple formats |
| Audio Formats | ❌ WAV only | ✅ Multiple formats |
| Font Support | ❌ Limited bitmap fonts | ✅ Custom TTF fonts |
| Sound Integration | ❌ Single Channel | ✅ Multi-Channel |
| Input Handling | ❌ Basic | ✅ Enhanced controls |
| Transparency Support | ❌ Not available | ✅ Full RGBA color support |
| Image Manipulation | ❌ No transformations | ✅ Rotate/Scale/Flip/Wrap |
| Image rendering | ❌ Slow | ✅ Fast (Texture-based + Caching) |
| Sprite Management | ❌ Manual implementation | ✅ Built-in sprite system |
| Collision Detection | ❌ Not available | ✅ Pixel-perfect collision |
You can find executable games here
- Download the
Modern-iGraphics-1.0.0.zipfile from here and extract it. - Download
MINGW.zipfile from here and extract it. - Copy the
MINGWfolder to the extractedModern-iGraphics-1.0.0folder. - The final folder structure should look like this:
Modern-iGraphics-1.0.0
├── MINGW
│ ├── bin
│ ├── include
│ ├── lib
│ ├── ....
│ └── share
├── OpenGL
├── assets
├── bin
├── examples
├── iGraphics.h
├── iGraphics.cbp
├── iMain.cpp
├── ....
Change the compiler path of Code::Blocks as following:
Settings → Compiler → Go to Toolchain executables tab → Change the Compiler's installation directory to the MINGW directory in the iGraphics folder. You can do that by clicking the three dots (...) on right. After you change the compiler, clear the .o files inside obj folder (If there is any).
Open iGraphics.cbp in Code::Blocks. The project is already configured with all the necessary settings. You can directly run the project. By default, the main file is iMain.cpp. You can remove it and add a different file if you want.
You can find the slides with step-by-step screenshots here.
Download the Library: Clone or download the iGraphics library from the repository.
git clone https://github.com/mahirlabibdihan/Modern-iGraphics
cd Modern-iGraphicsAlternatively, you can download the ZIP file from here and extract it.
Running the Example:
Ensure that g++ is installed on your system and available in your PATH. Then, run the following command to compile and execute the example program:
- Windows
.\runner.bat examples\BallDemo.cpp- Linux
sudo apt install libglu1-mesa-dev freeglut3-dev mesa-common-dev
sudo apt install libsdl2-dev libsdl2-mixer-dev
sudo apt install libfreetype6-dev
./runner.sh examples/BallDemo.cpp- MSYS2-MINGW64
pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_mixer
pacman -S mingw-w64-x86_64-freeglut mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-freetype
./runner.sh examples/BallDemo.cppFor quick project setup, use the provided project creation scripts:
Windows:
.\create_project.bat MyGameNameLinux/Unix:
./create_project.sh MyGameNameThese scripts will automatically generate a complete starter template with:
- ✅ All necessary iGraphics function stubs
- ✅ Example drawing code (text + red circle)
- ✅ Mouse and keyboard handlers
- ✅ Animation timer setup (commented)
- ✅ Comprehensive comments and documentation
-
Organize Your Assets
- Ensure all game assets (images, sprites, sounds, level designs, etc.) are inside the assets folder.
- Remove any unnecessary or default assets to save space.
-
Save Files
- Place any saved game data in the saves folder.
-
Run the Release Script
- Double-click release.bat or run it from the terminal using:
.\release.bat iMain.cpp
- Double-click release.bat or run it from the terminal using:
-
Check the Output
- After execution, a release folder will be created. Navigate to:
release → windows → x86 - Inside, you’ll find the necessary files to run your game. Please test
game.exeto ensure your game runs properly.
- After execution, a release folder will be created. Navigate to:
Users of iGraphics only have to edit, compile and run iMain.cpp. See the listing of iMain.cpp below:
#include "iGraphics.h"
/*
function iDraw() is called again and again by the system.
*/
void iDraw()
{
//place your drawing codes here
iClear();
}
/*
function iMouseClick() is called when the user presses/releases the mouse.
(mx, my) is the position where the mouse pointer is.
*/
void iMouseClick(int button, int state, int mx, int my)
{
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
//place your codes here
}
if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
{
//place your codes here
}
}
/*
function iMouseMove() is called when the user moves the mouse.
(mx, my) is the position where the mouse pointer is.
*/
void iMouseMove(int mx, int my)
{
//place your codes here
}
/*
function iKeyPress() is called whenever the user hits a key in keyboard.
key- holds the ASCII value of the key pressed.
*/
void iKeyPress(unsigned char key)
{
switch (key)
{
case 'q':
// do something with 'q'
iExitMainLoop();
break;
// place your codes for other keys here
default:
break;
}
}
/*
function iSpecialKeyPress() is called whenver user hits special keys likefunction
keys, home, end, pg up, pg down, arraows etc. you have to use
appropriate constants to detect them. A list is:
GLUT_KEY_F1, GLUT_KEY_F2, GLUT_KEY_F3, GLUT_KEY_F4, GLUT_KEY_F5, GLUT_KEY_F6,
GLUT_KEY_F7, GLUT_KEY_F8, GLUT_KEY_F9, GLUT_KEY_F10, GLUT_KEY_F11,
GLUT_KEY_F12, GLUT_KEY_LEFT, GLUT_KEY_UP, GLUT_KEY_RIGHT, GLUT_KEY_DOWN,
GLUT_KEY_PAGE_UP, GLUT_KEY_PAGE_DOWN, GLUT_KEY_HOME, GLUT_KEY_END,
GLUT_KEY_INSERT */
void iSpecialKeyPress(unsigned char key)
{
switch (key)
{
case GLUT_KEY_END:
// do something
break;
// place your codes for other keys here
default:
break;
}
}
int main(int argc, char *argv[])
{
// Initialization code before opening the window
iWindowedMode(400, 400, "iGraphics");
iStartMainLoop();
// Execution will continue from here once iExitMainLoop() is called or window is closed.
return 0;
}- Description: Creates a window of specified size and title.
- Parameters:
width: Width of the window.height: Height of the window.title: Title of the window.
- Example:
iWindowedMode(300, 300, "iGraphics");
- Description: Sets the game mode for fullscreen display.
- Parameters:
gameModeStr: String representing the game mode.- Available modes include:
W800_X_H600: 800x600 resolution.W1024_X_H768: 1024x768 resolution.W1280_X_H720: 1280x720 resolution.W1920_X_H1080: 1920x1080 resolution.
- Available modes include:
- Example:
iGameMode(W1280_X_H720);
- Description: Starts the main loop of the application.
- Parameters: None
- Note: This function contains an infinite loop that keeps the application running until
iExitMainLoop()is called. - Example:
iStartMainLoop();
- Description: Exits the main loop and return from
iStartMainLoop(). - Parameters: None
- Example:
void iKeyPress(unsigned char key) { switch (key) { case 'q': iExitMainLoop(); break; default: break; } }
- Description: Clears the screen.
- Parameters: None
- Example:
iClear();
- Description: Sets current drawing color.
- Parameters:
r: Red component of color (0-255).g: Green component of color (0-255).b: Blue component of color (0-255).
- Example:
iSetColor(255, 0, 0); // Red
- Description: Sets current drawing color with transparency.
- Parameters:
r,g,b: RGB values (0-255).a: Alpha value (0.0 to 1.0).
- Example:
iSetTransparentColor(255, 0, 0, 0.5); // Semi-transparent red
- Description: Gets pixel color at coordinate
(x, y). - Parameters:
x,y: Coordinates of the pixel.rgb[]: Array to store RGB values.
- Example:
iGetPixelColor(100, 120, array);
- Description: Draws a point at
(x, y)using current color. - Parameters:
x,y: Coordinates.size: Optional size.
- Example:
iPoint(10, 20);
- Description: Draws a line between two points.
- Parameters:
x1,y1: One end.x2,y2: Other end.
- Example:
iLine(10, 20, 100, 120);
- Description: Draws a circle.
- Parameters:
x,y: Center.r: Radius.slices: Segments to draw.
- Example:
iCircle(10, 20, 10);
- Description: Draws a filled circle.
- Parameters:
- Same as
iCircle.
- Same as
- Example:
iFilledCircle(10, 20, 10);
- Description: Draws an ellipse.
- Parameters:
x,y: Center.a,b: Axes lengths.slices: Segments to draw.
- Example:
iEllipse(10, 20, 10, 5);
- Description: Draws a filled ellipse.
- Parameters: Same as
iEllipse. - Example:
iFilledEllipse(10, 20, 10, 5);
- Description: Draws a rectangle.
- Parameters:
left: x-coordinate of bottom-left.bottom: y-coordinate of bottom-left.dx: Width.dy: Height.
- Example:
iRectangle(10, 20, 10, 5);
- Description: Draws a filled-rectangle on the screen with current color.
- Parameters: Same as
iRectangle. - Example:
iFilledRectangle(10, 20, 10, 5);
- Description: Draws a polygon on the screen with current color.
- Parameters:
x,y: Arrays of coordinates of vertices.n: Number of vertices.
- Example:
double xa[] = {0, 10, 5}; double ya[] = {0, 0, 10}; iPolygon(xa, ya, 3);
- Description: Draws a filled-polygon on the screen with current color.
- Parameters: Same as
iPolygon. - Example:
double xa[] = {0, 10, 5}; double ya[] = {0, 0, 10}; iFilledPolygon(xa, ya, 3);
- Description: Sets the width of lines to be drawn.
- Parameters:
width- Line width in pixels. - Example:
iSetLineWidth(3.0); // Set line width to 3 pixels iLine(0, 0, 100, 100); // Draw a thick line
- Description: Displays the current FPS (Frames Per Second) at specified coordinates.
- Parameters:
x,y: Coordinates where FPS will be displayed.
- Example:
iShowSpeed(10, 10); // Show FPS counter at top-left corner
- Description: Displays a string on screen.
- Parameters:
x,y: Coordinates of the first character.str: The text to display.font: (Optional) Font type. Available fonts include:GLUT_BITMAP_8_BY_13GLUT_BITMAP_9_BY_15GLUT_BITMAP_TIMES_ROMAN_10GLUT_BITMAP_TIMES_ROMAN_24GLUT_BITMAP_HELVETICA_10GLUT_BITMAP_HELVETICA_12GLUT_BITMAP_HELVETICA_18
- Example:
iText(50, 60, "This is a text", GLUT_BITMAP_TIMES_ROMAN_10);
- Description: Displays a bold string on screen.
void iTextAdvanced(double x, double y, const char *str, float scale = 0.3, float weight = 1.0, void *font = GLUT_STROKE_ROMAN)
- Description: Displays a string on screen with specified scale and weight.
- Parameters:
x,y: Coordinates of the first character.str: The text to display.scale: Scale factor for the text.weight: Weight of the text (1.0 for normal, 2.0 for bold).font: Font type (default isGLUT_STROKE_ROMAN).
- Example:
iTextAdvanced(50, 60, "This is a text", 0.5, 2.0);
- Description: Rotates the coordinate system around a point.
- Parameters:
x,y: Coordinates of the point to rotate around.degree: Angle in degrees to rotate.
- Example:
iRotate(100, 100, 45); // Rotate around point (100, 100) by 45 degrees iShowImage(50, 50, "image.png"); // This image will be rotated iUnRotate();
- Description: Scales the coordinate system around a point.
- Parameters:
x,y: Coordinates of the point to scale around.scaleX: Scaling factor in the x-direction.scaleY: Scaling factor in the y-direction.- Example:
iScale(0,0, 2.0, 1.5); // Scale around the origin (0, 0) by 2.0 in x and 1.5 in y // This will affect all subsequent drawing operations iUnScale();
-
Description: Repeatedly executes a function at specified time intervals.
-
Parameters:
msec: Time interval in milliseconds.f: Function to be executed.
-
Returns: Timer index.
-
Example:
void func() { //code of the task that will be repeated. } int main(int argc, char *argv[]) { ... int t = iSetTimer(100, func); // //call it inside main() before iWindowedMode(); ... iWindowedMode(400, 400, "iGraphics"); }
- Description: Pauses the timer.
- Parameters:
indexof the timer. - Example:
iPauseTimer(t);
- Description: Resumes the timer.
- Parameters:
indexof the timer. - Example:
iResumeTimer(t);
- Description: Pauses execution for a given duration.
- Parameters:
secin seconds. - Example:
iDelay(5); // Pauses for 5 seconds
- Description: Called when a mouse button is pressed or released.
- Parameters:
button: Button pressed (GLUT_LEFT_BUTTON, GLUT_RIGHT_BUTTON, GLUT_MIDDLE_BUTTON).state: State of the button (GLUT_DOWN or GLUT_UP).mx,my: Coordinates of the mouse pointer.
- Note: This function should be defined in the main file.
- Description: Called when the mouse moves.
- Parameters:
mx,my: Coordinates of the mouse pointer. - Note: This function should be defined in the main file.
- Description: Called when the mouse is dragged.
- Parameters:
mx,my: Coordinates of the mouse pointer. - Note: This function should be defined in the main file.
- Description: Called when the mouse wheel is scrolled.
- Parameters:
dir: Direction of scroll (1 for up, -1 for down).mx,my: Coordinates of the mouse pointer.
- Note: This function should be defined in the main file.
- Description: Shows the mouse cursor.
- Parameters: None
- Example:
iShowCursor();
- Description: Hides the mouse cursor.
- Parameters: None
- Example:
iHideCursor();
- Description: Called when a key is pressed.
- Parameters:
key: ASCII value of the key pressed.
- Note: This function should be defined in the main file.
- Description: Called when a special key is pressed.
- Parameters:
key: Special key value (e.g.,GLUT_KEY_LEFT,GLUT_KEY_RIGHT, etc.).
- Note: This function should be defined in the main file.
- Description: Called when a key is released.
- Parameters:
key: ASCII value of the key released.- Note: This function should be defined in the main file.
- Description: Called when a special key is released.
- Parameters:
key: Special key value (e.g.,GLUT_KEY_LEFT,GLUT_KEY_RIGHT, etc.).- Note: This function should be defined in the main file.
- Description: Checks if a key is being pressed (Not yet released).
- Parameters:
keyto check. - Returns:
1if pressed,0otherwise. - Example:
if (isKeyPressed('a')) { // 'a' key is pressed }
- Description: Checks if a special key is being pressed (Not yet released).
- Parameters:
keyto check. - Returns:
1if pressed,0otherwise. - Example:
if (isSpecialKeyPressed(GLUT_KEY_LEFT)) { // Left arrow key is pressed }
iGraphics was originally designed for graphical applications, but it has been extended to support sound playback using the SDL2 library. The sound functions are available in iSound.h and are shown below:
-
Description: Plays a sound from file with optional looping and volume control.
-
Parameters:
filename: Path to the sound file.loop:truefor continuous play,falsefor one-time play.volume: Volume level (0-100).
-
Returns: Channel where the sound is played (-1 if failed).
-
Note: You can't play more than 8 sounds simultaneously.
-
Supported Formats: WAV, MP3, OGG, FLAC, and more.
-
Example:
#include "iSound.h" // Include the sound header ... int channel = iPlaySound("background.wav", true, 80);
- Description: Pauses the sound specified by
channel. - Parameters:
channelof the sound. - Example:
iPauseSound(channel);
- Description: Resumes the sound specified by
channel. - Parameters:
channelof the sound. - Example:
iResumeSound(channel);
- Description: Stops the sound specified by
channel. Frees the channel for other sounds. - Parameters:
channelof the sound. - Example:
iStopSound(channel);
- Description: Stops all currently playing sounds. Frees all channels.
- Description: Sets the volume for a specific sound.
- Parameters:
index: Index of the sound.volume: Volume level (0-100).
- Description: Increases the volume of a specific sound by a specified amount.
- Parameters:
index: Index of the sound.amount: Amount to increase the volume by (0-100).
- Description: Decreases the volume of a specific sound by a specified amount.
- Parameters:
index: Index of the sound.amount: Amount to decrease the volume by (0-100).
Custom font rendering is supported using TrueType fonts. freetype library is used to render text. The new text functions are available in iFont.h and are shown below:
-
Description: Displays a string on screen using TrueType font.
-
Parameters:
x,y: Coordinates of the first character.text: The text to display.fontPath: Path to the TrueType font file (e.g., "assets/fonts/arial.ttf").fontSize: Size of the font (default is 48).
-
Example:
#include "iFont.h" // Include the font header ... iShowText(50, 60, "This is a text", "assets/fonts/arial.ttf", 48);
-
Description: Displays an image at specified coordinates.
-
Parameters:
x,y: Coordinates where the image will be displayed.filename: Path to the image file.
-
Example:
iShowImage(100, 200, "image.png");
-
Description: Loads an image from file. Supports multiple image formats (BMP, PNG, JPG, GIF) with the help of the stb_image library.
-
Parameters:
img: Pointer to anImagestructure.filename: Path to the image file.
-
Returns:
trueif successful,falseotherwise. -
Example:
Image img; if (iLoadImage(&img, "image.png")) { // Image loaded successfully } else { // Failed to load image }
-
Image Structure
typedef struct { unsigned char *data; int width, height, channels; GLuint textureID; // OpenGL texture ID } Image;
-
Description: Displays an already loaded image at specified coordinates. Image should be loaded using
iLoadImage. -
Parameters:
x,y: Coordinates where the image will be displayed.img: Pointer to the loadedImagestructure.
-
Example:
Image img; iLoadImage(&img, "image.png"); iShowLoadedImage(100, 200, &img);
-
Description: Scales the image by a specified factor.
-
Parameters:
img: Pointer to the loadedImagestructure.scale: Scaling factor (e.g., 2.0 for double size).
-
Example:
iScaleImage(&img, 2.0);
-
Description: Resizes the image to specified dimensions.
-
Parameters:
img: Pointer to the loadedImagestructure.width: New width of the image.height: New height of the image.
-
Example:
iResizeImage(&img, 200, 100); // Resize to 200x100 pixels
-
Description: Mirrors the image either horizontally or vertically.
-
Parameters:
img: Pointer to the loadedImagestructure.state:HORIZONTALorVERTICAL. Here, MirrorState is an enum.
-
Example:
iMirrorImage(&img, HORIZONTAL); // Mirror horizontally
-
Description: Wraps the image around the screen by
dxpixels horizontally anddypixels vertically. This function is useful for creating infinite scrolling backgrounds. -
Parameters:
img: Pointer to the loadedImagestructure.dx: Horizontal shift in pixels (default is 0).- A positive value of
dxshifts the image to the right. - A negative value of
dxshifts the image to the left.
- A positive value of
dy: Vertical shift in pixels (default is 0).- A positive value of
dyshifts the image down. - A negative value of
dyshifts the image up.
- A positive value of
-
Example:
iWrapImage(&img, 50); // Wrap the image by 50 pixels to the right iWrapImage(&img, -50); // Wrap the image by 50 pixels to the left iWrapImage(&img, 0, 30); // Wrap the image by 30 pixels down iWrapImage(&img, 0, -30); // Wrap the image by 30 pixels up
- Description: Makes specific colored pixels transparent in the image.
- Parameters:
img: Pointer to the loadedImagestructure.ignoreColor: Color to ignore in 0xRRGGBB format (e.g., 0xFF0000 for red).
- Example:
iIgnorePixels(&img, 0xFFFFFF); // Make white pixels transparent
- Description: Frees the memory allocated for the image.
Free sprite resources: https://craftpix.net/freebies/\ Online sprite cutter: https://ezgif.com/sprite-cutter
FrameSet Structure
typedef struct
{
Image *frames;
int count;
} FrameSet;Sprite Structure
typedef struct
{
int x, y;
FrameSet frameSet;
int currentFrame;
....
} Sprite;-
Description: Loads frames from a folder containing multiple images.
-
Parameters:
frames: Pointer to aFrameSetstructure.folderPath: Path to the folder containing images.
-
Returns: Number of frames loaded. -1 if failed to load any images.
-
Example:
FrameSet frames; iLoadFramesFromFolder(&frames, "sprites/"); // Load images from "sprites/" folder
-
Description: Loads frames from a sprite sheet.
-
Parameters:
frames: Pointer to aFrameSetstructure.filename: Path to the sprite sheet image.rows: Number of rows in the sprite sheet.cols: Number of columns in the sprite sheet.
-
Returns: Number of frames loaded. -1 if failed to load the sprite sheet.
-
Example:
FrameSet frames; iLoadFramesFromSheet(&frames, "spritesheet.png", 4, 4); // Load images frames a sprite sheet with 4 rows and 4 columns
-
Description: Changes the frames of a sprite.
-
Parameters:
s: Pointer to aSpritestructure.frames: Pointer to aFrameSetstructure representing the new frames.
-
Example:
FrameSet frames; iLoadFramesFromFolder(&frames, "sprites/"); // Load images from a folder Sprite s; iChangeSpriteFrames(&s, &frames);
- Description: Sets the position of the sprite.
- Parameters:
s: Pointer to aSpritestructure.x,y: New coordinates for the sprite.
- Example:
iSetSpritePosition(&s, 100, 200); // Set sprite position to (100, 200)
- Description: Displays the sprite on the screen.
- Parameters:
s: Pointer to aSpritestructure.
- Description: Animates the sprite by cycling through its frames.
- Parameters:
s: Pointer to aSpritestructure.
- Example:
iAnimateSprite(&s); // Animate the sprite
- Description: Scales the sprite by a specified factor.
- Parameters:
s: Pointer to aSpritestructure.scale: Scaling factor (e.g., 2.0 for double size).
- Description: Resizes the sprite to specified dimensions.
- Parameters:
s: Pointer to aSpritestructure.width: New width of the sprite.height: New height of the sprite.
- Description: Mirrors the sprite either horizontally or vertically.
- Parameters:
s: Pointer to aSpritestructure.state:HORIZONTALorVERTICAL.
- Description: Rotates the sprite around a point
(x, y)by a specified angle in degrees. - Parameters:
s: Pointer to aSpritestructure.x,y: Coordinates of the point to rotate around.degree: Angle in degrees to rotate.
- Example:
iRotateSprite(&s, 100, 100, 45); // Rotate sprite around point (100, 100) by 45 degrees
- Description: Frees the memory allocated for the sprite.
- Parameters:
s: Pointer to aSpritestructure.
- Description: Counts the number of visible pixels in a sprite. This is useful for collision detection.
- Parameters:
s1: Pointer to theSpritestructure.- Returns: Number of visible pixels in the sprite.
- Example:
Sprite s1; ... int visiblePixels = iGetVisiblePixelsCount(&s1);
-
Description: Creates a
FrameSetfrom an array of images. -
Parameters:
frames: Pointer to an array ofImagestructures.count: Number of frames in the array.- Returns: A
FrameSetstructure containing the frames.
-
Example:
Image frames[4]; ... FrameSet frameSet = iCreateFrameSet(frames, 4); // Create a FrameSet from the array of images
Image singleImg; ... FrameSet frameSet = iCreateFrameSet(&singleImg, 1); // Create a FrameSet from a single image
<!-- Collision Detection -->
### 🛡️ Collision Detection
#### `int iCheckImageCollision(int x1, int y1, Image *img1, int x2, int y2, Image *img2)`
- **Description:** Checks for pixel-level collision between two images.
- **Parameters:**
- `x1`, `y1`: Coordinates of the first image.
- `img1`: Pointer to the first `Image` structure.
- `x2`, `y2`: Coordinates of the second image.
- `img2`: Pointer to the second `Image` structure.
- **Returns:** Number of overlapping pixels. `>= 1` if collision is detected, `0` otherwise.
- **Note:** This function doesn't consider image rotation (Using `iRotate` and `iUnRotate`). Use `iCheckSpriteCollision` for such cases.
- **Example:**
```cpp
Image img1, img2;
iLoadImage(&img1, "image1.png");
iLoadImage(&img2, "image2.png");
....
// Check for collision between img1 at (100, 200) and img2 at (150, 250)
if (iCheckImageCollision(100, 200, &img1, 150, 250, &img2)) {
// Collision detected
}
-
Description: Checks for pixel-level collision between two sprites.
-
Parameters:
s1: Pointer to the firstSpritestructure.s2: Pointer to the secondSpritestructure.
-
Returns: Number of overlapping pixels.
>= 1if collision is detected,0otherwise. -
Example:
Sprite s1, s2; .... if (iCheckSpriteCollision(&s1, &s2)) { // Collision detected }
- Description: Checks for pixel-level collision between an image and a sprite.
- Parameters:
x1,y1: Coordinates of the image.img: Pointer to theImagestructure.s: Pointer to theSpritestructure.- Returns: Number of overlapping pixels.
>= 1if collision is detected,0otherwise. - Note: This function doesn't consider image rotation (Using
iRotateandiUnRotate). UseiCheckSpriteCollisionfor such cases.
- Example:
Image img; Sprite s; iLoadImage(&img, "image.png"); .... if (iCheckImageSpriteCollision(100, 200, &img, &s)) { // Collision detected between image and sprite }
- Description: Enters fullscreen mode.
- Example:
iEnterFullscreen(); // Enter fullscreen mode
- Description: Exits fullscreen mode and returns to windowed mode.
- Example:
iLeaveFullscreen(); // Exit fullscreen mode
This library is for educational purposes and is typically used in academic or hobbyist OpenGL projects.
- Shahriar Nirjon - Original iGraphics library
- Ashrafur Rahman Khan - Linux Support, Freeglut, SDL2 sound engine, Transparent Color, Mouse passive motion and Mouse wheel (repository)
- Anwarul Bashar Shuaib - Image cache, resize, mirror, wrap, and pixel-perfect collision detection functionality (repository)
- Wasif Jalal - SDL2 sound engine, Game Mode (repository)
- SDL2: v2.0.12
- SDL2_Mixer: v2.0.4
- Freetype: v2.3.5
- zlib: v1.2.3
- stb_image: v2.30
- stb_image_resize: v0.96
- Nano SVG