enricoturri1966 2023-10-21 12:06:59 +08:00 committed by Noisyfox
parent f6a3421e2a
commit 7e04448b7a
23 changed files with 742 additions and 449 deletions

View file

@ -69,7 +69,7 @@ namespace GUI {
m_state = Off;
}
void GLSelectionRectangle::render(const GLCanvas3D& canvas) const
void GLSelectionRectangle::render(const GLCanvas3D& canvas)
{
if (!is_dragging())
return;
@ -92,11 +92,6 @@ namespace GUI {
float bottom = (float)std::min(start(1), end(1)) * inv_zoom;
glsafe(::glLineWidth(1.5f));
float color[3];
color[0] = 0.00f;
color[1] = 1.00f;
color[2] = 0.38f;
glsafe(::glColor3fv(color));
glsafe(::glDisable(GL_DEPTH_TEST));
@ -112,12 +107,46 @@ namespace GUI {
glsafe(::glLineStipple(4, 0xAAAA));
glsafe(::glEnable(GL_LINE_STIPPLE));
::glBegin(GL_LINE_LOOP);
::glVertex2f((GLfloat)left, (GLfloat)bottom);
::glVertex2f((GLfloat)right, (GLfloat)bottom);
::glVertex2f((GLfloat)right, (GLfloat)top);
::glVertex2f((GLfloat)left, (GLfloat)top);
glsafe(::glEnd());
GLShaderProgram* shader = wxGetApp().get_shader("flat");
if (shader != nullptr) {
shader->start_using();
if (!m_rectangle.is_initialized() || !m_old_start_corner.isApprox(m_start_corner) || !m_old_end_corner.isApprox(m_end_corner)) {
m_old_start_corner = m_start_corner;
m_old_end_corner = m_end_corner;
m_rectangle.reset();
GLModel::InitializationData init_data;
GLModel::InitializationData::Entity entity;
entity.type = GLModel::PrimitiveType::LineLoop;
entity.positions.reserve(4);
entity.positions.emplace_back(left, bottom, 0.0f);
entity.positions.emplace_back(right, bottom, 0.0f);
entity.positions.emplace_back(right, top, 0.0f);
entity.positions.emplace_back(left, top, 0.0f);
entity.normals.reserve(4);
for (size_t j = 0; j < 5; ++j) {
entity.normals.emplace_back(Vec3f::UnitZ());
}
entity.indices.reserve(6);
entity.indices.emplace_back(0);
entity.indices.emplace_back(1);
entity.indices.emplace_back(2);
entity.indices.emplace_back(2);
entity.indices.emplace_back(3);
entity.indices.emplace_back(0);
init_data.entities.emplace_back(entity);
m_rectangle.init_from(init_data);
}
ColorRGBA color(0.0f, 1.0f, 0.38f, 1.0f);
m_rectangle.set_color(-1, color);
m_rectangle.render();
shader->stop_using();
}
glsafe(::glPopAttrib());