Henry Pootle
Henry Pootle

Reputation: 1216

Android NDK: Strange lines coordinates in OpenGL ES

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

Upvotes: 0

Views: 620

Answers (1)

Reuben Scratton
Reuben Scratton

Reputation: 38717

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.

Upvotes: 1

Related Questions