-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglFunc.hpp
72 lines (58 loc) · 2.25 KB
/
glFunc.hpp
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
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
struct Colorf
{
int r, g, b;
Colorf(int bw) : r(bw), g(bw), b(bw) {}
Colorf(int r, int g, int b) : r(r), g(g), b(b) {}
Colorf operator+(Colorf const& colorf) {return Colorf(r + colorf.r, g + colorf.g, b + colorf.b);}
Colorf operator-(Colorf const& colorf) {return Colorf(r - colorf.r, g - colorf.g, b - colorf.b);}
Colorf operator*(Colorf const& colorf) {return Colorf(r * colorf.r, g * colorf.g, b * colorf.b);}
Colorf operator/(Colorf const& colorf) {return Colorf(r / colorf.r, g / colorf.g, b / colorf.b);}
};
struct Vec2{
float x, y;
Vec2(float value) : x(value), y(value) {}
Vec2(float _x, float _y) : x(_x), y(_y) {}
Vec2 operator+(Vec2 const& vec2) {return Vec2(x + vec2.x, y + vec2.y);}
Vec2 operator-(Vec2 const& vec2) {return Vec2(x - vec2.x, y - vec2.y);}
Vec2 operator*(Vec2 const& vec2) {return Vec2(x * vec2.x, y * vec2.y);}
Vec2 operator/(Vec2 const& vec2) {return Vec2(x / vec2.x, y / vec2.y);}
};
namespace draw{
namespace v2{
void point(Colorf color, int w, Vec2 point){
glPointSize(w);
glColor3f(color.r,color.g,color.b);
glBegin(GL_POINTS);
glVertex2f(point.x,point.y);
glEnd();
}
void line(Colorf color, int w, Vec2 point1, Vec2 point2){
glLineWidth(w);
glColor3f(color.r,color.g,color.b);
glBegin(GL_LINES);
glVertex2d(point1.x,point1.y);
glVertex2d(point2.x,point2.y);
glEnd();
}
void triangle(Colorf color, Vec2 point1, Vec2 point2, Vec2 point3){
glColor3f(color.r,color.g,color.b);
glBegin(GL_TRIANGLES);
glVertex2d(point1.x,point1.y);
glVertex2d(point2.x,point2.y);
glVertex2d(point3.x,point3.y);
glEnd();
}
void quad(Colorf color, Vec2 point1, Vec2 point2, Vec2 point3, Vec2 point4){
glColor3f(color.r,color.g,color.b);
glBegin(GL_QUADS);
glVertex2d(point1.x,point1.y);
glVertex2d(point2.x,point2.y);
glVertex2d(point3.x,point3.y);
glVertex2d(point4.x,point4.y);
glEnd();
}
}
}