Permalink
Browse files

Add `S2D_DrawCircle`

  • Loading branch information...
blacktm committed Sep 19, 2018
1 parent 1060a6e commit 7511e1551d0b028c64316d7d394a81fe68cdd515
Showing with 43 additions and 0 deletions.
  1. +6 −0 README.md
  2. +8 −0 include/simple2d.h
  3. +23 −0 src/shapes.c
  4. +6 −0 test/testcard.c
View
@@ -323,6 +323,12 @@ S2D_DrawLine(x1, y1, x2, y2,
r4, g4, b4, a4);
```
To draw a circle, use:
```c
S2D_DrawCircle(x, y, radius, sectors, r, g, b, a);
```
### Images
Images in many popular formats, like JPEG, PNG, and BMP can be drawn in the window. Unlike shapes, images need to be read from files and stored in memory. Simply declare a pointer to an `S2D_Image` structure and initialize it using `S2D_CreateImage` providing the file path to the image.
View
@@ -440,6 +440,14 @@ void S2D_DrawLine(
GLfloat r4, GLfloat g4, GLfloat b4, GLfloat a4
);
/*
* Draw a circle from triangles
*/
void S2D_DrawCircle(
GLfloat x, GLfloat y, GLfloat radius, int sectors,
GLfloat r, GLfloat g, GLfloat b, GLfloat a
);
// Image ///////////////////////////////////////////////////////////////////////
/*
View
@@ -129,3 +129,26 @@ void S2D_DrawLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2,
x2 - y, y2 + x, r4, g4, b4, a4
);
};
/*
* Draw a circle from triangles
*/
void S2D_DrawCircle(GLfloat x, GLfloat y, GLfloat radius, int sectors,
GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
double angle = 2 * M_PI / sectors;
for (int i = 0; i < sectors; i++) {
GLfloat x1 = x + radius * cos(i * angle);
GLfloat y1 = y + radius * sin(i * angle);
GLfloat x2 = x + radius * cos((i - 1) * angle);
GLfloat y2 = y + radius * sin((i - 1) * angle);
S2D_GL_DrawTriangle( x, y, r, g, b, a,
x1, y1, r, g, b, a,
x2, y2, r, g, b, a);
}
}
View
@@ -294,6 +294,12 @@ void render() {
1, 0, 1, 0.5
);
// Circles
S2D_DrawCircle(525, 225, 25, 20, 1.0, 0.2, 0.2, 1);
S2D_DrawCircle(575, 225, 25, 8, 0.2, 1.0, 0.2, 1);
S2D_DrawCircle(575, 225, 17, 16, 0, 0, 0, 0.6);
// Images
S2D_DrawImage(img_png);

0 comments on commit 7511e15

Please sign in to comment.