Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: having a problem with fonts and abusive transparency-layers

  1. #1
    Junior Member Newbie Tcll5850's Avatar
    Join Date
    Feb 2014
    Posts
    20

    having a problem with fonts and abusive transparency-layers

    so basically, what I'm doing is taking advantage of depth testing...
    but what happens is the textured display lists for the font's characters don't want to draw correctly:

    they draw as non-textured quads until they're layered, and draw properly when they're supposed to be hidden

    my GUI system is an advanced logic system that only processes and draws what's needed,
    instead of having to go through everything. (the GUI manages itself, basically)
    (yes, that means it uses the CPU)
    ^ I intend to port this to a shader in the next development

    the fonts were just recently added, and the drawing system could be a bit better... (ignoring the drawing data that's hidden)

    anyways... here's the code:
    Code :
        __GL.glEnable(__GL.GL_BLEND)
        for lid in layer: 
            l=layer[lid]
     
            __GL.glEnable(__GL.GL_DEPTH_TEST)
     
            sl=len(l.stack)-1
            #print 'layer[%i]:'%lid
            #print '%i stack layers:'%(sl+1)
            for sid in l.stack: #the hash order shold already order as 0+ (0 being the BG, [-1] the FG)
                #reverse the order (draw FG first at highest point then draw BG(s) behind FG)
                n=sl-sid
     
                d=(n)*.01
                d2=(n+.5)*.01
                sprimitives=l.stack[n].primitives
                sstrings=l.stack[n].strings
     
                #print '    stack[%i] - %i primitives:'%(n,len(sprimitives))
                for spname in sprimitives:
                    #print '        "%s"'%spname
                    p=sprimitives[spname] #localize the primitive for easy reference
                    __GL.glColor4f(p.r,p.g,p.b,p.a)
                    if p.isTri: __GL.glBegin(__GL.GL_TRIANGLES); __GL.glVertex3fv(p.v1+[d]); __GL.glVertex3fv(p.v2+[d]); __GL.glVertex3fv(p.v3+[d]); __GL.glEnd()
                    else: __GL.glBegin(__GL.GL_QUADS); __GL.glVertex3fv(p.v1+[d]); __GL.glVertex3fv(p.v2+[d]); __GL.glVertex3fv(p.v3+[d]); __GL.glVertex3fv(p.v4+[d]); __GL.glEnd()
     
     
                __GL.glEnable(__GL.GL_TEXTURE_2D)
     
                #print '    font[%i] - %i strings:'%(oid,len(strings))
                for ssname in sstrings:
                    #print '        "%s"'%sname
                    s=sstrings[ssname] #localize
                    if s.enabled:
                        __GL.glLoadIdentity()
                        #__GL.glPushMatrix()
                        __GL.glColor4f(s.r,s.g,s.b,s.a)
                        __GL.glTranslatef(s.x,s.y,0.0)
                        __GL.glScalef(s.s,s.s,s.s)
     
                        xpos = 0.0
                        for list,w,h in s.lists:
                            if list!=None:
                                __GL.glTranslatef(xpos,0.0,d2)
                                __GL.glCallList(list)
                            xpos=w+1
                            #print (s.x+xpos,s.y)
                        __GL.glLoadIdentity()
                        #__GL.glPopMatrix()
     
                __GL.glDisable(__GL.GL_TEXTURE_2D)
     
            __GL.glDisable(__GL.GL_DEPTH_TEST)
     
            #print '%i ovarlay/font layers:'%len(l.overlay)
            for oid in l.overlay:
                oprimitives=l.overlay[oid].primitives
                #print '    overlay[%i] - %i primitives:'%(oid,len(oprimitives))
                for opname in oprimitives:
                    #print '        "%s"'%opname
                    p=oprimitives[opname] #localize the primitive for easy reference
                    __GL.glColor4f(p.r,p.g,p.b,p.a)
                    if p.isTri: __GL.glBegin(__GL.GL_TRIANGLES); __GL.glVertex2fv(p.v1); __GL.glVertex2fv(p.v2); __GL.glVertex2fv(p.v3); __GL.glEnd()
                    else: __GL.glBegin(__GL.GL_QUADS); __GL.glVertex2fv(p.v1); __GL.glVertex2fv(p.v2); __GL.glVertex2fv(p.v3); __GL.glVertex2fv(p.v4); __GL.glEnd()
     
     
                __GL.glEnable(__GL.GL_TEXTURE_2D)
     
                ostrings=l.overlay[oid].strings
                #print '    font[%i] - %i strings:'%(oid,len(strings))
                for osname in ostrings:
                    #print '        "%s"'%sname
                    s=ostrings[osname] #localize
                    if s.enabled:
                        __GL.glLoadIdentity()
                        #__GL.glPushMatrix()
                        __GL.glColor4f(s.r,s.g,s.b,s.a)
                        __GL.glTranslatef(s.x,s.y,0.0)
                        __GL.glScalef(s.s,s.s,s.s)
     
                        xpos = 0.0
                        for list,w,h in s.lists:
                            if list!=None:
                                __GL.glTranslatef(xpos,0.0,0.0)
                                __GL.glCallList(list)
                            xpos=w+1
                            #print (s.x+xpos,s.y)
                        __GL.glLoadIdentity()
                        #__GL.glPopMatrix()
     
                __GL.glDisable(__GL.GL_TEXTURE_2D)
     
        #raw_input()
     
        #for debugging: (draw the active HitDefs)
        global showHitDefs,Widgets
        if showHitDefs:
            __GL.glDisable(__GL.GL_BLEND)
            for wname in Widgets:
                W=Widgets[wname]
                HD=W.hitdef
                if HD.enabled:
                    __GL.glLineWidth(1.5)
                    x=HD.x; y=HD.y; X=HD.X; Y=HD.Y
                    __GL.glBegin(__GL.GL_LINE_LOOP)
                    __GL.glColor3f(1 if W.event.hasFocus else 0,1,0) #hitdef will be yellow if focused on
                    __GL.glVertex2f(x,y); __GL.glVertex2f(X,y)
                    __GL.glVertex2f(X,Y); __GL.glVertex2f(x,Y)
                    __GL.glEnd()
                    __GL.glLineWidth(1.0)
    this is just what draws everything...

    if you need the layer classes and initialization info (font display list generation),
    let me know and I'll post it.

    the layer classes are for tracking the polygons (and now text) to be drawn.
    the stack layer is drawn from top to bottom (this abuses transparency with depth testing)
    the overlay layer draws over the stack layer and blends everything normally.

    there used to be a font layer (seen in my previous screenshots of my program),
    but for my 3rd time redoing the fonts system, the fonts got pushed to draw with the polygons.


    why did I go through all this hastle of designing my own manager?
    because the GL feedback buffer needs you to calculate everything twice,
    where my system only needs you to calculate everything once.


    I think I have noticed one thing though...
    notice that overlain text by that one selection box that says "Grid",
    it's supposed to say "Normals"...
    but notice how the "No" doesn't display and the "rm" is slightly cut off by the button?
    (I actually just noticed this)
    that would be an issue with where d2 is used in the code I posted...
    each letter is translated upward by .5 on the Z axis... oops

    I'll post a screenshot when I fix that...
    (just needs a translation before-hand)

    but I'm posting about the black boxes that are supposed to be the characters...
    those should be displaying their textures... >_>

    OT:
    and yes, I follow screen (W,H,D) standards (X,Y,Z) instead of (X,Z,Y) like most people do... (including MineCraft)
    (the Depth buffer, is called the ZBuffer, not the YBuffer... get your facts straight people) lol

  2. #2
    Junior Member Newbie Tcll5850's Avatar
    Join Date
    Feb 2014
    Posts
    20
    I more than called exactly what would happen:


    so... any ideas??

  3. #3
    Junior Member Newbie Tcll5850's Avatar
    Join Date
    Feb 2014
    Posts
    20
    YES I have an idea... and that is that I am an idiot >.<



    ugh... why do I need to ask my questions to figure out my answers... >.<
    why can't I just figure out my answers w/o asking my questions... >.<
    Last edited by Tcll5850; 02-26-2014 at 11:32 AM.

Posting Permissions

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