< OpenGL Programming < Basics

Note that this is for very outdated versions of OpenGL.

Drawing points

glBegin(GL_POINTS);
  glVertex2f(0.5f, 0.5f); 
  glVertex2f(0.5f, -0.5f); 
  glVertex2f(-0.5f, 0.5f); 
  glVertex2f(-0.5f, -0.5f); 
glEnd();

Drawing lines

/* Draws two horizontal lines */
glBegin(GL_LINES);
  glVertex2f(0.5f, 0.5f); 
  glVertex2f(-0.5f, 0.5f); 
  glVertex2f(-0.5f, -0.5f); 
  glVertex2f(0.5f, -0.5f); 
glEnd();

Loop of lines

/* Draws a square */
glBegin(GL_LINE_LOOP);
  glVertex2f(0.5f, 0.5f); 
  glVertex2f(-0.5f, 0.5f); 
  glVertex2f(-0.5f, -0.5f); 
  glVertex2f(0.5f, -0.5f); 
glEnd();

Connected lines

/* Draws a 'C' */
glBegin(GL_LINE_STRIP);
  glVertex2f(0.5f, 0.5f); 
  glVertex2f(-0.5f, 0.5f); 
  glVertex2f(-0.5f, -0.5f); 
  glVertex2f(0.5f, -0.5f); 
glEnd();
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.