OpenGL Programming/Basics/LinesPoints

From Wikibooks, open books for an open world
Jump to: navigation, search

Drawing points[edit]

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[edit]

/* 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[edit]

/* 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[edit]

/* 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();