Lab 02
Lab 02
The PyOpenGL module consists of a number of functions, which can be imported with a single line:
This line imports the OpenGL functions, which begin with gl, for example, glVertex. This is all you need to start using OpenGL,
but you may also want to import the OpenGL Utility library (GLU), which contains a number of convert functions that simplify
some common tasks. This line imports the GLU functions, which begin with glu:
SAMPLE CODE
"""
"FreeGLUT Points Demo
"Written by Senay W., Dec 2016
"
"Set up a GLUT window and draws some points and Lines…… in it
"
"""
p1 = (200, 100)
p2 = (50, 0)
p3 = (100, 200)
p4 = (150, 0)
p5 = (0, 100)
def displayLines():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_LINES)
glVertex2f(100.0, 200.0)
glVertex2f(150.0, 200.0)
glVertex2f(150.0, 250.0)
glVertex2f(200.0, 250.0)
glEnd()
glFlush()
def displayLineStrip():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_LINE_STRIP)
glVertex2fv(p1) glVertex2fv(p2)
glVertex2fv(p3) glVertex2fv(p4)
glVertex2fv(p5) glEnd() glFlush()
def displayStar():
glClear(GL_COLOR_BUFFER_BIT)
glBegin(GL_LINE_LOOP) glVertex2f(p1[0], p1[1])
glVertex2f(p2[0],p2[1]) glVertex2f(p3[0],p3[1])
glVertex2f(p4[0],p4[1]) glVertex2f(p5[0],p5[1]) glEnd()
glFlush()
""" Program entry point """
Exercise
1.Study and Experiment DDA line drawing algorithm using graphics.py?
2.Study and Experiment Brenham’s Line drawing algorithm using graphics.py?