Image - Polkm105/DesignPatternPractice GitHub Wiki
PARTIAL
This section contains all functions relating to CP_Image
Table Of Contents
- CP_Image_Load
- CP_Image_Free
- CP_Image_GetWidth
- CP_Image_GetHeight
- CP_Image_Draw
- CP_Image_DrawAdvanced
- CP_Image_DrawSubImage
- CP_Image_CreateFromData
- CP_Image_Screenshot
- CP_Image_GetPixelData
- CP_Image_UpdatePixelData
CP_Image_Load
Load a CP_Image by inputting the file path of the image file as a string (const char*).
Function
CP_Image CP_Image_Load(const char* filepath);
Parameters
- filepath - (const char*) The path to the image file that you want to load.
Return
This function returns a CP_Image.
Example
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, width / 2, height / 2, width / 2, width / 2, 255);
}
void shutdown()
{
CP_Image_Free(justinFace);
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_Image
- CP_Image_Draw
- CP_Image_Free
CP_Image_Free
Free a CP_Image by giving the image that you want to free.
Function
void CP_Image_Free(CP_Image* img);
Parameters
- image - (CP_Image) The image that you want to free.
Return
This function does not return anything.
Example
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, width / 2, height / 2, width / 2, width / 2, 255);
}
void shutdown()
{
CP_Image_Free(justinFace);
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_Image
- CP_Image_Draw
- CP_Image_Load
CP_Image_GetWidth
Get the width in pixels of a given CP_Image.
Function
int CP_Image_GetWidth(CP_Image img);
Parameters
- image- (CP_Image) The image that you want to know the width of
Return
- int- The width of the image in pixels
Example
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_Image_GetWidth(justinFace);
int windowWidth = CP_System_GetWindowWidth();
int windowHeight = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, windowWidth / 2, windowHeight / 2, windowWidth / 2, windowHeight / 2, 255);
}
void shutdown()
{
CP_Image_Free(justinFace);
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_Image
- CP_Image_Load
- CP_Image_Draw
- CP_Image_Free
CP_Image_GetHeight
Get the height in pixels of a given CP_Image.
Function
int CP_Image_GetHeight(CP_Image img);
Parameters
- image- (CP_Image) The image that you want to know the height of
Return
- int- The height of the image in pixels
Example
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int height = CP_Image_GetHeight(justinFace);
int windowWidth = CP_System_GetWindowWidth();
int windowHeight = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, windowWidth / 2, windowHeight / 2, windowWidth / 2, windowHeight / 2, 255);
}
void shutdown()
{
CP_Image_Free(justinFace);
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_Image
- CP_Image_Load
- CP_Image_Draw
- CP_Image_Free
CP_Image_Draw
Draws a given CP_Image to the screen using the given size and coordinates.
Function
void CP_Image_Draw(CP_Image img, float x, float y, float w, float h, int alpha);
Parameters
- image- (CP_Image) The image that you want to draw to the screen
- x- (float) The x coordinate of the image in screen coordinates
- y- (float) The y coordinate of the image in screen coordinates
- w- (float) The width to draw the image in pixels
- h- (float) The height to draw the image in pixels
- alpha- (float) The alpha value to draw the image with (0-255)
Return
This function does not return anything.
Example
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
CP_Image_Draw(justinFace, width / 2, height / 2, width / 2, width / 2, 255);
}
void shutdown()
{
CP_Image_Free(justinFace);
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_Image
- CP_Image_Load
- CP_Image_Free
CP_Image_DrawAdvanced
Draws a given CP_Image to the screen using the given position, size, alpha, and rotation.
Function
void CP_Image_DrawAdvanced(CP_Image img, float x, float y, float w, float h, int alpha, float degrees);
Parameters
- image- (CP_Image) The image that you want to draw to the screen
- x- (float) The x coordinate of the image in screen coordinates
- y- (float) The y coordinate of the image in screen coordinates
- w- (float) The width to draw the image in pixels
- h- (float) The height to draw the image in pixels
- alpha- (float) The alpha value to draw the image with (0-255)
- degrees- (float) The degrees to rotate the image
Return
This function does not return anything.
Example
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
CP_Image_DrawAdvanced(justinFace, width / 2, height / 2, width / 2, width / 2, 255, 180);
}
void shutdown()
{
CP_Image_Free(justinFace);
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_Image
- CP_Image_Load
- CP_Image_Free
CP_Image_DrawSubImage
Draws a given CP_Image to the screen using the given position, size, texture coordinates, and alpha.
Function
void CP_Image_DrawSubImage(CP_Image img, float x, float y, float w, float h, float u0, float v0, float u1, float v1, int alpha);
Parameters
- image- (CP_Image) The image that you want to draw to the screen
- x - (float) The x coordinate of the image in screen coordinates
- y - (float) The y coordinate of the image in screen coordinates
- w - (float) The width to draw the image in pixels
- h - (float) The height to draw the image in pixels
- s0 - (float) The left most pixel of the sub-image(far left = 0)
- t0 - (float) The top most pixel of the sub-image (top = 0)
- s1 - (float) The right most pixel for the sub-image (far right = image width)
- t0 - (float) The bottom most pixel for the sub-image (bottom = image height)
- alpha - (int) The alpha value to draw the image with (0-255)
Return
This function does not return anything.
Example
CP_Image justinFace = NULL;
void init()
{
justinFace = CP_Image_Load("./Assets/Justins_face.png");
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
int imageWidth = CP_Image_GetWidth(justinFace);
int imageHeight = CP_Image_GetHeight(justinFace);
// draws the top left quarter of the image
CP_Image_DrawSubImage(justinFace, (width / 2), (height / 2), width, height, 0, 0, imageWidth / 2, imageHeight / 2, 255);
}
void shutdown()
{
CP_Image_Free(justinFace);
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_Image
- CP_Image_GetWidth
- CP_Image_GetHeight
- CP_Image_Load
- CP_Image_Free
CP_Image_CreateFromData
Creates a CP_Image from the given data.
Function
CP_Image CP_Image_CreateFromData(int w, int h, unsigned char* pixelDataInput);
Parameters
- w - (int) The width you want the created image to be (must correspond to the size of the data given)
- h - (int) The height you want the created image to be (must correspond to the size of the data given)
- pixelDataInput - (unsigned char*) The data to use to create the new image
Return
Example
CP_Image justinFace = NULL;
void init()
{
unsigned char pixelData[] = {
255, 0, 0, 255, 255, 0, 0, 255, // 2 red pixels
0, 0, 255, 255, 0, 0, 255, 255 // 2 blue pixels
};
justinFace = CP_Image_CreateFromData(2, 2, pixelData);
}
void update()
{
CP_Graphics_ClearBackground(CP_Color_Create(255, 255, 255, 255));
int width = CP_System_GetWindowWidth();
int height = CP_System_GetWindowHeight();
// draws the top left quarter of the image
CP_Image_Draw(justinFace, width / 2, height / 2, width, height, 255);
}
void shutdown()
{
CP_Image_Free(justinFace);
}
Related
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_GetWindowWidth
- CP_System_GetWindowHeight
- CP_Image_Draw
- CP_Image_Free