PDA

View Full Version : Missing pixel at rectangle



Mike HML
07-26-2009, 02:30 PM
Hello,

i am using OpenGL ES on Android for 2d rendering in java.
Whenever i am drawing a rectangle using GL_LINE_LOOP, the bottom right corner pixel is missing.
To fix the problem, i've tried to offset the ModelView Matrix by 0.375 as advised in the FAQ.
Unfortunately this has not fixed it, and now i am running out of ideas...
Could you please take a look at the my code below and give me some advise about what causes the disappeared bottom right corner pixel?
Any advice is appreciated!
Thanks,
Mike.





public void onDrawFrame(GL10 gl) {
float xDest = 100.0f;
float yDest = 100.0f;
float height = 50.0f;
float width = 100.0f;

/*
* Create a rectangle
*/
FloatBuffer vertexBuffer;
float[] vertexArray;
vertexArray = new float[4 * 2];
vertexBuffer = FloatBuffer.wrap(vertexArray);

vertexArray[0] = xDest; vertexArray[1] = yDest; // left bottom
vertexArray[2] = xDest; vertexArray[3] = yDest+height; // left top
vertexArray[4] = xDest+width; vertexArray[5] = yDest+height; // right top
vertexArray[6] = xDest+width; vertexArray[7] = yDest; // right bottom

/*
* OpenGL setup
*/
gl.glViewport(0, 0, 480, 320);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluOrtho2D(gl, 0.0f, 480, 0.0f, 320);

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.375f, 0.375f, 0.0f);

gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

/*
* Draw
*/
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

gl.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);

/*
* Restore OpenGL states:
*/
gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY );
gl.glEnable(GL10.GL_TEXTURE_2D);

Log.e("GLERROR:", GLU.gluErrorString(gl.glGetError()));
}

dletozeun
07-26-2009, 02:55 PM
That seems to be a well known problem and someone solved it here (http://factor-language.blogspot.com/2008/11/some-recent-ui-rendering-fixes.html). Look also at the first comment.