Hi,
I came across a problem in Galaxy Tab 2 with Android 4.0.4 using Open GL ES 2: it does not draw correctly when using GL_POINTS or GL_LINES, only with GL_TRIANGLES*. The coordinates for the points and lines are computed incorrectly. For example, drawing a line at 0,10 to 0,20 draws nothing.
The code works fine on other Samsung and Sony devices, but fails on the Tab2.
To bypass the problem, when i want to draw a set of pixels, i’m drawing filled rectangles with width/height=1.
However, i’m hitting a performance problem: the performance is now 2x worst, since, for each pixel, i have to draw 4 vertices.
This is the code to draw a filled rectangle, and the code to draw the pixel:
#define LRP_VERTEX_CODE \
"attribute vec4 a_Position;" \
"uniform mat4 projectionMatrix;" \
"void main() {gl_PointSize = 1.0; gl_Position = a_Position*projectionMatrix;}"
#define LRP_FRAGMENT_CODE \
"precision mediump float;" \
"uniform vec4 a_Color;" \
"void main() {gl_FragColor = a_Color;}"
lrpColor = glGetUniformLocation(lrpProgram, "a_Color");
lrpPosition = glGetAttribLocation(lrpProgram, "a_Position"); // get handle to vertex shader's vPosition member
glEnableVertexAttribArray(lrpPosition); // Enable a handle to the vertices - since this is the only one used, keep it enabled all the time
void glDrawPixel(int32 x, int32 y, int32 rgb)
{
glFillRect(x,y,1,1,rgb);
}
void glFillRect(int32 x, int32 y, int32 w, int32 h, int32 rgb)
{
GLfloat* coords = lrcoords;
PixelConv pc;
pc.pixel = rgb;
coords[0] = coords[3] = x;
coords[1] = coords[10] = y;
coords[4] = coords[7] = y+h;
coords[6] = coords[9] = x+w;
setCurrentProgram(lrpProgram);
glUniform4f(lrpColor, f255[pc.r], f255[pc.g], f255[pc.b], 1);
glVertexAttribPointer(lrpPosition, COORDS_PER_VERTEX, GL_FLOAT, GL_FALSE, COORDS_PER_VERTEX * sizeof(float), coords);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, rectOrder);
}
Does anyone knows how can i optimize this situation? I tried to draw 1 triangle to draw the single point, but i’m unable to get it working. Any clues on this?
thanks
guich