PyOpenGL 서피스 만들기

7944 단어 python
#encoding=utf8
from OpenGL.GL import * 
from OpenGL.GLUT import * 

a=0

ctrlPoints=[]
ctrlPoints= [
    [[-0.5,0.5,0],[0.5,0.5,0]],
    [[-0.5,0,0.5],[0.5,0,0.5]],
    [[-0.25,-0.5,0.25],[0.25,-0.5,0.25]]
    ]
ctrlPoints1= [
    [[-0.5,0.5,0],[0.5,0.5,0]],
    [[-0.5,0,0],[0.5,0,0]],
    [[-0.25,-0.5,0],[0.25,-0.5,0]]
    ]
ctrlPoints2= [
    [[-0.5,0.5,0],[-0.5,0.5,0]],
    [[-0.5,0,0],[-0.5,0,0.5]],
    [[-0.25,-0.5,0],[-0.25,-0.5,0.25]]
    ]

ctrlPoints3= [
    [[0.5,0.5,0],[0.5,0.5,0]],
    [[0.5,0,0],[0.5,0,0.5]],
    [[0.25,-0.5,0],[0.25,-0.5,0.25]]
    ]

ctrlPoints4= [
    [[-0.25,-0.5,0.25],[-0.25,-0.5,0]],
    [[0,-0.5,0.25],[0,-0.5,0]],
    [[0.25,-0.5,0.25],[0.25,-0.5,0]]
    ]
xaxis=0.0
yaxis=0.0
zaxis=0.0

def keyboard(key, w, h):
    global xaxis,yaxis,zaxis
    if (key=='x'):
        glRotatef(10, 1, 0, 0)
    if (key=='y'):
        glRotatef(10, 0, 1, 0)
    if (key=='z'):
        glRotatef(10, 0, 0, 1)
def RenderScene():
    glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT)
    glColor3f(0.0, 0.0, 0.0)
    glPushMatrix()

    glEnable(GL_MAP2_VERTEX_3)
    glMap2f(GL_MAP2_VERTEX_3, 0, 10, 0, 10, ctrlPoints)
    glMapGrid2f(10, 0.0, 10.0, 10, 0.0, 10.0)
    glEvalMesh2(GL_FILL, 0, 10, 0, 10)

    glEnable(GL_MAP2_VERTEX_3)
    glMap2f(GL_MAP2_VERTEX_3, 0, 10, 0, 10, ctrlPoints1)
    glMapGrid2f(10, 0.0, 10.0, 10, 0.0, 10.0)
    glEvalMesh2(GL_FILL, 0, 10, 0, 10)

    glEnable(GL_MAP2_VERTEX_3)
    glMap2f(GL_MAP2_VERTEX_3, 0, 10, 0, 10, ctrlPoints2)
    glMapGrid2f(10, 0.0, 10.0, 10, 0.0, 10.0)
    glEvalMesh2(GL_FILL, 0, 10, 0, 10)

    glEnable(GL_MAP2_VERTEX_3)
    glMap2f(GL_MAP2_VERTEX_3, 0, 10, 0, 10, ctrlPoints3)
    glMapGrid2f(10, 0.0, 10.0, 10, 0.0, 10.0)
    glEvalMesh2(GL_FILL, 0, 10, 0, 10)

    glEnable(GL_MAP2_VERTEX_3)
    glMap2f(GL_MAP2_VERTEX_3, 0, 10, 0, 10, ctrlPoints4)
    glMapGrid2f(10, 0.0, 10.0, 10, 0.0, 10.0)
    glEvalMesh2(GL_FILL, 0, 10, 0, 10)


    glFlush()

    glPopMatrix()

    glutSwapBuffers()
glutInit()
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE)
glutInitWindowPosition(100, 100)
glutInitWindowSize(400, 400)
glutCreateWindow("HiddenStrawberry")


mat_ambient= [0.5,0.0,1.0,0.5]
mat_diffuse= [1.0,0.6,1.0,1.0]
mat_specular= [1.0,1.0,1.0,1.0]

light_ambient= [0.1,0.1,0.1,1.0]
light_diffuse= [1.0,1.0,1.0,0.0]
light_specular= [0.5,1.0,1.0,0.0]
light_position= [-2.0,-5.0,-5.0,1.0]

glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient)
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse)
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular)
glMaterialf(GL_FRONT,GL_SHININESS,60.0)
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient)
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse)
glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular)
glLightfv(GL_LIGHT0,GL_POSITION,light_position)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_DEPTH_TEST)
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE)
glEnable(GL_BLEND)
glEnable(GL_AUTO_NORMAL)
glEnable(GL_NORMALIZE)
glFrontFace(GL_CW)
glShadeModel(GL_SMOOTH)
glEnable(GL_LINE_SMOOTH)



glutDisplayFunc(RenderScene)
glutIdleFunc(RenderScene)
glutKeyboardFunc(keyboard)
glutMainLoop()

좋은 웹페이지 즐겨찾기