http://blog.csdn.net/yexiaozi_007/article/details/7978620
以画xyz坐标轴为例,很多人会遇到用glcolor设置了颜色,但是直线画出来还是黑色或者白色的情况,这可能是因为没有打开GL_COLOR_MATERIAL,或者没有关闭GL_TEXTURE_2D
- glEnable(GL_DEPTH_TEST);
- glLineWidth(3.0f);
- glEnable(GL_COLOR_MATERIAL);
- float axes_length = 0.2;
- glEnableClientState(GL_VERTEX_ARRAY);
- glColor4f(1.0, 0, 0, 1);
- float linevertexs_x[6] = {0,0,0,axes_length,0,0};
- glVertexPointer(3,GL_FLOAT,0, linevertexs_x);
- glDrawArrays(GL_LINES,0, 2);
- glColor4f(0, 1.0, 0, 1);
- float linevertexs_y[6] = {0,0,0,0,axes_length,0};
- glVertexPointer(3,GL_FLOAT,0, linevertexs_y);
- glDrawArrays(GL_LINES,0, 2);
- glColor4f(0, 0, 1.0, 1);
- float linevertexs_z[6] = {0,0,0,0,0,axes_length};
- glVertexPointer(3,GL_FLOAT,0, linevertexs_z);
- glDrawArrays(GL_LINES,0, 2);
- //glColor4f(1, 1, 1, 1);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisable(GL_COLOR_MATERIAL);