我需要在屏幕上显示文字而不丢帧,频率为120 Hz。代码工作正常,直到我放入一些文本(菜单选项),然后它下降到47赫兹。我知道问题是我正在显示的文本量。我想在纹理中编写文本并将其显示为静态图像,但我不知道它是否可行。是吗?如果是这样的话?
我是OpenGl的新手,我开始阅读RED书(第7版),但我仍然试图了解一切是如何运作的。我的代码需要跨平台,只能使用Pyopengl / pyglet。任何帮助/建议将不胜感激。谢谢你的帮助。
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()
答案 0 :(得分:2)
感谢Katzwinkel,我的代码现在以合适的帧速率运行。我只是保留了标签对象,只有在发生变化时才更新它们。