Python
[Pygame] PyOpenGL 파이게임
J-sean
2023. 9. 11. 23:09
반응형
파이게임과 PyOpenGL을 연동해 보자.
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 Cube():
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(verticies[vertex])
glEnd()
def main():
pygame.init()
display = (640,480)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
clock = pygame.time.Clock()
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
glRotatef(1, 3, 1, 2)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
Cube()
pygame.display.flip()
clock.tick(30)
if __name__ == '__main__':
main()
|
※ 참고
반응형