[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] pygamefont problem



Hello,

I have a rather old problem that fails to work after upgrading. The
problem is that font-rendering does not work correctly. The result looks
like the a television that lost horizontal sync.

I think I use old code, but I don't know what is wrong. I include a
small programme that works, but displays incorrectly (it is a Q&D cut
from my real programme). Any suggestions, or a pointer to an example I
can use?

Thanks,
F.




#!/usr/bin/env python2.4
# -*- coding: utf8 -*-

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from pygamefont import *

import sys

ESCAPE = '\033'

window = 0
n=0

def InitGL(Width, Height):
    global v,l1
    glShadeModel(GL_SMOOTH)
    glClearColor(0.0, 0.0, 0.0, 0.5)
    glClearDepth(1.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
    glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
    v=PyGameBitmapFont('verdana.ttf',100)
    l1=Line(v)
    l1.build('1')

def ReSizeGLScene(Width, Height):
    if Height == 0:
        Height = 1
    glViewport(0, 0, Width, Height)  
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    
def DrawGLScene():
    global n
    n+=1
    glColor3d(0,1,0)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    glTranslatef (0.0, 0.0, -1.0)
    glRasterPos2f(0,0)
    l1.build(str(n))
    atextLeft( l1, (-0.9,-0.4))
    glutSwapBuffers()
    return True

def keyPressed(*args):
    global window
    # If escape is pressed, kill everything.
    if args[0] == ESCAPE:
        sys.exit ()

def main():
    global window
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
    glutInitWindowSize(300, 100)
    glutInitWindowPosition(0, 0)
    window = glutCreateWindow("OpenGL PyGame font-tester")
    glutDisplayFunc(DrawGLScene)
    glutIdleFunc(DrawGLScene)
    glutReshapeFunc(ReSizeGLScene)
    glutKeyboardFunc(keyPressed)
    InitGL(300, 100)
    glutMainLoop()

print "Hit ESC key to quit."
main()