-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimitives.cpp
94 lines (71 loc) · 1.85 KB
/
Primitives.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
91
92
93
94
#include "Primitives.h"
#include "IncludeGL.h"
namespace Drawing
{
void DrawLine( const Math::Vector2f lineStart, const Math::Vector2f lineEnd, LINE_TYPE lineType, float lineWidth )
{
#ifdef EMSCRIPTEN
#else
glPushMatrix();
// LINES
glLineWidth( lineWidth );
if( lineType != SOLID )
{
glEnable ( GL_LINE_STIPPLE );
if( lineType == DASHED )
glLineStipple (1, 0x00FF); /* dashed */
else
glLineStipple (1, 0x0101); /* dotted */
}
glBegin( GL_LINES );
glVertex2f( lineStart.x, lineStart.y );
glVertex2f( lineEnd.x, lineEnd.y );
glEnd();
if( lineType != SOLID )
{
glDisable( GL_LINE_STIPPLE );
}
glPopMatrix();
#endif
}
void DrawQuad( int sizeX ,int sizeY,
const Math::Vector2& uv1,
const Math::Vector2& uv2,
const Math::Vector2& uv3,
const Math::Vector2& uv4
)
{
Math::Vector2 mins( -sizeX * 0.5f,-sizeY * 0.5f );
Math::Vector2 maxs( sizeX * 0.5f, sizeY * 0.5f );
glBegin( GL_TRIANGLE_STRIP );
glTexCoord2f( uv1.x, uv1.y );
glVertex2f( mins.x, maxs.y );
glTexCoord2f( uv2.x, uv2.y );
glVertex2f( maxs.x, maxs.y );
glTexCoord2f( uv3.x, uv3.y );
glVertex2f( mins.x, mins.y);
glTexCoord2f( uv4.x, uv4.y );
glVertex2f( maxs.x, mins.y );
glEnd();
}
void DrawBoundinBox( const Math::Vector2& mins , const Math::Vector2& maxs )
{
Math::Vector2 topLeft ( mins.x, maxs.y );
Math::Vector2 bottomLeft ( mins.x, mins.y );
Math::Vector2 topRight ( maxs.x, maxs.y );
Math::Vector2 bottomRight( maxs.x, mins.y );
glPushMatrix();
// Disabling texture 2D
glDisable( GL_TEXTURE_2D );
glBegin( GL_LINE_STRIP );
glVertex2fv( &topLeft.x );
glVertex2fv( &bottomLeft.x );
glVertex2fv( &bottomRight.x );
glVertex2fv( &topRight.x );
glVertex2fv( &topLeft.x );
glEnd();
// Enabling texture 2D
glEnable(GL_TEXTURE_2D);
glPopMatrix();
}
}