💡 글 작성자는 vscode를 활용하여 Python을 작성하고있습니다.
이전 게시글 : https://donggyu.tistory.com/84
(실행하면 360도 돌아가는 주전자이다.)
from OpenGL.GLUT import *
from OpenGL.GL import *
angle = 0.0
def draw():
glClear(GL_COLOR_BUFFER_BIT)
glClear(GL_DEPTH_BUFFER_BIT)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glEnable(GL_CULL_FACE)
glCullFace(GL_BACK)
glLoadIdentity()
glPushMatrix()
glRotatef(-45.0, 1.0, 0.0, 0.0)
glTranslatef(0.5, 0.0, 0.0)
glRotatef(angle, 0.0, 1.0, 0.0)
glColor3f(1.0, 0.0, 0.0)
glutSolidTeapot(0.3)
glPopMatrix()
glPushMatrix()
glRotatef(0.0, 1.0, 0.0, 0.0)
glTranslatef(-0.5, 0.0, 0.0)
glRotatef(-angle, 0.0, 1.0, 0.0)
glColor3f(0.0, 0.0, 1.0)
glutSolidTeapot(0.3)
glPopMatrix()
glutSwapBuffers()
def mtimer(self):
global angle
angle += 1.0
if angle >= 360.0:
angle = 0.0
print(angle)
glutPostRedisplay()
glutTimerFunc(20, mtimer, 1)
def init_gl():
glShadeModel(GL_SMOOTH)
ambient = [0.25, 0.25, 0.0, 1.0]
diffuse = [0.9, 0.9, 0.0, 1.0]
position = [0.0, 7.0, 0.0, 1.0]
glEnable(GL_LIGHTING)
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient)
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse)
glLightfv(GL_LIGHT0, GL_POSITION, position)
glEnable(GL_LIGHT0)
#print(angle)
glutInit()
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutCreateWindow("OpenGL")
init_gl()
glutDisplayFunc(draw)
glutTimerFunc(20, mtimer, 1)
glutMainLoop()
[Python Singleton Pattern] Database Singleton Pattern 만들기 (0) | 2021.09.27 |
---|---|
[Python Opengl for glfw] Python을 활용하여 glfw로 삼각형 만들기 (0) | 2021.09.11 |
[Python OpenGL] Python을 활용하여 OpenGL로 주전자 만들기 1편 (0) | 2021.09.11 |
[Python MongoDB] Python을 활용하여 MongoDB 연결하기 2편 (0) | 2021.09.05 |
[Python MongoDB] Python을 활용하여 MongoDB 연결하기 1편 (0) | 2021.09.05 |