Results 1 to 10 of 39

Thread: OpenGL GLSL - Text rendering query

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by Chebmaster View Post
    DON'T.
    I beg you, stop and rethink your strategy.
    I think it's way better to encourage people in what they are doing than to offer alternatives because there is some other/better/advanced/optimal/fancy/cross-platfrom/new ideology/etc... way, unless they ask.

    At least I myself end up feeling demotivated if there are too many alternate approaches, to know which one is best would require learning about all of them, and that is too much new stuff in one go.

  2. #2
    so I don't have a clue where to start looking in that class.
    procedure TDumbUniMesh.Render; gives the rough idea of which (still sub-optimal but much better) approach could be used.
    Ideally, there should be a community library for beginners to use instead of the accursed glBegin -- I shall see if I could adapt my DumbUniMesh into a standalone library.


    any advice on the question regarding shaders?
    It would be hard it what is shown is your current level.
    First, you want to pass *two* colors to the shader. This is easily done *but* is, as far as I know, incompatible with the ancient "glColorXX" way of passing the data to the GPU.

    So in addition to learning how to create shaders and bind input parameters to them (not that hard, but full of details rarely explained satisfactorily), you still *have* to learn a more modern method of passing parameters to the video card (I may be missing something here -- my knowledge was gained through much trial and error).

    I'd give my examples, but my code is heavily diffused into abstraction classes and exception wrappers.

    For now, have you tried simply doing it in two passes? One untextured quad for the background, then another glColor() and another, now textured, quad for the character. Yes, it's double overdraw. But it would work.

  3. #3
    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?

  4. #4
    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 ::

  5. #5
    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
  •