[Python] How to render a texture with pygame (or another program) from an str with a letter...

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    So hello, I want to generate a texture from a string with a letter. I am trying to generate this texture from pygame's font, and from what i have understood, it is how you are supposed to do it, but it doesn't work...

    here is the texture rendering code:

    def get_texture_letter(self,path):
    texture = self.drawText(path)
    texture = pg.transform.flip(texture, flip_x = True, flip_y = False)
    texture = self.ctx.texture(size = texture.get_size(), components=3,
    data = pg.image.tostring(texture, 'RGB'))
    return texture

    def drawText(self, text):
    textSurface = self.app.font.render(text, True, (255, 255, 66, 255)).convert_alpha()
    return textSurface


    and i call it like that:

    tex = self.get_texture_letter(path='O')


    I don't undertand why (the rendering is working with texture like png files) but not when i use the texture generated from this.

    It just generates a fully yellow texture.

    Am I generating it in a wrong way?

    Have a nice day!

    Continue reading...

Compartilhe esta Página