bgl render problems with Wire material

I get a strange problem with drawing stuff using bgl or blf if I have a material using the wire render setting in the GE. It only happens sometimes, seems to depend on when openGL gets around to rendering that material. I’ve been trying all night to fix it and haven’t made any progress. This affects BGUI as well since it draws using bgl (I’ve tested it). If anyone has any ideas as to how to fix it any help would be appreciated~

An example blend is included cleantest.zip (754 KB) :confused:

If you want to try it for yourself: make a scene with one obj, set the material type to wire, and attach the following script to an always sensor.


# open GL stuff
# import stand alone modules
from bgl import *
import blf
from bge import logic as logic
from bge import render as render

scene = logic.getCurrentScene()
cont = logic.getCurrentController()
owner = cont.owner

def init():
    """init function - runs once"""
    # create a new font object, use external ttf file
    font_path = logic.expandPath('//fonts/arial.ttf')
    # store the font indice - to use later
    logic.font_id = blf.load(font_path)
    scene.post_draw.append(write)


def write():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()
    glMatrixMode(GL_PROJECTION)
    glPushMatrix()
    glLoadIdentity()
    gluOrtho2D(0, width, 0, height)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glLoadIdentity()

    # try drawing a blue rectangle with 50% alpha
    glColor4f(0.0,0.0,1.0,0.5) # RGBA
    glRectf(width*0.5,height*0.5,width*0.75,height*0.75)
    
    # BLF drawing routine
    font_id = logic.font_id
    blf.position(font_id, (width * 0.2), (height * 0.3), 0) 
    blf.size(font_id, 50, 72) # size,res
    glColor4f(0.0,1.0,0.0,1.0) # RGBA
    blf.draw(font_id, "some text") 



if not init in owner or owner["init"] == False:
    init()
    owner["init"] = True

Actually Blender only set the render mode but don’t set render mode back on the end of the render loop, to save render time. You only need to set the polygon mode from GL_LINE to GL_FILL before you render your objects.

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

If you want to render a transparent object you need also to set the blending mode. To be sure that the correct blending mode is set.


glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

You should also set the delay to 1 on the delay sensor, to fix the init bug.

Ah thank you, I know almost nothing about openGL programming (That night was actually the first time I had looked at it), I banged my head against it for 6 hrs. >.< I bow to those with greater knowledge. Thanks again, you saved me a lot of work.