Пример #1
0
/**
 * Prepare drawing a GL_ALPHA texture with the specified color.
 */
static void
PrepareColoredAlphaTexture(Color color)
{
#ifdef USE_GLSL
  OpenGL::alpha_shader->Use();
  color.Bind();
#else
  color.Bind();

  if (color == COLOR_BLACK) {
    /* GL_ALPHA textures have black RGB - this is easy */

    OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  } else {
    /* use GL_COMBINE to replace the texture color (black) with the
       specified one */
    OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

    /* replace the texture color with the selected text color */
    OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
    OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
    OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

    /* use the texture alpha */
    OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
    OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
    OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
  }
#endif
}
Пример #2
0
void
Canvas::DrawFilledRectangle(int left, int top, int right, int bottom,
                            const Color color)
{
#ifdef USE_GLSL
  OpenGL::solid_shader->Use();
#endif

  color.Bind();

  std::unique_ptr<const GLBlend> blend; 
  if(!color.IsOpaque()) {
      blend = std::make_unique<const GLBlend>(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  }

#ifdef HAVE_GLES
  const RasterPoint vertices[] = {
    { left, top },
    { right, top },
    { left, bottom },
    { right, bottom },
  };

  const ScopeVertexPointer vp(vertices);
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
#else
  glRecti(left, top, right, bottom);
#endif
}
Пример #3
0
  void DrawOutlineRectangle(int left, int top, int right, int bottom,
                            Color color) {
    color.Bind();
#if defined(HAVE_GLES) && !defined(HAVE_GLES2)
    glLineWidthx(1 << 16);
#else
    glLineWidth(1);
#endif

    OutlineRectangleGL(left, top, right, bottom);
  }
Пример #4
0
void
Canvas::DrawHLine(int x1, int x2, int y, Color color)
{
  color.Bind();

  const RasterPoint v[] = {
    { GLvalue(x1), GLvalue(y) },
    { GLvalue(x2), GLvalue(y) },
  };

  const ScopeVertexPointer vp(v);
  glDrawArrays(GL_LINE_STRIP, 0, ARRAY_SIZE(v));
}
Пример #5
0
  void DrawOutlineRectangle(int left, int top, int right, int bottom,
                            Color color) {
    color.Bind();
    const unsigned scaledWidth=Layout::PenWidthPixels(1);
    const unsigned glWidth=scaledWidth > OpenGL::max_linewidth ? OpenGL::max_linewidth : scaledWidth; // GL behavior seems to be undefined otherwise
#if defined(HAVE_GLES) && !defined(HAVE_GLES2)
    glLineWidthx(glWidth << 16);
#else
    glLineWidth(glWidth);
#endif

    OutlineRectangleGL(left, top, right, bottom);
  }
Пример #6
0
void
Canvas::StretchMono(int dest_x, int dest_y,
                    unsigned dest_width, unsigned dest_height,
                    const Bitmap &src,
                    int src_x, int src_y,
                    unsigned src_width, unsigned src_height,
                    Color fg_color, Color bg_color)
{
  /* note that this implementation ignores the background color; it is
     not mandatory, and we can assume that the background is already
     set; it is only being passed to this function because the GDI
     implementation will be faster when erasing the background
     again */

#ifdef USE_GLSL
  OpenGL::alpha_shader->Use();
  fg_color.Bind();
#else
  const GLEnable<GL_TEXTURE_2D> scope;

  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);

  /* replace the texture color with the selected text color */
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

  /* invert texture alpha (our bitmaps have black text on white
     background) */
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
  OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#endif

  const GLBlend blend(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  GLTexture &texture = *src.GetNative();
  texture.Bind();
  texture.Draw(dest_x, dest_y, dest_width, dest_height,
               src_x, src_y, src_width, src_height);
}
Пример #7
0
 /**
  * Configures this brush in the OpenGL context.
  */
 void Bind() const {
     color.Bind();
 }
Пример #8
0
 /**
  * Configure the Pen in the OpenGL context.  Don't forget to call
  * Unbind() when you're done with this Pen.
  */
 void Bind() const {
   color.Bind();
   BindStyle();
 }