diff options
Diffstat (limited to 'xs/src/slic3r/GUI/GLTexture.cpp')
-rw-r--r-- | xs/src/slic3r/GUI/GLTexture.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/xs/src/slic3r/GUI/GLTexture.cpp b/xs/src/slic3r/GUI/GLTexture.cpp index 924920bd8..18c9f5dea 100644 --- a/xs/src/slic3r/GUI/GLTexture.cpp +++ b/xs/src/slic3r/GUI/GLTexture.cpp @@ -72,13 +72,15 @@ 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); - ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()); + ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()); if (generate_mipmaps) { // we manually generate mipmaps because glGenerateMipmap() function is not reliable on all graphics cards - _generate_mipmaps(image); + unsigned int levels_count = _generate_mipmaps(image); + ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1 + levels_count); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } else @@ -127,37 +129,35 @@ const std::string& GLTexture::get_source() const void GLTexture::render_texture(unsigned int tex_id, float left, float right, float bottom, float top) { - ::glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - - ::glDisable(GL_LIGHTING); ::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_QUADS); - ::glTexCoord2d(0.0f, 1.0f); ::glVertex3f(left, bottom, 0.0f); - ::glTexCoord2d(1.0f, 1.0f); ::glVertex3f(right, bottom, 0.0f); - ::glTexCoord2d(1.0f, 0.0f); ::glVertex3f(right, top, 0.0f); - ::glTexCoord2d(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); ::glEnd(); ::glBindTexture(GL_TEXTURE_2D, 0); ::glDisable(GL_TEXTURE_2D); ::glDisable(GL_BLEND); - ::glEnable(GL_LIGHTING); } -void GLTexture::_generate_mipmaps(wxImage& image) +unsigned int GLTexture::_generate_mipmaps(wxImage& image) { int w = image.GetWidth(); int h = image.GetHeight(); GLint level = 0; std::vector<unsigned char> data(w * h * 4, 0); - while ((w > 1) && (h > 1)) + while ((w > 1) || (h > 1)) { ++level; @@ -182,8 +182,10 @@ void GLTexture::_generate_mipmaps(wxImage& image) data[data_id + 3] = (img_alpha != nullptr) ? img_alpha[i] : 255; } - ::glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA8, (GLsizei)w, (GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()); + ::glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, (GLsizei)w, (GLsizei)h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()); } + + return (unsigned int)level; } } // namespace GUI |