| 1 |
/* gtkmm example Copyright (C) 2025 gtkmm development team |
| 2 |
* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License as published by |
| 5 |
* the Free Software Foundation; either version 2 of the License, or |
| 6 |
* (at your option) any later version. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License along |
| 14 |
* with this program; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "exampleglarea.h" |
| 18 |
#include "shaders.h" // Include for shader source strings |
| 19 |
|
| 20 |
// epoxy/gl.h is already included in exampleglarea.h, no need to include again here unless specifically needed later. |
| 21 |
// #include <epoxy/gl.h> |
| 22 |
#include <iostream> // For standard input/output operations |
| 23 |
#include <cmath> // For mathematical functions |
| 24 |
#include <glm/gtc/matrix_transform.hpp> // For GLM matrix transformations |
| 25 |
#include <glm/gtc/type_ptr.hpp> // For glm::value_ptr |
| 26 |
#include <vector> // For std::vector |
| 27 |
|
| 28 |
// Initialize the static constant arrays with the actual data |
| 29 |
// No change needed here, as they are now correctly declared as static const in the header. |
| 30 |
const GLfloat ExampleGLArea::m_default_cube_vertex_data[24 * 8] = { |
| 31 |
// Front face (Front: Z=0.5) - Bright Green |
| 32 |
-0.5f, -0.5f, 0.5f, 1.0f, COLOR_FRONT.r, COLOR_FRONT.g, COLOR_FRONT.b, COLOR_FRONT.a, |
| 33 |
0.5f, -0.5f, 0.5f, 1.0f, COLOR_FRONT.r, COLOR_FRONT.g, COLOR_FRONT.b, COLOR_FRONT.a, |
| 34 |
0.5f, 0.5f, 0.5f, 1.0f, COLOR_FRONT.r, COLOR_FRONT.g, COLOR_FRONT.b, COLOR_FRONT.a, |
| 35 |
-0.5f, 0.5f, 0.5f, 1.0f, COLOR_FRONT.r, COLOR_FRONT.g, COLOR_FRONT.b, COLOR_FRONT.a, |
| 36 |
|
| 37 |
// Back face (Back: Z=-0.5) - Yellow |
| 38 |
-0.5f, -0.5f, -0.5f, 1.0f, COLOR_BACK.r, COLOR_BACK.g, COLOR_BACK.b, COLOR_BACK.a, |
| 39 |
0.5f, -0.5f, -0.5f, 1.0f, COLOR_BACK.r, COLOR_BACK.g, COLOR_BACK.b, COLOR_BACK.a, |
| 40 |
0.5f, 0.5f, -0.5f, 1.0f, COLOR_BACK.r, COLOR_BACK.g, COLOR_BACK.b, COLOR_BACK.a, |
| 41 |
-0.5f, 0.5f, -0.5f, 1.0f, COLOR_BACK.r, COLOR_BACK.g, COLOR_BACK.b, COLOR_BACK.a, |
| 42 |
|
| 43 |
// Top face (Top: Y=0.5) - Light Blue |
| 44 |
-0.5f, 0.5f, 0.5f, 1.0f, COLOR_TOP.r, COLOR_TOP.g, COLOR_TOP.b, COLOR_TOP.a, |
| 45 |
0.5f, 0.5f, 0.5f, 1.0f, COLOR_TOP.r, COLOR_TOP.g, COLOR_TOP.b, COLOR_TOP.a, |
| 46 |
0.5f, 0.5f, -0.5f, 1.0f, COLOR_TOP.r, COLOR_TOP.g, COLOR_TOP.b, COLOR_TOP.a, |
| 47 |
-0.5f, 0.5f, -0.5f, 1.0f, COLOR_TOP.r, COLOR_TOP.g, COLOR_TOP.b, COLOR_TOP.a, |
| 48 |
|
| 49 |
// Bottom face (Bottom: Y=-0.5) - Purple |
| 50 |
-0.5f, -0.5f, -0.5f, 1.0f, COLOR_BOTTOM.r, COLOR_BOTTOM.g, COLOR_BOTTOM.b, COLOR_BOTTOM.a, |
| 51 |
0.5f, -0.5f, -0.5f, 1.0f, COLOR_BOTTOM.r, COLOR_BOTTOM.g, COLOR_BOTTOM.b, COLOR_BOTTOM.a, |
| 52 |
0.5f, -0.5f, 0.5f, 1.0f, COLOR_BOTTOM.r, COLOR_BOTTOM.g, COLOR_BOTTOM.b, COLOR_BOTTOM.a, |
| 53 |
-0.5f, -0.5f, 0.5f, 1.0f, COLOR_BOTTOM.r, COLOR_BOTTOM.g, COLOR_BOTTOM.b, COLOR_BOTTOM.a, |
| 54 |
|
| 55 |
// Right face (Right: X=0.5) - Red |
| 56 |
0.5f, -0.5f, 0.5f, 1.0f, COLOR_RIGHT.r, COLOR_RIGHT.g, COLOR_RIGHT.b, COLOR_RIGHT.a, |
| 57 |
0.5f, -0.5f, -0.5f, 1.0f, COLOR_RIGHT.r, COLOR_RIGHT.g, COLOR_RIGHT.b, COLOR_RIGHT.a, |
| 58 |
0.5f, 0.5f, -0.5f, 1.0f, COLOR_RIGHT.r, COLOR_RIGHT.g, COLOR_RIGHT.b, COLOR_RIGHT.a, |
| 59 |
0.5f, 0.5f, 0.5f, 1.0f, COLOR_RIGHT.r, COLOR_RIGHT.g, COLOR_RIGHT.b, COLOR_RIGHT.a, |
| 60 |
|
| 61 |
// Left face (Left: X=-0.5) - Dark Blue |
| 62 |
-0.5f, -0.5f, -0.5f, 1.0f, COLOR_LEFT.r, COLOR_LEFT.g, COLOR_LEFT.b, COLOR_LEFT.a, |
| 63 |
-0.5f, -0.5f, 0.5f, 1.0f, COLOR_LEFT.r, COLOR_LEFT.g, COLOR_LEFT.b, COLOR_LEFT.a, |
| 64 |
-0.5f, 0.5f, 0.5f, 1.0f, COLOR_LEFT.r, COLOR_LEFT.g, COLOR_LEFT.b, COLOR_LEFT.a, |
| 65 |
-0.5f, 0.5f, -0.5f, 1.0f, COLOR_LEFT.r, COLOR_LEFT.g, COLOR_LEFT.b, COLOR_LEFT.a |
| 66 |
}; |
| 67 |
|
| 68 |
const GLuint ExampleGLArea::m_default_cube_index_data[36] = { |
| 69 |
0, 3, 2, |
| 70 |
0, 2, 1, |
| 71 |
|
| 72 |
4, 5, 6, |
| 73 |
4, 6, 7, |
| 74 |
|
| 75 |
8, 11, 10, |
| 76 |
8, 10, 9, |
| 77 |
|
| 78 |
12, 15, 14, |
| 79 |
12, 14, 13, |
| 80 |
|
| 81 |
16, 19, 18, |
| 82 |
16, 18, 17, |
| 83 |
|
| 84 |
20, 23, 22, |
| 85 |
20, 22, 21 |
| 86 |
}; |
| 87 |
|
| 88 |
const GLuint ExampleGLArea::m_edge_index_data[12 * 2] = { |
| 89 |
0, 1, |
| 90 |
1, 2, |
| 91 |
2, 3, |
| 92 |
3, 0, |
| 93 |
|
| 94 |
4, 5, |
| 95 |
5, 6, |
| 96 |
6, 7, |
| 97 |
7, 4, |
| 98 |
|
| 99 |
0, 4, |
| 100 |
1, 5, |
| 101 |
2, 6, |
| 102 |
3, 7 |
| 103 |
}; |
| 104 |
|
| 105 |
// Constructor implementation |
| 106 |
ExampleGLArea::ExampleGLArea() |
| 107 |
{ |
| 108 |
set_allowed_apis(Gdk::GLApi::GL); |
| 109 |
|
| 110 |
m_camera_position = glm::vec3(0.0f, 0.0f, 2.0f); |
| 111 |
m_camera_target = glm::vec3(0.0f, 0.0f, 0.0f); |
| 112 |
|
| 113 |
m_rotation_angles[0] = 327.479f; |
| 114 |
m_rotation_angles[1] = 142.582f; |
| 115 |
m_rotation_angles[2] = 0.0f; |
| 116 |
|
| 117 |
auto motion_controller = Gtk::EventControllerMotion::create(); |
| 118 |
motion_controller->signal_motion().connect(sigc::mem_fun(*this, &ExampleGLArea::on_mouse_motion)); |
| 119 |
add_controller(motion_controller); |
| 120 |
|
| 121 |
auto click_controller_middle = Gtk::GestureClick::create(); |
| 122 |
click_controller_middle->set_button(GDK_BUTTON_MIDDLE); |
| 123 |
click_controller_middle->signal_pressed().connect( |
| 124 |
[this](int /*n_press*/, double x, double y) { this->on_mouse_press(GDK_BUTTON_MIDDLE, x, y); } |
| 125 |
); |
| 126 |
click_controller_middle->signal_released().connect(sigc::mem_fun(*this, &ExampleGLArea::on_mouse_release)); |
| 127 |
add_controller(click_controller_middle); |
| 128 |
|
| 129 |
auto click_controller_right = Gtk::GestureClick::create(); |
| 130 |
click_controller_right->set_button(GDK_BUTTON_SECONDARY); |
| 131 |
click_controller_right->signal_pressed().connect( |
| 132 |
[this](int /*n_press*/, double x, double y) { this->on_mouse_press(GDK_BUTTON_SECONDARY, x, y); } |
| 133 |
); |
| 134 |
click_controller_right->signal_released().connect(sigc::mem_fun(*this, &ExampleGLArea::on_mouse_release)); |
| 135 |
add_controller(click_controller_right); |
| 136 |
|
| 137 |
auto scroll_controller = Gtk::EventControllerScroll::create(); |
| 138 |
scroll_controller->set_flags(Gtk::EventControllerScroll::Flags::VERTICAL); |
| 139 |
scroll_controller->signal_scroll().connect( |
| 140 |
[this](double /*dx*/, double dy) { return this->on_scroll(dy); }, false |
| 141 |
); |
| 142 |
add_controller(scroll_controller); |
| 143 |
|
| 144 |
set_focusable(true); |
| 145 |
set_focus_on_click(true); |
| 146 |
} |
| 147 |
|
| 148 |
void ExampleGLArea::on_realize() |
| 149 |
{ |
| 150 |
Gtk::GLArea::on_realize(); |
| 151 |
|
| 152 |
try { |
| 153 |
make_current(); |
| 154 |
throw_if_error(); |
| 155 |
|
| 156 |
init_buffers(); |
| 157 |
init_shaders(); |
| 158 |
|
| 159 |
glEnable(GL_DEPTH_TEST); |
| 160 |
glEnable(GL_CULL_FACE); |
| 161 |
glCullFace(GL_BACK); |
| 162 |
|
| 163 |
glClearColor(0.5f, 0.5f, 0.5f, 1.0f); |
| 164 |
} catch (const Gdk::GLError& gle) { |
| 165 |
std::cerr << "GLArea error on realize: " << gle.domain() << "-" << gle.code() << "-" << gle.what() << std::endl; |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
void ExampleGLArea::on_unrealize() |
| 170 |
{ |
| 171 |
try { |
| 172 |
make_current(); |
| 173 |
throw_if_error(); |
| 174 |
|
| 175 |
glBindVertexArray(m_vao); |
| 176 |
glDeleteBuffers(1, &m_position_buffer); |
| 177 |
glDeleteBuffers(1, &m_index_buffer); |
| 178 |
glDeleteBuffers(1, &m_edge_index_buffer); |
| 179 |
glDeleteProgram(m_program); |
| 180 |
glDeleteVertexArrays(1, &m_vao); |
| 181 |
|
| 182 |
} catch (const Gdk::GLError& gle) { |
| 183 |
std::cerr << "GLArea error on unrealize: " << gle.domain() << "-" << gle.code() << "-" << gle.what() << std::endl; |
| 184 |
} |
| 185 |
|
| 186 |
Gtk::GLArea::on_unrealize(); |
| 187 |
} |
| 188 |
|
| 189 |
bool ExampleGLArea::on_render(const Glib::RefPtr<Gdk::GLContext>& /*context*/) |
| 190 |
{ |
| 191 |
try { |
| 192 |
make_current(); |
| 193 |
throw_if_error(); |
| 194 |
|
| 195 |
glViewport(0, 0, get_width(), get_height()); |
| 196 |
|
| 197 |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 198 |
|
| 199 |
draw_object(); |
| 200 |
|
| 201 |
glFlush(); |
| 202 |
|
| 203 |
return true; |
| 204 |
} catch (const Gdk::GLError& gle) { |
| 205 |
std::cerr << "GLArea error on render: " << gle.domain() << "-" << gle.code() << "-" << gle.what() << std::endl; |
| 206 |
return false; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
void ExampleGLArea::on_mouse_press(int button, double x, double y) |
| 211 |
{ |
| 212 |
m_last_mouse_pos = glm::vec2(x, y); |
| 213 |
m_is_rotating = false; |
| 214 |
m_is_panning = false; |
| 215 |
|
| 216 |
if (button == GDK_BUTTON_MIDDLE) { |
| 217 |
m_is_rotating = true; |
| 218 |
} else if (button == GDK_BUTTON_SECONDARY) { |
| 219 |
m_is_panning = true; |
| 220 |
} |
| 221 |
grab_focus(); |
| 222 |
} |
| 223 |
|
| 224 |
void ExampleGLArea::on_mouse_release(int /*n_press*/, double /*x*/, double /*y*/) |
| 225 |
{ |
| 226 |
m_is_rotating = false; |
| 227 |
m_is_panning = false; |
| 228 |
} |
| 229 |
|
| 230 |
void ExampleGLArea::on_mouse_motion(double x, double y) |
| 231 |
{ |
| 232 |
if (m_is_rotating) { |
| 233 |
float delta_x = static_cast<float>(x - m_last_mouse_pos.x); |
| 234 |
float delta_y = static_cast<float>(y - m_last_mouse_pos.y); |
| 235 |
|
| 236 |
m_rotation_angles[1] += -delta_x * m_rotation_speed; |
| 237 |
m_rotation_angles[0] += -delta_y * m_rotation_speed; |
| 238 |
|
| 239 |
m_rotation_angles[0] = fmod(m_rotation_angles[0], 360.0f); |
| 240 |
m_rotation_angles[1] = fmod(m_rotation_angles[1], 360.0f); |
| 241 |
|
| 242 |
queue_draw(); |
| 243 |
} else if (m_is_panning) { |
| 244 |
float delta_x = static_cast<float>(x - m_last_mouse_pos.x); |
| 245 |
float delta_y = static_cast<float>(y - m_last_mouse_pos.y); |
| 246 |
|
| 247 |
float current_zoom_scale = m_camera_position.z / 2.0f; |
| 248 |
|
| 249 |
glm::vec3 camera_direction = glm::normalize(m_camera_target - m_camera_position); |
| 250 |
glm::vec3 world_up = glm::vec3(0.0f, 1.0f, 0.0f); |
| 251 |
|
| 252 |
glm::vec3 camera_right = glm::normalize(glm::cross(camera_direction, world_up)); |
| 253 |
glm::vec3 camera_up = glm::normalize(glm::cross(camera_right, camera_direction)); |
| 254 |
|
| 255 |
m_camera_position -= camera_right * delta_x * m_pan_speed * current_zoom_scale; |
| 256 |
m_camera_target -= camera_right * delta_x * m_pan_speed * current_zoom_scale; |
| 257 |
|
| 258 |
m_camera_position += camera_up * delta_y * m_pan_speed * current_zoom_scale; |
| 259 |
m_camera_target += camera_up * delta_y * m_pan_speed * current_zoom_scale; |
| 260 |
|
| 261 |
queue_draw(); |
| 262 |
} |
| 263 |
m_last_mouse_pos = glm::vec2(x, y); |
| 264 |
} |
| 265 |
|
| 266 |
bool ExampleGLArea::on_scroll(double double_y) |
| 267 |
{ |
| 268 |
m_camera_position.z += static_cast<float>(double_y) * m_zoom_speed; |
| 269 |
m_camera_position.z = glm::clamp(m_camera_position.z, 0.5f, 50.0f); |
| 270 |
|
| 271 |
queue_draw(); |
| 272 |
return true; |
| 273 |
} |
| 274 |
|
| 275 |
void ExampleGLArea::init_buffers() |
| 276 |
{ |
| 277 |
glGenVertexArrays(1, &m_vao); |
| 278 |
glBindVertexArray(m_vao); |
| 279 |
|
| 280 |
if (m_position_buffer != 0) glDeleteBuffers(1, &m_position_buffer); |
| 281 |
if (m_index_buffer != 0) glDeleteBuffers(1, &m_index_buffer); |
| 282 |
if (m_edge_index_buffer != 0) glDeleteBuffers(1, &m_edge_index_buffer); |
| 283 |
|
| 284 |
glGenBuffers(1, &m_position_buffer); |
| 285 |
glBindBuffer(GL_ARRAY_BUFFER, m_position_buffer); |
| 286 |
glBufferData(GL_ARRAY_BUFFER, sizeof(m_default_cube_vertex_data), m_default_cube_vertex_data, GL_STATIC_DRAW); |
| 287 |
|
| 288 |
glEnableVertexAttribArray(0); |
| 289 |
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 8, (void*)0); |
| 290 |
glEnableVertexAttribArray(1); |
| 291 |
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 8, (void*)(sizeof(GLfloat) * 4)); |
| 292 |
|
| 293 |
glGenBuffers(1, &m_index_buffer); |
| 294 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer); |
| 295 |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_default_cube_index_data), m_default_cube_index_data, GL_STATIC_DRAW); |
| 296 |
|
| 297 |
glGenBuffers(1, &m_edge_index_buffer); |
| 298 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_edge_index_buffer); |
| 299 |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_edge_index_data), m_edge_index_data, GL_STATIC_DRAW); |
| 300 |
|
| 301 |
glBindVertexArray(0); |
| 302 |
glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 303 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 304 |
} |
| 305 |
|
| 306 |
GLuint ExampleGLArea::create_shader(GLenum type, const char* src) |
| 307 |
{ |
| 308 |
GLuint shader = glCreateShader(type); |
| 309 |
glShaderSource(shader, 1, &src, nullptr); |
| 310 |
glCompileShader(shader); |
| 311 |
|
| 312 |
GLint status; |
| 313 |
glGetShaderiv(shader, GL_COMPILE_STATUS, &status); |
| 314 |
if (status == GL_FALSE) { |
| 315 |
GLint log_len; |
| 316 |
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len); |
| 317 |
std::vector<char> buffer(log_len + 1); |
| 318 |
glGetShaderInfoLog(shader, log_len, nullptr, buffer.data()); |
| 319 |
std::cerr << "Shader compile failure (" << (type == GL_VERTEX_SHADER ? "vertex" : "fragment") << "):\n" << buffer.data() << std::endl; |
| 320 |
glDeleteShader(shader); |
| 321 |
return 0; |
| 322 |
} |
| 323 |
return shader; |
| 324 |
} |
| 325 |
|
| 326 |
void ExampleGLArea::init_shaders() |
| 327 |
{ |
| 328 |
GLuint vertex_shader = create_shader(GL_VERTEX_SHADER, VERTEX_SHADER_SRC); |
| 329 |
GLuint fragment_shader = create_shader(GL_FRAGMENT_SHADER, FRAGMENT_SHADER_SRC); |
| 330 |
|
| 331 |
if (vertex_shader == 0 || fragment_shader == 0) { |
| 332 |
m_program = 0; |
| 333 |
return; |
| 334 |
} |
| 335 |
|
| 336 |
m_program = glCreateProgram(); |
| 337 |
glAttachShader(m_program, vertex_shader); |
| 338 |
glAttachShader(m_program, fragment_shader); |
| 339 |
|
| 340 |
glBindAttribLocation(m_program, 0, "in_position"); |
| 341 |
glBindAttribLocation(m_program, 1, "in_color"); |
| 342 |
|
| 343 |
glLinkProgram(m_program); |
| 344 |
|
| 345 |
GLint status; |
| 346 |
glGetProgramiv(m_program, GL_LINK_STATUS, &status); |
| 347 |
if (status == GL_FALSE) { |
| 348 |
GLint log_len; |
| 349 |
glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &log_len); |
| 350 |
std::vector<char> buffer(log_len + 1); |
| 351 |
glGetProgramInfoLog(m_program, log_len, nullptr, buffer.data()); |
| 352 |
std::cerr << "Program linking failure:\n" << buffer.data() << std::endl; |
| 353 |
glDeleteProgram(m_program); |
| 354 |
m_program = 0; |
| 355 |
} else { |
| 356 |
m_mvp_location = glGetUniformLocation(m_program, "mvp"); |
| 357 |
m_use_vertex_color_location = glGetUniformLocation(m_program, "use_vertex_color"); |
| 358 |
m_line_color_uniform_location = glGetUniformLocation(m_program, "line_color_uniform"); |
| 359 |
} |
| 360 |
|
| 361 |
glDetachShader(m_program, vertex_shader); |
| 362 |
glDeleteShader(vertex_shader); |
| 363 |
glDetachShader(m_program, fragment_shader); |
| 364 |
glDeleteShader(fragment_shader); |
| 365 |
} |
| 366 |
|
| 367 |
glm::mat4 ExampleGLArea::compute_mvp() |
| 368 |
{ |
| 369 |
glm::mat4 model = glm::mat4(1.0f); |
| 370 |
model = glm::rotate(model, glm::radians(m_rotation_angles[0]), glm::vec3(1.0f, 0.0f, 0.0f)); |
| 371 |
model = glm::rotate(model, glm::radians(m_rotation_angles[1]), glm::vec3(0.0f, 1.0f, 0.0f)); |
| 372 |
model = glm::rotate(model, glm::radians(m_rotation_angles[2]), glm::vec3(0.0f, 0.0f, 1.0f)); |
| 373 |
|
| 374 |
glm::mat4 view = glm::lookAt( |
| 375 |
m_camera_position, |
| 376 |
m_camera_target, |
| 377 |
glm::vec3(0.0f, 1.0f, 0.0f) |
| 378 |
); |
| 379 |
|
| 380 |
float view_height = 1.0f * m_camera_position.z; |
| 381 |
float aspect_ratio = (float)get_width() / (float)get_height(); |
| 382 |
float view_width = view_height * aspect_ratio; |
| 383 |
|
| 384 |
glm::mat4 projection = glm::ortho(-view_width / 2.0f, view_width / 2.0f, |
| 385 |
-view_height / 2.0f, view_height / 2.0f, |
| 386 |
0.1f, 100.0f); |
| 387 |
|
| 388 |
return projection * view * model; |
| 389 |
} |
| 390 |
|
| 391 |
void ExampleGLArea::draw_object() |
| 392 |
{ |
| 393 |
if (m_program == 0) return; |
| 394 |
|
| 395 |
glm::mat4 mvp = compute_mvp(); |
| 396 |
|
| 397 |
glUseProgram(m_program); |
| 398 |
glUniformMatrix4fv(m_mvp_location, 1, GL_FALSE, glm::value_ptr(mvp)); |
| 399 |
|
| 400 |
glBindVertexArray(m_vao); |
| 401 |
|
| 402 |
glUniform1i(m_use_vertex_color_location, 1); |
| 403 |
glEnable(GL_CULL_FACE); |
| 404 |
glCullFace(GL_BACK); |
| 405 |
glDepthMask(GL_TRUE); |
| 406 |
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
| 407 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer); |
| 408 |
glDrawElements(GL_TRIANGLES, sizeof(m_default_cube_index_data) / sizeof(GLuint), GL_UNSIGNED_INT, 0); |
| 409 |
|
| 410 |
glDepthMask(GL_FALSE); |
| 411 |
glDisable(GL_CULL_FACE); |
| 412 |
glLineWidth(3.0f); |
| 413 |
glUniform1i(m_use_vertex_color_location, 0); |
| 414 |
glUniform4f(m_line_color_uniform_location, 1.0f, 1.0f, 1.0f, 1.0f); |
| 415 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_edge_index_buffer); |
| 416 |
glDrawElements(GL_LINES, sizeof(m_edge_index_data) / sizeof(GLuint), GL_UNSIGNED_INT, 0); |
| 417 |
|
| 418 |
glDepthMask(GL_TRUE); |
| 419 |
glEnable(GL_CULL_FACE); |
| 420 |
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
| 421 |
|
| 422 |
glBindVertexArray(0); |
| 423 |
glUseProgram(0); |
| 424 |
} |