Results 1 to 10 of 39

Thread: OpenGL GLSL - Text rendering query

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    P.S. And "untextured" coluld be a single texel stretched wide -- I adapted this strategy for my GUI to avoid unnecessary state switches.

    P.P.S. Annoyingly "GL_QUADS" is deprecated and GLES doesn't have it. I went total :rageface: when I tried drawing a textured trapezoid and found that there is no good way except tesselating the tar out of it. What a bummer!
    I had to recreate GL_LINE_STRIP on my own because it does not exist either. There are only triangles. Indexed ones.
    On the plus side I can now use Google's "GL over Direct3d" wrapper -- ain't that neat?

  2. #2
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2
    So my code does do a two pass at present and providing I use glColor4f(1.0,1.0,1.0,1.0); aka Opaque white, the blend works and the alpha is taken into account from the font texture. And everything is great, but when I change the color to say yellow, the blend changes the colour of the background quad. This is why I was looking at shaders.

    Fundamentally I've been able to write a fragment shader to set the colour to a fixed value, but where I'm coming unstuck is if I use a vertex shader to extract the color (which I understand to be an interpolated value, along with the position information), I'm in a position where it breaks the 2D orthographic projection and nothing I've tried has worked. And I've tried quite a few variations of shader.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  3. #3
    You should not use blend, you should use alpha test.

    Code:
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          glEnable(GL_ALPHA_TEST);
          glAlphaFunc(GL_GREATER, 0.01);
    For shaders... I am beginner myself, but look at my FFP emulation for my GUI:
    (please note that I calculate matrix by hand for GLES compatibility where glRotate() and the like do not exist: these are deprecated)

    Code:
    #version 120
    
    uniform mat4 u_matrix;
    
    attribute vec3 a_position;
    attribute vec4 a_color;
    attribute vec2 a_texCoord;
    
    varying vec2 v_texCoord;
    varying vec4 v_color;
    				
    void main()
    {
    	gl_Position = u_matrix * vec4(a_position[0], a_position[1], a_position[2], 1.0); 
    	v_texCoord = a_texCoord;
    	v_color = a_color;
    }
    Code:
    #version 120
    
    uniform sampler2D u_texture;
    
    varying vec2 v_texCoord;
    varying vec4 v_color;
    
    void main()
    {
    	vec4 mytexel = texture2D( u_texture, v_texCoord);
    	if (mytexel[3] < 0.05) {
    		discard;
    	} else {
    		gl_FragColor = v_color * mytexel;
    	}
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •