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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
#include <SDL_opengl.h>
#include "glbase.h"
#include "glshape.h"
#include "gltexture.h"
#include "glfont.h"
#define ENTER bool was2d = in2D(true)
#define ENTERT bool was2d = in2D(false)
#define LEAVE out2D(was2d)
void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) {
ENTER;
c.Bind();
glBegin(GL_TRIANGLE_STRIP);
glVertex2i(x1, y1);
glVertex2i(x2 + 1, y1);
glVertex2i(x1, y2 + 1);
glVertex2i(x2 + 1, y2 + 1);
glEnd();
LEAVE;
}
void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) {
ENTER;
glBegin(GL_TRIANGLE_STRIP);
c1.Bind(); glVertex2i(x1, y1);
c2.Bind(); glVertex2i(x2 + 1, y1);
c3.Bind(); glVertex2i(x1, y2 + 1);
c4.Bind(); glVertex2i(x2 + 1, y2 + 1);
glEnd();
LEAVE;
}
void mogltk::shape::hline(int x1, int x2, int y, ColorP c) {
box(x1, y, x2, y, c);
}
void mogltk::shape::hline3d(int x1, int x2, int y, ColorP shade1, ColorP shade2, int bevel) {
ENTER;
if (!bevel) {
hline(x1, x2, y, shade2);
hline(x1, x2, y + 1, shade1);
} else {
hline(x1, x2, y, shade1);
hline(x1, x2, y + 1, shade2);
}
LEAVE;
}
void mogltk::shape::vline(int x, int y1, int y2, ColorP c) {
box(x, y1, x, y2, c);
}
void mogltk::shape::vline3d(int x, int y1, int y2, ColorP shade1, ColorP shade2, int bevel) {
ENTER;
if (!bevel) {
vline(x, y1, y2, shade2);
vline(x + 1, y1, y2, shade1);
} else {
vline(x, y1, y2, shade1);
vline(x + 1, y1, y2, shade2);
}
LEAVE;
}
void mogltk::shape::hline(int x1, int x2, int y, ColorP c1, ColorP c2) {
box(x1, y, x2, y, c1, c2, c1, c2);
}
void mogltk::shape::vline(int x, int y1, int y2, ColorP c1, ColorP c2) {
box(x, y1, x, y2, c1, c1, c2, c2);
}
void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c) {
ENTER;
hline(x1, x2, y1, c);
hline(x1, x2, y2, c);
vline(x1, y1, y2, c);
vline(x2, y1, y2, c);
LEAVE;
}
void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) {
ENTER;
hline(x1, x2, y1, c1, c2);
hline(x1, x2, y2, c3, c4);
vline(x1, y1, y2, c1, c3);
vline(x2, y1, y2, c2, c4);
LEAVE;
}
void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) {
tbox(t, x1, y1, x2, y2, tx, ty, tx + (x2 - x1) * f, ty + (y2 - y1) * f, c);
}
void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx, int ty, double f) {
tbox(t, x1, y1, x2, y2, c1, c2, c3, c4, tx, ty, tx + (x2 - x1) * f, ty + (y2 - y1) * f);
}
void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP c) {
ENTERT;
c.Bind();
t->Bind();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2i(tx1, ty1); glVertex2i(x1, y1);
glTexCoord2i(tx2 + 1, ty1); glVertex2i(x2 + 1, y1);
glTexCoord2i(tx1, ty2 + 1); glVertex2i(x1, y2 + 1);
glTexCoord2i(tx2 + 1, ty2 + 1); glVertex2i(x2 + 1, y2 + 1);
glEnd();
LEAVE;
}
void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx1, int ty1, int tx2, int ty2) {
ENTERT;
t->Bind();
glBegin(GL_TRIANGLE_STRIP);
c1.Bind(); glTexCoord2i(tx1, ty1); glVertex2i(x1, y1);
c2.Bind(); glTexCoord2i(tx2 + 1, ty1); glVertex2i(x2 + 1, y1);
c3.Bind(); glTexCoord2i(tx1, ty2 + 1); glVertex2i(x1, y2 + 1);
c4.Bind(); glTexCoord2i(tx2 + 1, ty2 + 1); glVertex2i(x2 + 1, y2 + 1);
glEnd();
LEAVE;
}
void mogltk::shape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP shade1, ColorP shade2, int depth, int bevel) {
ENTER;
if (!bevel) {
shade1.Bind();
} else {
shade2.Bind();
}
glBegin(GL_TRIANGLE_FAN);
glVertex2i(x1, y1);
glVertex2i(x2 + 1, y1);
glVertex2i(x2 + 1 - depth, y1 + depth);
glVertex2i(x1 + depth, y2 + 1 - depth);
glVertex2i(x1, y2 + 1);
glEnd();
if (!bevel) {
shade2.Bind();
} else {
shade1.Bind();
}
glBegin(GL_TRIANGLE_FAN);
glVertex2i(x2 + 1, y2 + 1);
glVertex2i(x1, y2 + 1);
glVertex2i(x1 + depth, y2 + 1 - depth);
glVertex2i(x2 + 1 - depth, y1 + depth);
glVertex2i(x2 + 1, y1);
glEnd();
face.Bind();
glBegin(GL_TRIANGLE_STRIP);
glVertex2i(x1 + depth, y1 + depth);
glVertex2i(x2 + 1 - depth, y1 + depth);
glVertex2i(x1 + depth, y2 + 1 - depth);
glVertex2i(x2 + 1 - depth, y2 + 1 - depth);
glEnd();
LEAVE;
}
void mogltk::shape::obox3d(int x1, int y1, int x2, int y2, ColorP shade1, ColorP shade2, int bevel) {
ENTER;
if (!bevel) {
obox(x1 + 1, y1 + 1, x2, y2, shade1);
obox(x1, y1, x2 - 1, y2 - 1, shade2);
} else {
obox(x1, y1, x2 - 1, y2 - 1, shade1);
obox(x1 + 1, y1 + 1, x2, y2, shade2);
}
LEAVE;
}
void mogltk::shape::window(int x1, int y1, int x2, int y2, String title,
ColorP titlecolor, ColorP titlebackcolor,
ColorP front, ColorP shade1, ColorP shade2) {
ENTER;
box3d(x1, y1, x2, y2, front, shade1, shade2);
hline3d(x1 + 2, x2 - 2, y1 + 18, shade1, shade2, 1);
box(x1 + 2, y1 + 2, x2 - 2, y1 + 17, titlebackcolor);
int tsize = SystemFont->singletextsize(title);
SystemFont->putcursor((x2 + x1 - tsize) / 2, y1 + 2);
SystemFont->setcolor(titlecolor);
SystemFont->setshadow(0);
SystemFont->printf(title);
LEAVE;
}
void mogltk::shape::text3d(int x, int y, String text, ColorP textcolor,
ColorP shade1, ColorP shade2,
align_t align, int bevel) {
}
bool mogltk::shape::in2D(bool unbind) {
bool was2D = mogltk::glbase::is2D();
if (!was2D)
mogltk::glbase::Enter2DMode();
if (unbind) mogltk::texture::Unbind();
return was2D;
}
void mogltk::shape::out2D(bool was2D) {
if (!was2D)
mogltk::glbase::Leave2DMode();
}
|