summaryrefslogtreecommitdiff
path: root/lib/glshape.cc
blob: 831be3212a72a4016fd4a597e7bbb8e0bf677bfd (plain)
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
#include <SDL_opengl.h>
#include "glbase.h"
#include "glshape.h"
#include "gltexture.h"
#include "glfont.h"
#include "engine.h"

#define ENTER bool was2d = Enter(true)
#define ENTERT bool was2d = Enter(false)
#define LEAVE Leave(was2d)

void mogltk::glshape::box(int x1, int y1, int x2, int y2, glColorP 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::glshape::box(int x1, int y1, int x2, int y2, glColorP c1, glColorP c2, glColorP c3, glColorP 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::glshape::tbox(mogltk::gltexture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, glColorP 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::glshape::tbox(mogltk::gltexture * t, int x1, int y1, int x2, int y2, glColorP c1, glColorP c2, glColorP c3, glColorP 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::glshape::box3d(int x1, int y1, int x2, int y2, glColorP face, glColorP shade1, glColorP shade2, int depth, bool 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;
}

bool mogltk::glshape::Enter(bool unbind) {
    bool was2D = mogltk::engine::glbase_o->is2D();
    
    if (!was2D)
	mogltk::engine::glbase_o->Enter2DMode();
    
    if (unbind) mogltk::gltexture::Unbind();
    
    return was2D;
}

bool mogltk::glshape::Enter() {
    return Enter(true);
}

void mogltk::glshape::Leave(bool was2D) {
    if (!was2D)
	mogltk::engine::glbase_o->Leave2DMode();
}