跳转到内容

OpenGL 编程/基础/线点

来自维基教科书,开放世界中的开放书籍

请注意,这适用于非常旧版本的 OpenGL。

绘制点

[编辑 | 编辑源代码]
glBegin(GL_POINTS);
  glVertex2f(0.5f, 0.5f); 
  glVertex2f(0.5f, -0.5f); 
  glVertex2f(-0.5f, 0.5f); 
  glVertex2f(-0.5f, -0.5f); 
glEnd();

绘制线

[编辑 | 编辑源代码]
/* 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();

线循环

[编辑 | 编辑源代码]
/* 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();

连接线

[编辑 | 编辑源代码]
/* 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();
华夏公益教科书