Android NDK:OpenGL ES 中的奇怪线条坐标

发布于 2024-12-29 07:09:02 字数 1360 浏览 2 评论 0 原文

我正在使用 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 的设备上运行它时,我有这个:

screen from Android 2.2 device

甚至更多,在 Android 4 的 Android 模拟器上(更新:与 2.3 的模拟器相同)我有这个:

screen from Android 4 emulator

是否可以在不使用 opengl2 的情况下在所有 Android 版本的所有设备上使其看起来像此图片所示?

想要的屏幕

谢谢

I'm rendering simple scene with library GLESv1_CM on Android with NDK.

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);
}

I wish to have 3 crossed lines, but when I run it on device with android 2.2 or 3.2 i have this:

screen from Android 2.2 device

Even more, on Android emulator with Android 4 (update: same on emulator with 2.3) i have this:

screen from Android 4 emulator

Is it possible to make it looks like on this picture on all devices with all Android versions without using opengl2?

wanted screen

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千仐 2025-01-05 07:09:02

根据此类投影的 OpenGL 常见问题解答

如果需要精确的像素化,您可能需要放置一个小的
ModelView矩阵中的平移,如下图:

glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
glTranslatef (0.375, 0.375, 0.);

我想这会减少舍入问题的可能性。

According to the OpenGL FAQ for this type of projection:

If exact pixelization is required, you might want to put a small
translation in the ModelView matrix, as shown below:

glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0.375, 0.375, 0.);

I imagine this reduces the likelihood of rounding issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文