5th Attempt to fix texture rendering on OpenGL 1.1 cards

This commit is contained in:
Enrico Turri 2018-06-22 15:11:04 +02:00
parent 15c69a90ec
commit de540de9aa
4 changed files with 27 additions and 8 deletions

View File

@ -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) 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; 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); 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 t = (0.5f * (float)cnv_size.get_height()) * inv_zoom;
float r = l + (float)w * inv_zoom; float r = l + (float)w * inv_zoom;
float b = t - (float)h * inv_zoom; float b = t - (float)h * inv_zoom;
GLTexture::render_texture(tex_id, l, r, b, t); GLTexture::render_texture(tex_id, l, r, b, t);
::glPopMatrix(); ::glPopMatrix();

View File

@ -92,7 +92,7 @@ void GLGizmoBase::set_state(GLGizmoBase::EState state)
m_state = 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(); return m_textures[m_state].get_id();
} }

View File

@ -57,7 +57,7 @@ public:
EState get_state() const; EState get_state() const;
void set_state(EState state); void set_state(EState state);
unsigned int get_textures_id() const; unsigned int get_texture_id() const;
int get_textures_size() const; int get_textures_size() const;
int get_hover_id() const; int get_hover_id() const;

View File

@ -72,7 +72,6 @@ bool GLTexture::load_from_file(const std::string& filename, bool generate_mipmap
} }
// sends data to gpu // sends data to gpu
::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
::glGenTextures(1, &m_id); ::glGenTextures(1, &m_id);
::glBindTexture(GL_TEXTURE_2D, 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); ::glEnable(GL_BLEND);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
::glEnable(GL_TEXTURE_2D); ::glEnable(GL_TEXTURE_2D);
::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); ::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id); ::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); ::glBegin(GL_QUADS);
::glTexCoord2f(0.0f, 1.0f); ::glVertex3f(left, bottom, 0.0f); ::glTexCoord2f(0.0f, 1.0f); ::glVertex2f(left, bottom);
::glTexCoord2f(1.0f, 1.0f); ::glVertex3f(right, bottom, 0.0f); ::glTexCoord2f(1.0f, 1.0f); ::glVertex2f(right, bottom);
::glTexCoord2f(1.0f, 0.0f); ::glVertex3f(right, top, 0.0f); ::glTexCoord2f(1.0f, 0.0f); ::glVertex2f(right, top);
::glTexCoord2f(0.0f, 0.0f); ::glVertex3f(left, top, 0.0f); ::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(); ::glEnd();
::glBindTexture(GL_TEXTURE_2D, 0); ::glBindTexture(GL_TEXTURE_2D, 0);