In this post we will try to draw some shapes on OpenGL screen . Download source code
Start from the idea of graphs . Think of x and y axis , your screen is build up of X an Y axis
Remember this line glutInitWindowSize(640, 480);
X-axis : 640
Y-axis : 480
Let start by drawing a Line on Screen.
glClear(GL_COLOR_BUFFER_BIT); clear the screen
In these line we draw our shape and tell the program what we want to draw.
Our Screen is in pixels. We have to assume that where we want to draw. In the above fig we draw a point on XY-axis 320x and 240y (center of the screen). Now we know a line consist of two points. To draw a line we have to make another point.
glVertex2i(x, y) This function create a point on screen by giving it x and y values. where you want to draw that point. In the above case we want our point at
To draw other point i assume X = 320 and y = 100.
Now Run your program to see the line and try to change the line by changing its x and y values.