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

wnt8j

Remember this line glutInitWindowSize(640, 480);

X-axis : 640

Y-axis : 480

vertex

Let start by drawing a Line on Screen.

void myDisplay(void)
{
  glClear(GL_COLOR_BUFFER_BIT);

  glBegin(GL_LINE_LOOP);
   glVertex2i(320, 240);
glVertex2i(320,100);

  glEnd();

  glFlush();

}

glClear(GL_COLOR_BUFFER_BIT); clear the screen

In these line we draw our shape and tell the program what we want to draw.

glBegin(GL_LINE_LOOP);

glEnd();

xa

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

glVertex2i(320,240);

To draw other point i assume  X = 320 and y = 100.

glVertex2i(320,100);

Now Run your program to see the line and try to change the line by changing its x and y values.

 

 

 

Advertisements