mb = [ 1.0, 1.0, 1.0, 1.0 ]
diff= [ 1.0, 1.0, 1.0, 1.0 ]
spec= [ 1.0, 1.0, 1.0, 1.0 ]
lightpos= [ 2.0, 5.0, 5.0, 1.0 ]
shiny = 4.0
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb)
glLightfv(GL_LIGHT0, GL_AMBIENT, amb)
glLightfv(GL_LIGHT0, GL_DIFFUSE, diff)
glLightfv(GL_LIGHT0, GL_SPECULAR, spec)
glLightfv(GL_LIGHT0, GL_POSITION, lightpos)
#glLightf(GL_LIGHT0, GL_SHININESS, 4.0)
glEnable(GL_LIGHT0)
# Turn on lighting. You can turn it off with a similar call to
# glDisable().
glEnable(GL_LIGHTING)
#
# Sets the OpenGL material state. This is remembered so we only need to
# do this once. If you want to use different materials, you'd need to do this
# before every different one you wanted to use.
def initMaterial():
emit = [0.0, 0.0, 0.0, 1.0]
amb = [0.0, 0.0, 0.0, 1.0]
diff = [0.0, 0.0, 1.0, 1.0]
spec = [1.0, 1.0, 1.0, 1.0]
shiny = 20.0
glMaterialfv(GL_FRONT, GL_AMBIENT, amb)
glMaterialfv(GL_FRONT, GL_DIFFUSE, diff)
glMaterialfv(GL_FRONT, GL_SPECULAR, spec)
glMaterialfv(GL_FRONT, GL_EMISSION, emit)
glMaterialfv(GL_FRONT, GL_SHININESS, shiny)
#
# Set up OpenGL state. This does everything so when we draw we only need to
# actually draw the sphere, and OpenGL remembers all of our other settings.
#
def initGL():
# Tell openGL to use gauraud shading:
glShadeModel(GL_SMOOTH)
# Enable back-face culling
glEnable(GL_CULL_FACE)
glCullFace(GL_BACK)
# Enable depth-buffer test
glEnable(GL_DEPTH_TEST)
# Set up projection and modelview matrices ("camera" settings)
# Look up these functions to see what they're doing.
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glFrustum(-0.5, 0.5, -0.5, 0.5, 1, 10)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(5, 5, 5, 0, 0, 0, 1, 0, 0)
# set light parameters
initLights()
# set material parameters
initMaterial()
# initialize the "quadric" used by GLU to render high-level objects.
#/**
# * Main entrance point, obviously.
# * Sets up some stuff then passes control to glutMainLoop() which never
# * returns.
# */
def main():
# OpenGL will take out any arguments intended for its use here.
# Useful ones are -display and -gldebug.
glutInit(sys.argv)
# Get a double-buffered, depth-buffer-enabled window, with an
# alpha channel.
# These options aren't really necessary but are here for examples.
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowSize(500, 500)
glutInitWindowPosition(300, 100)
glutCreateWindow("CS171 HW0")
initGL()
# set up GLUT callbacks.
glutDisplayFunc(redraw)
glutReshapeFunc(resize)
glutKeyboardFunc(keyfunc)
# From here on, GLUT has control,
glutMainLoop()
# so we should never get to this point.
return 1