-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShapeDraw.cpp
90 lines (82 loc) · 2.11 KB
/
ShapeDraw.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <windows.h> // Header File For Windows
#include "baseTypes.h"
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include "glut.h"
#include <math.h>
//#include <stdlib.h>
#include <stdio.h>
const float DEG2RAD = 3.14159f/180.0f;
void DrawCircle(float_t radius, float_t x, float_t y, char8_t r, char8_t g, char8_t b, bool filled)
{
glEnable(GL_POINT_SMOOTH);
if(!filled)
{
glDisable(GL_TEXTURE_2D);
glColor4ub(r, g, b,0xFF);
// Set the point size
glPointSize(1.0);
glBegin(GL_POINTS);
float_t radiusMax = radius + 2.0f;
float_t radiusMin = radius - 2.0f;
for (int i=0; i < 360; i+=2)
{
float degInRad = i*DEG2RAD;
glVertex2f(x + (cos(degInRad)*radius),y + (sin(degInRad)*radius));
glVertex2f(x + (cos(degInRad)*radiusMax),y + (sin(degInRad)*radiusMax));
glVertex2f(x + (cos(degInRad)*radiusMin),y + (sin(degInRad)*radiusMin));
}
}
else
{
glColor4ub(r, g, b,0xFF);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPointSize(radius/2.0f);
glBegin(GL_POINTS);
glVertex2f(x, y);
}
glEnd();
}
void DrawLine(float_t startX, float_t startY, float_t endX, float_t endY, char8_t r, char8_t g, char8_t b)
{
glColor3ub(r, g, b);
// Draw filtered lines
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINE_STRIP);
glVertex2f(startX, startY);
glVertex2f(endX, endY);
glEnd();
}
void DrawRect(float_t startX, float_t startY, float_t endX, float_t endY, char8_t r, char8_t g, char8_t b, bool filled)
{
glColor3ub(r, g, b);
// Draw filtered lines
/*
glBegin(GL_POLYGON);
glVertex2f(startX, startY);
glVertex2f(endX, startY);
glVertex2f(endX, endY);
glVertex2f(startX, endY);
glEnd();
*/
glColor3ub(r, g, b);
if (filled) {
glBegin(GL_QUADS);
glVertex3f(startX,startY,0);
glVertex3f(endX,startY,0);
glVertex3f(endX,endY,0);
glVertex3f(startX,endY,0);
glEnd();
}
else
{
glBegin(GL_LINE_STRIP);
glVertex2f(startX, startY);
glVertex2f(endX, startY);
glVertex2f(endX, endY);
glVertex2f(startX, endY);
glVertex2f(startX, startY);
glEnd();
}
}