Draw Line and shapes on screen OpenGL

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.

void myDisplay(void)

   glVertex2i(320, 240);




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.





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s