Rotate Text

369 views
Skip to first unread message

Martin

unread,
Aug 18, 2008, 3:38:48 PM8/18/08
to pyglet-users
Hi,

I have an application where I want to render a text 90° rotated but it
looks like whatever I try as soon as I add a roatation, the text
disapears completly... I'm sure I miss something obvious, but I can't
figure out what it is.

I found a hint in a different post that I should add my rotation in th
eon_resize event handler, so here is what I came up with:

-----
import pyglet
from pyglet import gl

w = pyglet.window.Window (640, 480)

label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=0, y=0)
@w.event
def on_draw () :
label.draw ()

def on_resize (width, height) :
gl.glViewport(0, 0, width, height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.glOrtho(0, width, 0, height, -1, 1)
#gl.glTranslatef (10, 0, 0)
gl.glMatrixMode(gl.GL_MODELVIEW)
#gl.glRotatef (-90, 1, 0, 0)
#gl.glRotatef (-90, 0, 1, 0)
# end def on_resize
-----

It does not make a difference if I rotate the projection matrix or the
model view matrix, the text disapears in any case.

Any help would be really appreciated

Martin

P.S.: I really like pygelt and hope that you continue all the great
work.

Alex Holkner

unread,
Aug 18, 2008, 7:37:17 PM8/18/08
to pyglet...@googlegroups.com

These rotations are about the origin (bottom-left corner), so that a
ninety degree rotation will rotate the label off the screen. You had
the right idea with glTranslate, you just need to do it after switch
to GL_MODELVIEW, and you need to translate by a larger amount (start
with 30,30,0).

Alex.

stampson

unread,
Aug 18, 2008, 8:09:56 PM8/18/08
to pyglet-users
#!/usr/bin/env python


import pyglet
from pyglet.gl import *

window = pyglet.window.Window()

@window.event
def on_draw():
window.clear()
glLoadIdentity()
label1.draw()
# The rotation occurs around the origin (lower left corner)
# so first we 'move' the origin to the center of the window
# and since the label is anchored in the center of the label,
# the text will seem to rotate around its center.
glTranslatef(window.width // 2, window.height // 2, 0.0)
glRotatef(90.0, 0.0, 0.0, 1.0)
label2.draw()

glLoadIdentity()
glTranslatef(100.0, window.height - 100, 0.0)
glRotatef(45.0, 0.0, 0.0, 1.0)
label3.draw()



label1 = pyglet.text.Label('Not rotated',x=10, y=10)
label2 = pyglet.text.Label('Rotated 90 degrees',anchor_x='center',
anchor_y='center')
label3 = pyglet.text.Label('Rotated 45 degrees',anchor_x='center',
anchor_y='center')

pyglet.app.run()

Martin Glueck

unread,
Aug 19, 2008, 4:10:08 AM8/19/08
to pyglet...@googlegroups.com
Thanks. I knew it was something simple like that...
I'm primary mistake was that I did not really think about which axis I need to rotate. Know that I saw the example which rotates around Z it is clear....

Thanks for the fast help,
Martin
Reply all
Reply to author
Forward
0 new messages