Good morning!
I was trying to draw two triangle_fan at the same time with OpenGL ES 2.Unfortunately, have been stuck in this problem for a pretty long time,for there’s no such example.
So, can anyone help me out?Really appreciate it!
Good morning!
I was trying to draw two triangle_fan at the same time with OpenGL ES 2.Unfortunately, have been stuck in this problem for a pretty long time,for there’s no such example.
So, can anyone help me out?Really appreciate it!
What do you mean by “same time”? I think all you need to do is draw the two fans and refresh the display.
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, eyeVertice);
glEnableVertexAttribArray(ATTRIB_VERTEX);
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, 1, 0, eyeColors);
glEnableVertexAttribArray(ATTRIB_COLOR);
glUseProgram(program);
glUniform1f(uniforms[UNIFORM_TRANSLATE], (GLfloat)transY);
glDrawArrays(GL_TRIANGLE_FAN, 0, num);
here’s a piece of the code , I try to have it executed twice with different “eyeVertice”, for showing two eyes.But it showed quite strange result.The eyes totally mix up.
Can we have a look at the contents of your eyeVertice array.
Usually for such a thing, you will store the two triangle fans consecutively in the array.
glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, eyeVertice);
This tells me that u r using 2d coordinates are u doing this in screen space? if so also make sure that the ortho graphic projection matrix is setup accordingly so that the geometry may be correctly visible.
(void)makeEyeWithX:(GLfloat)x Y:(GLfloat)y vertice:(GLfloat *)eyeVertices vertexNumber:(GLint)num{
GLfloat xStep = -1.0f / (num - 2);
eyeVertices[0] = x;
eyeVertices[1] = y;
eyeVertices[2] = x;
eyeVertices[3] = y - 0.5f;
eyeVertices[num * 2 - 2] = x;
eyeVertices[num * 2 - 1] = y + 0.5f;
/*
*/
int direction = -1;
for (GLint i=4; i<(num - 1) * 2; i+=2) {
if (eyeVertices[i - 2] + xStep <= -0.5f) {
xStep = -xStep;
direction = -direction;
}
eyeVertices[i] = eyeVertices[i - 2] + xStep;
eyeVertices[i + 1] = direction * sqrt(0.25 - eyeVertices[i] * eyeVertices[i]) + 0.5;
}
}
I use this method to make the eyeVertice.Actually it’s a semicircle.
Can you give me some pieces of code that draw two rectangles line up with each other horizontally with the parameter TRIANGLE_FAN?I need an example to imitate.