In this Python Opengl Programming i want to show you Drawing Teapot. So in the last article we had a simple introduction to Opengl and also we have talked about installation process. In Python Programming Language. you can see that article from the below link.
Python Opengl Programming Drawing Teapot
We have said that Opengl is an application programming interface also we call call it API which is merely software library for accessing features in graphic hardware and also opengl is designed as streamlined, hardware independent interface that can be implemented on many different types of graphic hardware systems.
So now this is the complete code for Python Opengl Programming Drawing Teapot
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from OpenGL.GLUT import * from OpenGL.GL import * def draw(): glClear(GL_COLOR_BUFFER_BIT) glutWireTeapot(0.5) glFlush() glutInit(sys.argv) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(250, 250) glutInitWindowPosition(100, 100) glutCreateWindow("My Second OpenGL Program") glutDisplayFunc(draw) glutMainLoop() |
OK at the top these are our imports for Opengl in Python
1 2 |
from OpenGL.GLUT import * from OpenGL.GL import * |
So this method is for drawing on Opengl screen and it is called all the time
1 2 3 4 |
def draw(): glClear(GL_COLOR_BUFFER_BIT) glutWireTeapot(0.5) glFlush() |
In the above method this is for clearing of our Opengl window
1 |
glClear(GL_COLOR_BUFFER_BIT) |
And this method is for drawing of our Teapot, it is a built in method in GLUT library and in the argument you need to give the teapot diameter.
1 |
glutWireTeapot(0.5) |
Also when you want to draw something in Opengl window screen you need to call this function.
1 |
glFlush() |
And these are the initialization code for our window
1 2 3 4 5 6 7 |
glutInit(sys.argv) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(250, 250) glutInitWindowPosition(100, 100) glutCreateWindow("My Second OpenGL Program") glutDisplayFunc(draw) glutMainLoop() |
This is the type of Window in Opengl
1 |
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) |
These are the size and position of our window
1 2 |
glutInitWindowSize(250, 250) glutInitWindowPosition(100, 100) |
Run the complete code and this will be the result
Subscribe and Get Free Video Courses & Articles in your Email