views:

76

answers:

0

I took advice from an answer to another question I asked which led to me using a DPI of 72 to match points to pixels for the text in my game.

The problem is that pyglet is rendering text far too big or far too small. Perhaps it depends on the framebuffer size? I haven't got a clue. Here's my code for rendering fonts:

class Font():
    def __init__(self,font,size):
        self.size = size
        self.font = font
    def return_surface(self,label):
        surface = Surface((label.content_width + 1,label.content_height + 1))
        surface.set_background_alpha(0)
        setup_framebuffer(surface,True)
        label.draw()
        end_framebuffer()
        return surface
    def render(self,text,colour):
        colour = fix_colour(colour)
        label = pyglet.text.Label(text,font_name=self.font,font_size=self.size,color = colour,dpi=72)
        return self.return_surface(label)
    def render_wordwrap(self,text,width,colour,alignment):
        if alignment == 0:
            alignment = 'left'
        elif alignment == 1:
            alignment = 'center'
        else:
            alignment = 'right'
        colour = fix_colour(colour)
        label = pyglet.text.Label(text,font_name=self.font,font_size=self.size,color = colour,width=width,halign=alignment, multiline=True,dpi=72)
        return self.return_surface(label)

setup_framebuffer just takes this "surface" object and binda a framebuffer for the texture ID stored in this object. The surface object is used for storing rendering information as well as the framebuffer and texture IDs:

def setup_framebuffer(surface,flip=False):
#Create texture if not done already
if surface.texture is None:
    create_texture(surface)
#Render child to parent
if surface.frame_buffer is None:
    surface.frame_buffer =  c_uint()
    glGenFramebuffersEXT(1,byref(surface.frame_buffer))
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, surface.frame_buffer)
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, surface.texture, 0)
glPushAttrib(GL_VIEWPORT_BIT)
glViewport(0,0,surface._scale[0],surface._scale[1])
glMatrixMode(GL_PROJECTION)
glLoadIdentity() #Load the projection matrix
if flip:
    gluOrtho2D(0,surface._scale[0],surface._scale[1],0)
else:
    gluOrtho2D(0,surface._scale[0],0,surface._scale[1])


def end_framebuffer():
    glPopAttrib()
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity() #Load the projection matrix
    gluOrtho2D(0,1280,720,0) #Set an orthorgraphic view

I will appreciate help immensely.