我使用NDK在Android上使用库GLESv1_CM渲染简单场景。
void render(Rect viewport)
{
glViewport(viewport.left, viewport.top, viewport.Width(), viewport.Height());
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(viewport.left, viewport.right, viewport.top, viewport.bottom, -1, 1);
GLfloat points[] = { 5, 50, 1, 1, 1, 1,
7, 50, 1, 1, 1, 1,
7, 50, 1, 0, 0, 1,
7, 52, 1, 0, 0, 1,
8, 50, 0, 1, 0, 1,
10, 50, 0, 1, 0, 1};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(2,GL_FLOAT,sizeof(GLfloat)*6,&points);
glColorPointer(4,GL_FLOAT,sizeof(GLfloat)*6,&points[2]);
glDrawArrays(GL_LINES,0,6);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
我希望有3条交叉线,但是当我在装有android 2.2或3.2的设备上运行时,我有这个:
更多的是,在安装了Android 4的Android模拟器上(更新:在2.3模拟器上相同)我有这个:
在不使用opengl2的情况下,是否可以在所有Android版本的设备上使其显示在此图片上?
谢谢
答案 0 :(得分:1)
根据the OpenGL FAQ这类预测:
如果需要精确的像素化,您可能需要放一小块 在ModelView矩阵中进行转换,如下所示:
glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glTranslatef (0.375, 0.375, 0.);
我想这会降低四舍五入问题的可能性。