2

I need to display text on my screen without dropping frames, at 120 Hz. The code is working fine until I put on some text (menu options), then it drops to 47 Hz. I know that the problem is the amount of text I am displaying. I thought about writing the text in texture and display it as a static image, but I don't know if it's possible. Is it? If so how?

I am very new to OpenGl, I started to read the RED book (7th edition), but I am still trying to understand how everything works. My code needs to be cross platform and can use only Pyopengl / pyglet. Any help/ advise would be appreciated. Thanks for your help.

def on_draw(dt):
    left = True
    right = False
    Rval = 0.0/255.0
    Gval = 153.0/255.0
    Bval = 0.0/255.0

    ShapePosition()

    glClear(GL_COLOR_BUFFER_BIT)
    glLoadIdentity()
    DrawChecker(Nbr = 16, Dark = 25.0/255, Light = 75.0/255)

    if ScreenSwap == 1:
        DrawQuestionMark(Rval, Gval, Bval, left)

        # Blue Line
        BlueLine(left)

        # Line to see if we are dropping frame
        DropFrameTest(left)
        pyglet.text.Label('Left', font_name='Times New Roman', font_size=34, x=(window.width*0.753), y= (window.height*0.05), anchor_x='left', anchor_y='center', color = (255, 0, 0, 150)).draw()
        ScreenSwap = 0

    else:     
        DrawQuestionMark(Rval, Gval, Bval, right)

        # Blue Line
        BlueLine(right)

        # Line to see if we are dropping frame
        DropFrameTest(right)
        pyglet.text.Label('Right', font_name='Times New Roman', font_size=34, x=(window.width*0.877), y= (window.height*0.05), anchor_x='left', anchor_y='center', color = (0, 255, 0, 150)).draw()
        ScreenSwap = 1

    fps = math.ceil(pyglet.clock.get_fps())
    labelStr = str(int(fps))+' Hz'
    pyglet.text.Label(labelStr, font_name='Times New Roman', font_size=36, x=(window.width*0.02), y= (window.height*0.05), anchor_x='left', anchor_y='center', color = (250, 250, 250, 150)).draw()    

    if menu:
        for i in range(len(labelSysInfo)): # labelSysInfo is a list of 8 strings of text
            pyglet.text.Label(labelSysInfo[i], font_name='Times New Roman', font_size=18, x=(window.width*0.75) , y= (window.height*0.95)-(i*window.height*0.03), anchor_x='left', anchor_y='center', color = (210, 210, 255, 255)).draw()
4

1 回答 1

2

Thanks to Katzwinkel, my code is now running at a decent frame rate. I simply kept the label objects and updated them only when there was a change.

于 2013-07-22T12:12:17.640 回答