blob: 11dd318148bb41b34992638179d1f70af5e91c86 (
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
|
/*
ui/modelview.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include "auxiliary/functions.h"
#include "ui/modelview.h"
#include "ui/paint.h"
#include "sys/sys.h"
#include "render/camera.h"
#include "render/draw.h"
#include "render/render.h"
namespace ui
{
ModelView::ModelView(Widget *parent, const char *modelname) : Widget(parent)
{
set_border(false);
set_background(false);
set_label("modelview");
set_modelname(modelname);
}
ModelView::~ModelView()
{}
void ModelView::print(const size_t indent) const
{
std::string marker("");
con_print << aux::pad_left(marker, indent*2) << label() << " \"" << modelname() << "\"" << std::endl;
}
void ModelView::set_modelname(const std::string & modelname)
{
modelview_modelname.assign(modelname);
}
void ModelView::set_modelname(const char *modelname)
{
if (modelname)
modelview_modelname.assign(modelname);
else
modelview_modelname.clear();
}
void ModelView::set_color(const math::Color & color)
{
modelview_color.assign(color);
}
void ModelView::draw()
{
if (!modelview_modelname.size())
return;
model::Model *model = model::Model::find(modelview_modelname);
if (!model)
return;
math ::Vector2f center(global_location());
center.x += width() * 0.5f;
center.y += height() * 0.5f;
gl::clear(GL_DEPTH_BUFFER_BIT);
// gl 3d mode
render::Camera::frustum_default(model->radius(), center.x, center.y);
gl::disable(GL_BLEND);
gl::depthmask(GL_TRUE); // enable writing to the depth buffer
gl::enable(GL_DEPTH_TEST);
gl::enable(GL_CULL_FACE); // enable culling
gl::enable(GL_COLOR_MATERIAL); // enable color tracking
gl::enable(GL_LIGHTING);
// enable vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
render::draw_model_fragments(model, core::localplayer()->color(), core::localplayer()->color_second(), true, true, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
gl::disable(GL_LIGHTING);
gl::disable(GL_COLOR_MATERIAL); // disable color tracking
gl::disable(GL_CULL_FACE); // disable culling
gl::depthmask(GL_TRUE); // enable depth buffer writing
gl::disable(GL_DEPTH_TEST); // disable depth buffer testing
gl::enable(GL_BLEND);
// gl 2d mode
render::Camera::ortho();
}
void ModelView::draw_border()
{
paint::color(palette()->foreground());
paint::border(global_location(), size());
}
}
|