-
Notifications
You must be signed in to change notification settings - Fork 3
Graphics
This section contains all of the Graphics functions.
- CP_Graphics_ClearBackground
- CP_Graphics_DrawPoint
- CP_Graphics_DrawLine
- CP_Graphics_DrawLineAdvanced
- CP_Graphics_DrawRect
- CP_Graphics_DrawRectAdvanced
- CP_Graphics_DrawCircle
- CP_Graphics_DrawEllipse
- CP_Graphics_DrawEllipseAdvanced
- CP_Graphics_DrawTriangle
- CP_Graphics_DrawTriangleAdvanced
- CP_Graphics_DrawQuad
- CP_Graphics_DrawQuadAdvanced
- CP_Graphics_BeginShape
- CP_Graphics_AddVertex
- CP_Graphics_EndShape
This function clears anything previously drawn to the screen and sets the entire screen to the provided color. Typically, you will use this at the beginning of any update loop to set a background color.
void CP_Graphics_ClearBackground(CP_Color color);
- color (CP_Color) - The color that will be used to clear the screen.
This function does not return anything.
void update()
{
// Create the color green
CP_Color myColor = CP_Color_Create(0, 255, 0, 255);
// Set the background color to green and erase anything that was previously crawn
CP_Graphics_ClearBackground(myColor);
}
This function draws a point at a given position. The color of the point is specified with the function CP_Settings_Fill. There is no stroke option for a point.
void CP_Graphics_DrawPoint(float x, float y);
- x (float) - The horizontal position of the point.
- y (float) - The vertical position of the point.
This function does not return anything.
void init()
{
// fill the background black to see the white points
CP_Graphics_ClearBackground(CP_Color_Create(0, 0, 0, 255));
}
void update()
{
// Hide the cursor on this window
CP_System_ShowCursor(false);
// fill the pixel white
CP_Settings_Fill(CP_Color_Create(0, 0, 0, 255));
// draw a single pixel at the mouse position
CP_Graphics_DrawPoint(CP_Input_GetMouseX(), CP_Input_GetMouseY());
}
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_System_ShowCursor
- CP_Settings_Fill
- CP_Input_GetMouseX
- CP_Input_GetMouseY
This function draws a line using two points. For most shapes you can set the color using CP_Settings_Fill, but a line is only a stroke, so you must use CP_Settings_Stroke to set the color.
void CP_Graphics_DrawLine(float x1, float y1, float x2, float y2);
- x1 (float) - The first point's x position.
- y1 (float) - The first point's y position.
- x2 (float) - The second point's x position.
- y2 (float) - The second point's y position.
This function does not return anything.
void update()
{
// set the stroke color to orange
CP_Settings_Stroke(CP_Color_Create(255, 160, 20, 255));
// draw a line from (100, 100) to (100, 200)
// x1 y1 x2 y2
CP_Graphics_DrawLine(100.0f, 100.0f, 500.0f, 100.0f);
// set the stroke color to light blue
CP_Settings_Stroke(CP_Color_Create(0, 160, 255, 255));
// draw a line from the origin to the mouse position
CP_Graphics_DrawLine(0.0f, 0.0f, CP_Input_GetMouseX(), CP_Input_GetMouseY());
}
A specialized version of the CP_Graphics_DrawLine function which allows the user to specify a rotation (in degrees). The line is always rotated around the center.
void CP_Graphics_DrawLineAdvanced(float x1, float y1, float x2, float y2, float degrees);
- x1 (float) - The horizontal position of the start of the line.
- y1 (float) - The vertical position of the start of the line.
- x2 (float) - The horizontal position of the end of the line.
- y1 (float) - The vertical position of the end of the line.
- degrees (float) - The rotation in degrees.
This function does not return anything.
void update()
{
// a line from (100, 100) to (200, 100) rotated 45 degrees about the center
CP_Graphics_DrawLineAdvanced(100.0f, 100.0f, 200.0f, 100.0f, 45.0f);
}
This is a function that draws a rectangle on the screen at a specified point with a specified width and height.
Note: You can use CP_Settings_RectMode to control whether the specified point refers to the center of the rectangle or to its top left corner.
void CP_Graphics_DrawRect(float x, float y, float w, float h);
- x (float) - The horizontal position of the rectangle.
- y (float) - The vertical position of the rectangle.
- w (float) - The width of the rectangle.
- h (float) - The height of the rectangle.
This function does not return anything.
void update()
{
// Clear the background to a blue color
CP_Graphics_ClearBackground(CP_Color_Create(20, 200, 255, 255));
// Draw a rectangle at the point (100, 100)
CP_Graphics_DrawRect(100.0f, 100.0f, 50.0f, 50.0f);
// Draw a rectangle at the mouse position
CP_Graphics_DrawRect(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 25.0f, 25.0f);
}
- CP_Settings_RectMode
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_Input_GetMouseX
- CP_Input_GetMouseY
This is a specialized version of the CP_Graphics_DrawRect function which additionally allows you to specify a rotation (in degrees). This rotates the rectangle around the reference point at which you draw the rectangle, so the CP_POSITION_CENTER CP_Settings_RectMode will rotate around the center of the rectangle, while the CP_POSITION_CORNER CP_Settings_RectMode will rotate around the top-left corner.
void CP_Graphics_DrawRectAdvanced(float x, float y, float w, float h, float degrees, float cornerRadius);
- x (float) - The horizontal position of the rectangle.
- y (float) - The vertical position of the rectangle.
- w (float) - The width of the rectangle.
- h (float) - The height of the rectangle.
- degrees (float) - The rotation in degrees.
- cornerRadius (float) - The radius of the rounded corners of the rectangle (0 for no rounded corners).
This function does not return anything.
void update()
{
// draw a 100x50 rectangle rotated by 45 degrees
CP_Graphics_DrawRectAdvanced(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 100.0f, 50.0f, 45.0f);
}
This is a simplified version of CP_Graphics_DrawEllipse. A circle can be drawn on the screen using this function. The mode for drawing a circle and ellipse can be changed with CP_Settings_EllipseMode.
void CP_Graphics_DrawCircle(float x, float y, float d);
- x (float) - The horizontal position of the circle.
- y (float) - The vertical position of the circle.
- d (float) - The diameter of the circle.
This function does not return anything.
void update()
{
// set the background color
CP_Graphics_ClearBackground(CP_Color_Create(255, 40, 200, 255));
//draw a circle at (100, 100)
CP_Graphics_DrawCircle(100, 100, 50.0f);
// draw a circle at the mouse position
CP_Graphics_DrawCircle(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 20.0f);
}
- CP_Graphics_DrawEllipse
- CP_Settings_EllipseMode
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_Input_GetMouseX
- CP_Input_GetMouseY
This function allows you to draw an ellipse with differing width and height. To draw an ellipse, provide the x and y values of a point and the width and height (diameters) of your ellipse. You can set the fill color of the drawn shape with CP_Settings_Fill and the stroke color with CP_Settings_Stroke. The method for drawing ellipses can be changed to different modes using CP_Settings_EllipseMode.
void CP_Graphics_DrawEllipse(float x, float y, float w, float h);
- x (float) - The horizontal coordinate of the ellipse.
- y (float) - The vertical coordinate of the ellipse.
- w (float) - The width of the ellipse as a diameter.
- h (float) - The height of the ellipse as a diameter.
This function does not return anything.
void update()
{
// Set the background color to red
CP_Graphics_ClearBackground(CP_Color_Create(255, 100, 100, 255));
// Draw an ellipse at the point (100, 100)
CP_Graphics_DrawEllipse(100.0f, 100.0f, 50.0f, 80.0f);
// Draw an ellipse at the mouse position
CP_Graphics_DrawEllipse(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 20.0f, 60.0f);
}
- CP_Settings_EllipseMode
- CP_Settings_Fill
- CP_Settings_Stroke
- CP_Graphics_ClearBackground
- CP_Color_Create
- CP_Input_GetMouseX
- CP_Input_GetMouseY
A specialized version of the CP_Graphics_DrawEllipse function which allows you to specify a rotation (in degrees). The shape will rotate about the reference point specified by the CP_Settings_EllipseMode.
void CP_Graphics_DrawEllipseAdvanced(float x, float y, float w, float h, float degrees);
- x (float) - The horizontal position of the ellipse.
- y (float) - The vertical position of the ellipse.
- w (float) - The width (horizontal diameter) of the ellipse.
- h (float) - The height (vertical diameter) of the ellipse.
- degrees (float) - The rotation in degrees.
This function does not return anything.
void update()
{
// draw a 100x50 ellipse rotated by 45 degrees at the mouse position
CP_Graphics_DrawEllipseAdvanced(CP_Input_GetMouseX(), CP_Input_GetMouseY(), 100.0f, 50.0f, 45.0f);
}
This function draws a triangle to the screen given three points. The filled color of the triangle can be set with CP_Settings_Fill and the stroke outline can be changed with CP_Settings_Stroke.
void CP_Graphics_DrawTriangle(float x1, float y1, float x2, float y2, float x3, float y3);
- x1 (float) - The first point's horizontal position.
- y1 (float) - The first point's vertical position.
- x2 (float) - The second point's horizontal position.
- y2 (float) - The second point's vertical position.
- x3 (float) - The third point's horizontal position.
- y3 (float) - The third point's vertical position.
This function does not return anything.
void update()
{
// set the fill color to red
CP_Settings_Fill(CP_Color_Create(255, 0, 0, 255));
// draw a triangle with three points
CP_Graphics_DrawTriangle(100.0f, 100.0f, // point 1
200.0f, 100.0f, // point 2
200.0f, 200.0f); // point 3
// set the fill color to dark blue
CP_Settings_Fill(CP_Color_Create(0, 0, 160, 255));
// draw a triangle with three points
CP_Graphics_DrawTriangle(0.0f, 0.0f, // point 1
CP_Input_GetMouseX(), CP_Input_GetMouseY(), // point 2
CP_Input_GetMousePreviousX(), CP_Input_GetMousePreviousY()); // point 3
}
- CP_Settings_Fill
- CP_Settings_Stroke
- CP_Color_Create
- CP_Input_GetMouseX
- CP_Input_GetMouseY
- CP_Input_GetMousePreviousX
- CP_Input_GetMousePreviousY
A specialized version of the CP_Graphics_DrawTriangle function which allows the user to specify a rotation (in degrees). The rotation is always about the center of the triangle.
void CP_Graphics_DrawTriangleAdvanced(float x1, float y1, float x2, float y2, float x3, float y3, float degrees);
- x1 (float) - The first point's horizontal position.
- y1 (float) - The first point's vertical position.
- x2 (float) - The second point's horizontal position.
- y2 (float) - The second point's vertical position.
- x3 (float) - The third point's horizontal position.
- y3 (float) - The third point's vertical position.
- degrees (float) - The rotation in degrees.
This function does not return anything.
void update()
{
// A triangle drawn based on the points (100, 100), (125, 150), (75, 150)
// with a rotation of 15 degrees
CP_Graphics_DrawTriangleAdvanced(100.0f, 100.0f, 125.0f, 150.0f, 75.0f, 150.0f, 15.0f);
}
This function will draw a quadrangle given four points. They will need to be in clockwise or counter-clockwise order, but it doesn't matter which.
void CP_Graphics_DrawQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
- x1 (float) - The first point's horizontal position.
- y1 (float) - The first point's vertical position.
- x2 (float) - The second point's horizontal position.
- y2 (float) - The second point's vertical position.
- x3 (float) - The third point's horizontal position.
- y3 (float) - The third point's vertical position.
- x4 (float) - The fourth point's horizontal position.
- y4 (float) - The fourth point's vertical position.
This function does not return anything.
void update()
{
// draw a quadrangle given four points
// x y
CP_Graphics_DrawQuad(0.0f, 0.0f, // corner 1
100.0f, 0.0f, // corner 2
100.0f, 50.0f, // corner 3
0.0f, 50.0f); // corner 4
}
A specialized version of the CP_Graphics_DrawQuad function which allows the user to specify a rotation in degrees. The quadrangle is always rotated about the center.
void CP_Graphics_DrawQuadAdvanced(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float degrees);
- x1 (float) - The first point's horizontal position.
- y1 (float) - The first point's vertical position.
- x2 (float) - The second point's horizontal position.
- y2 (float) - The second point's vertical position.
- x3 (float) - The third point's horizontal position.
- y3 (float) - The third point's vertical position.
- x4 (float) - The fourth point's horizontal position.
- y4 (float) - The fourth point's vertical position.
- degrees (float) - The rotation in degrees.
This function does not return anything.
void update()
{
// draw a quad rotated by 45 degrees
CP_Graphics_DrawQuadAdvanced(100.0f, 100.0f, // corner 1
200.0f, 100.0f, // corner 2
200.0f, 150.0f, // corner 3
100.0f, 150.0f, // corner 4
45.0f); // degrees rotation
}
Using CP_Graphics_BeginShape(), CP_Graphics_AddVertex, and CP_Graphics_EndShape, a shape can be defined with any number of vertices. After CP_Graphics_BeginShape() is called, use CP_Graphics_AddVertex to specify the vertices of the shape. A shape will not be drawn until CP_Graphics_EndShape is called.
void CP_Graphics_BeginShape(void);
This function has no parameters.
This function does not return anything.
void update()
{
// Start drawing a shape
CP_Graphics_BeginShape();
// Specify three vertices
CP_Graphics_AddVertex(100.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 200.0f);
// signal the end of the shape and draw the shape
CP_Graphics_EndShape();
}
Using CP_Graphics_BeginShape, CP_Graphics_AddVertex, and CP_Graphics_EndShape, a shape can be defined with any number of vertices. After CP_Graphics_BeginShape is called, use CP_Graphics_AddVertex to specify the vertices of the shape. A shape will not be drawn until CP_Graphics_EndShape is called.
void CP_Graphics_AddVertex(float x, float y);
- x (float) - The horizontal position of the vertex.
- y (float) - The vertical position of the vertex.
This function does not return anything.
void update()
{
// Start drawing a shape
CP_Graphics_BeginShape();
// Specify three vertices
CP_Graphics_AddVertex(100.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 200.0f);
// signal the end of the shape and draw the shape
CP_Graphics_EndShape();
}
Using CP_Graphics_BeginShape, CP_Graphics_AddVertex, and CP_Graphics_EndShape, a shape can be defined with any number of vertices. After CP_Graphics_BeginShape is called, use CP_Graphics_AddVertex to specify the vertices of the shape. A shape will not be drawn until CP_Graphics_EndShape is called.
void CP_Graphics_EndShape(void);
This function has no parameters.
This function does not return anything.
void update()
{
// Start drawing a shape
CP_Graphics_BeginShape();
// Specify three vertices
CP_Graphics_AddVertex(100.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 100.0f);
CP_Graphics_AddVertex(200.0f, 200.0f);
// signal the end of the shape and draw the shape
CP_Graphics_EndShape();
}