void Canvas::DrawTransparentText(int x, int y, const TCHAR *text) { assert(text != nullptr); assert(ValidateUTF8(text)); #ifdef HAVE_GLES assert(offset == OpenGL::translate); #endif if (font == nullptr) return; GLTexture *texture = TextCache::Get(*font, text); if (texture == nullptr) return; PrepareColoredAlphaTexture(text_color); #ifndef USE_GLSL GLEnable scope(GL_TEXTURE_2D); #endif const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); texture->Bind(); texture->Draw(x, y); }
void Canvas::DrawClippedText(int x, int y, unsigned width, unsigned height, const TCHAR *text) { assert(text != nullptr); assert(ValidateUTF8(text)); #ifdef HAVE_GLES assert(offset == OpenGL::translate); #endif if (font == nullptr) return; GLTexture *texture = TextCache::Get(*font, text); if (texture == nullptr) return; if (texture->GetHeight() < height) height = texture->GetHeight(); if (texture->GetWidth() < width) width = texture->GetWidth(); PrepareColoredAlphaTexture(text_color); #ifndef USE_GLSL GLEnable scope(GL_TEXTURE_2D); #endif const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); texture->Bind(); texture->Draw(x, y, width, height, 0, 0, width, height); }
void Canvas::DrawText(int x, int y, const TCHAR *text) { assert(text != nullptr); assert(ValidateUTF8(text)); #ifdef HAVE_GLES assert(offset == OpenGL::translate); #endif if (font == nullptr) return; GLTexture *texture = TextCache::Get(*font, text); if (texture == nullptr) return; if (background_mode == OPAQUE) DrawFilledRectangle(x, y, x + texture->GetWidth(), y + texture->GetHeight(), background_color); PrepareColoredAlphaTexture(text_color); #ifndef USE_GLSL GLEnable scope(GL_TEXTURE_2D); #endif const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); texture->Bind(); texture->Draw(x, y); }
void Canvas::text_transparent(PixelScalar x, PixelScalar y, const TCHAR *text) { assert(text != NULL); assert(ValidateUTF8(text)); #ifdef HAVE_GLES assert(x_offset == OpenGL::translate_x); assert(y_offset == OpenGL::translate_y); #endif if (font == NULL) return; GLTexture *texture = TextCache::Get(font, text); if (texture == NULL) return; GLEnable scope(GL_TEXTURE_2D); texture->Bind(); GLLogicOp logic_op(GL_AND_INVERTED); /* cut out the shape in black */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); texture->Draw(x, y); if (text_color != COLOR_BLACK) { /* draw the text color on top */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); logic_op.set(GL_OR); text_color.Set(); texture->Draw(x, y); } }
void GLSLProgram::SetTexture(const string& name, const GLTexture& pTexture) { if (m_mBindings.find(name) == m_mBindings.end ()) { // find a free texture unit int iUnusedTexUnit = 0; for (texMap::iterator i = m_mBindings.begin();i != m_mBindings.end();++i){ if (i->second <= iUnusedTexUnit) iUnusedTexUnit = i->second+1; } ConnectTextureID(name, iUnusedTexUnit); pTexture.Bind(iUnusedTexUnit); } else { pTexture.Bind(m_mBindings[name]); } }
void Canvas::CopyToTexture(GLTexture &texture, PixelRect src_rc) const { #ifdef HAVE_GLES assert(offset == OpenGL::translate); #endif texture.Bind(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, OpenGL::translate.x + src_rc.left, OpenGL::viewport_size.y - OpenGL::translate.y - src_rc.bottom, src_rc.right - src_rc.left, src_rc.bottom - src_rc.top); }
void Canvas::CopyToTexture(GLTexture &texture, PixelRect src_rc) const { #ifdef HAVE_GLES assert(x_offset == OpenGL::translate_x); assert(y_offset == OpenGL::translate_y); #endif texture.Bind(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, OpenGL::translate_x + src_rc.left, OpenGL::screen_height - OpenGL::translate_y - src_rc.bottom, src_rc.right - src_rc.left, src_rc.bottom - src_rc.top); }
void Canvas::text(PixelScalar x, PixelScalar y, const TCHAR *text) { assert(text != NULL); assert(ValidateUTF8(text)); #ifdef HAVE_GLES assert(x_offset == OpenGL::translate_x); assert(y_offset == OpenGL::translate_y); #endif if (font == NULL) return; GLTexture *texture = TextCache::Get(font, text); if (texture == NULL) return; if (background_mode == OPAQUE) /* draw the opaque background */ DrawFilledRectangle(x, y, x + texture->GetWidth(), y + texture->GetHeight(), background_color); GLEnable scope(GL_TEXTURE_2D); texture->Bind(); GLLogicOp logic_op(GL_AND_INVERTED); if (background_mode != OPAQUE || background_color != COLOR_BLACK) { /* cut out the shape in black */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); texture->Draw(x, y); } if (text_color != COLOR_BLACK) { /* draw the text color on top */ OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); logic_op.set(GL_OR); text_color.Set(); texture->Draw(x, y); } }