Hi,
I'm trying to figure out how I can keep the aspect ratio of my rendered objects constant, without distorting labels / text in my scene. In my 'on_resize()' function I call 'label.begin_update()' and 'label.end_update()', assuming that these calls will prevent the label from getting scaled. However this does not work - I'm probably doing something wrong here.
Does anybody have a suggestion on how to preserve the text / label? I'm using pyglet 1.1.4.
thanks!
andreas
import pyglet
class myWindow(pyglet.window.Window):
def __init__(self, *args, **kwargs):
pyglet.window.Window.__init__(self, *args, **kwargs)
def setup(self):
self.labels = []
self.labels.append(pyglet.text.Label(
"""dummy text""",
font_size=12,
x=130, y=130, anchor_x = 'left', anchor_y = 'center'))
glClearColor(0, 0, 0, 1.0)
glPointSize(5)
def draw_square(self):
glLineWidth(1)
glBegin(GL_LINE_LOOP)
glVertex2f(100, 100)
glVertex2f(400, 100)
glVertex2f(400, 400)
glVertex2f(100, 400)
glEnd()
def on_draw(self):
glEnable(GL_NORMALIZE)
glPushMatrix()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
# draw the square and the text label
self.draw_square()
for label in self.labels:
label.draw()
glPopMatrix()
def on_resize(self, w, h):
# set viewport to new view dimensions but don't scale text labels
for label in self.labels:
label.begin_update()
glViewport(0, 0, w, h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, W, 0, H, -1.0, 1.0)
glMatrixMode(GL_MODELVIEW)
for label in self.labels:
label.end_update()
if __name__ == "__main__":
H = 600
W = 500
my_win = myWindow(width=W, height=H, resizable=True)
my_win.setup()
pyglet.app.run()