如何在屏幕的0,0,-1 opengl坐标上绘制黑点?

时间:2011-11-10 10:55:26

标签: android opengl-es

实际上我正在绘制一个立方体,我正在检查立方体的旋转问题,但为此我需要在屏幕的0,0,-1 opengl坐标上绘制一个点,我正在使用透视投影,MyGLSurfaceView和android 1.5 opengl es 1.x

如何在屏幕的0,0,-1 opengl坐标上绘制黑点或白点?

1 个答案:

答案 0 :(得分:2)

如果您希望能够直接在窗口空间中绘制,那么最简单的方法是使用单位矩阵临时加载模型视图和投影,并使用您需要的位置绘制GL_POINT。所以这就像是:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

// draw the point here; specifics depending on whether you
// favour VBOs, VBAs, etc

// e.g. (assuming you don't have any client state enabled
// on entry and don't care about leaving the vertex array
// enabled on exit)
GLfloat vertexLocation[] = {0.0f, 0.0f, -1.0f};

glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertexLocation);

glDrawArrays(GL_POINTS, 0, 1);

// end of example to plot a GL_POINT

glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

// and possibly restore yourself to some other matrix mode
// if, atypically, the rest of your code doesn't assume modelview