[Pygame] PyOpenGL Font Rendering 파이게임 폰트 렌더링
Python 2023. 9. 12. 15:52 |반응형
OpenGL 화면에 Pygame 폰트를 렌더링 해 보자.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
verticies = ((1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1),
(1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1))
edges = ((0,1), (0,3), (0,4), (2,1), (2,3), (2,7), (6,3), (6,4),
(6,7), (5,1), (5,4), (5,7))
def drawCube():
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(verticies[vertex])
glEnd()
def drawText(x, y, text):
font = pygame.font.SysFont('arial', 64)
textSurface = font.render(text, True, (125, 125, 125, 255), (255, 255, 0, 255))
textData = pygame.image.tostring(textSurface, "RGBA", True)
glWindowPos2d(x-textSurface.get_width()/2, y-textSurface.get_height()/2)
glDrawPixels(textSurface.get_width(), textSurface.get_height(), GL_RGBA,
GL_UNSIGNED_BYTE, textData)
pygame.init()
clock = pygame.time.Clock()
display = (640, 480)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
drawCube()
drawText(display[0]/2, display[1]/2, "Cube")
pygame.display.flip()
clock.tick(60)
pygame.quit()
exit()
|
이번엔 폰트의 배경이 표시되지 않도록 해 보자.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
verticies = ((1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1),
(1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1))
edges = ((0,1), (0,3), (0,4), (2,1), (2,3), (2,7), (6,3), (6,4),
(6,7), (5,1), (5,4), (5,7))
def drawCube():
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(verticies[vertex])
glEnd()
def drawText(x, y, text):
font = pygame.font.SysFont('arial', 64)
textSurface = font.render(text, True, (125, 125, 125, 255)).convert_alpha()
textData = pygame.image.tostring(textSurface, "RGBA", True)
glWindowPos2d(x-textSurface.get_width()/2, y-textSurface.get_height()/2)
glDrawPixels(textSurface.get_width(), textSurface.get_height(), GL_RGBA,
GL_UNSIGNED_BYTE, textData)
pygame.init()
clock = pygame.time.Clock()
display = (640, 480)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
drawCube()
drawText(display[0]/2, display[1]/2, "Cube")
pygame.display.flip()
clock.tick(60)
pygame.quit()
exit()
|
반응형
'Python' 카테고리의 다른 글
[Pygame] Bouncing Ball 벽에 튕기는 공 만들기 (0) | 2023.09.13 |
---|---|
[Pygame] PyOpenGL Image Rendering 파이게임 이미지 렌더링 (0) | 2023.09.12 |
[Pygame] PyOpenGL 파이게임 (0) | 2023.09.11 |
Python PyOpenGL (0) | 2023.09.11 |
Python Coroutines 파이썬 코루틴 (0) | 2023.09.11 |