From de540de9aa321989eff17953d6e5ae84595f1526 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 22 Jun 2018 15:11:04 +0200 Subject: [PATCH] 5th Attempt to fix texture rendering on OpenGL 1.1 cards --- xs/src/slic3r/GUI/GLCanvas3D.cpp | 3 ++- xs/src/slic3r/GUI/GLGizmo.cpp | 2 +- xs/src/slic3r/GUI/GLGizmo.hpp | 2 +- xs/src/slic3r/GUI/GLTexture.cpp | 28 +++++++++++++++++++++++----- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 7dadfba03..40da7551e 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -1417,7 +1417,7 @@ void GLCanvas3D::Gizmos::_render_overlay(const GLCanvas3D& canvas) const for (GizmosMap::const_iterator it = m_gizmos.begin(); it != m_gizmos.end(); ++it) { float tex_size = (float)it->second->get_textures_size() * OverlayTexturesScale * inv_zoom; - GLTexture::render_texture(it->second->get_textures_id(), top_x, top_x + tex_size, top_y - tex_size, top_y); + GLTexture::render_texture(it->second->get_texture_id(), top_x, top_x + tex_size, top_y - tex_size, top_y); top_y -= (tex_size + scaled_gap_y); } } @@ -3592,6 +3592,7 @@ void GLCanvas3D::_render_legend_texture() const float t = (0.5f * (float)cnv_size.get_height()) * inv_zoom; float r = l + (float)w * inv_zoom; float b = t - (float)h * inv_zoom; + GLTexture::render_texture(tex_id, l, r, b, t); ::glPopMatrix(); diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index 4a76b287b..391a22f97 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -92,7 +92,7 @@ void GLGizmoBase::set_state(GLGizmoBase::EState state) m_state = state; } -unsigned int GLGizmoBase::get_textures_id() const +unsigned int GLGizmoBase::get_texture_id() const { return m_textures[m_state].get_id(); } diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index d8a5517c1..5e6eb79c7 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -57,7 +57,7 @@ public: EState get_state() const; void set_state(EState state); - unsigned int get_textures_id() const; + unsigned int get_texture_id() const; int get_textures_size() const; int get_hover_id() const; diff --git a/xs/src/slic3r/GUI/GLTexture.cpp b/xs/src/slic3r/GUI/GLTexture.cpp index 88d949c7b..a1211ff87 100644 --- a/xs/src/slic3r/GUI/GLTexture.cpp +++ b/xs/src/slic3r/GUI/GLTexture.cpp @@ -72,7 +72,6 @@ bool GLTexture::load_from_file(const std::string& filename, bool generate_mipmap } // sends data to gpu - ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); ::glGenTextures(1, &m_id); ::glBindTexture(GL_TEXTURE_2D, m_id); @@ -131,16 +130,35 @@ void GLTexture::render_texture(unsigned int tex_id, float left, float right, flo { ::glEnable(GL_BLEND); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + ::glEnable(GL_TEXTURE_2D); ::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); ::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id); +//############################################################################################################################### + ::glBegin(GL_TRIANGLES); + ::glTexCoord2f(0.0f, 1.0f); ::glVertex2f(left, bottom); + ::glTexCoord2f(1.0f, 1.0f); ::glVertex2f(right, bottom); + ::glTexCoord2f(1.0f, 0.0f); ::glVertex2f(right, top); + + ::glTexCoord2f(1.0f, 0.0f); ::glVertex2f(right, top); + ::glTexCoord2f(0.0f, 0.0f); ::glVertex2f(left, top); + ::glTexCoord2f(0.0f, 1.0f); ::glVertex2f(left, bottom); + +/* ::glBegin(GL_QUADS); - ::glTexCoord2f(0.0f, 1.0f); ::glVertex3f(left, bottom, 0.0f); - ::glTexCoord2f(1.0f, 1.0f); ::glVertex3f(right, bottom, 0.0f); - ::glTexCoord2f(1.0f, 0.0f); ::glVertex3f(right, top, 0.0f); - ::glTexCoord2f(0.0f, 0.0f); ::glVertex3f(left, top, 0.0f); + ::glTexCoord2f(0.0f, 1.0f); ::glVertex2f(left, bottom); + ::glTexCoord2f(1.0f, 1.0f); ::glVertex2f(right, bottom); + ::glTexCoord2f(1.0f, 0.0f); ::glVertex2f(right, top); + ::glTexCoord2f(0.0f, 0.0f); ::glVertex2f(left, top); +*/ + +// ::glTexCoord2f(0.0f, 1.0f); ::glVertex3f(left, bottom, 0.0f); +// ::glTexCoord2f(1.0f, 1.0f); ::glVertex3f(right, bottom, 0.0f); +// ::glTexCoord2f(1.0f, 0.0f); ::glVertex3f(right, top, 0.0f); +// ::glTexCoord2f(0.0f, 0.0f); ::glVertex3f(left, top, 0.0f); +//############################################################################################################################### ::glEnd(); ::glBindTexture(GL_TEXTURE_2D, 0);