小编exi*_*led的帖子

如何使用 PyOpenGL 渲染文本?

我正在学习现代 openGL,目前我在渲染文本方面遇到了麻烦。我正在遵循C++教程,但我正在尝试用 python 实现。

这是我的代码:

from OpenGL.GL import *
from OpenGL.GLU import *

from OpenGL.GL import shaders

import glfw
import freetype
import glm

import numpy as np
from PIL import Image
import math
import time


class CharacterSlot:
    def __init__(self, texture, glyph):
        self.texture = texture
        self.textureSize = (glyph.bitmap.width, glyph.bitmap.rows)

        if isinstance(glyph, freetype.GlyphSlot):
            self.bearing = (glyph.bitmap_left, glyph.bitmap_top)
            self.advance = glyph.advance.x
        elif isinstance(glyph, freetype.BitmapGlyph):
            self.bearing = (glyph.left, glyph.top)
            self.advance = None
        else:
            raise RuntimeError('unknown glyph type')

def _get_rendering_buffer(xpos, ypos, w, h, …
Run Code Online (Sandbox Code Playgroud)

python opengl pyopengl freetype text-rendering

2
推荐指数
1
解决办法
4931
查看次数

标签 统计

freetype ×1

opengl ×1

pyopengl ×1

python ×1

text-rendering ×1