http://blog.csdn.net/yexiaozi_007/article/details/7978620

以画xyz坐标轴为例,很多人会遇到用glcolor设置了颜色,但是直线画出来还是黑色或者白色的情况,这可能是因为没有打开GL_COLOR_MATERIAL,或者没有关闭GL_TEXTURE_2D

  1. glEnable(GL_DEPTH_TEST);
  2. glLineWidth(3.0f);
  3. glEnable(GL_COLOR_MATERIAL);
  4. float axes_length = 0.2;
  5. glEnableClientState(GL_VERTEX_ARRAY);
  6. glColor4f(1.0, 0, 0, 1);
  7. float linevertexs_x[6] = {0,0,0,axes_length,0,0};
  8. glVertexPointer(3,GL_FLOAT,0, linevertexs_x);
  9. glDrawArrays(GL_LINES,0, 2);
  10. glColor4f(0, 1.0, 0, 1);
  11. float linevertexs_y[6] = {0,0,0,0,axes_length,0};
  12. glVertexPointer(3,GL_FLOAT,0, linevertexs_y);
  13. glDrawArrays(GL_LINES,0, 2);
  14. glColor4f(0, 0, 1.0, 1);
  15. float linevertexs_z[6] = {0,0,0,0,0,axes_length};
  16. glVertexPointer(3,GL_FLOAT,0, linevertexs_z);
  17. glDrawArrays(GL_LINES,0, 2);
  18. //glColor4f(1, 1, 1, 1);
  19. glDisableClientState(GL_VERTEX_ARRAY);
  20. glDisable(GL_COLOR_MATERIAL);
05-17 03:33