My question is pretty trivial, I believe I am using OpenGL ES 2.0 to draw a simple 2D scene.
I have a background texture that stretches the entire screen and another flower texture (or the neck that I say sprite?), Which is drawn in a specific place on the screen.
So, it’s trivial why I can think about how to do this, I need to call twice glDrawArrays, one with the vertices of the background texture, and the other with the vertices of the flower texture.
Is it correct? if so, does that mean that for 10 colors will I need to call glDrawArrays10 times?
What about mixing? What if I want to mix a flower with a background, I need wallpapers and color pixel colors, and this could be a problem with two draws?
Or can it be done in one draw? if so, how can I create a shader that knows if it is now processing the top of the background texture or the top of the flower texture?
Or can it be done in one draw?
The problem with one draw is that the shader needs to know if the current vertex is a background vertex (which uses the color of the background texture) or a flower vertex (than the color of a flower’s flower), and I don’t know how to do this.
This is how I use one call to draw to draw a background image, stretch the entire screen, and the flower - in the center and a half size.
- (void)renderOnce {
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, backgroundTexture);
glUniform1i(backgroundTextureUniform, 2);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, flowerTexture);
glUniform1i(flowerTextureUniform, 3);
static const GLfloat allVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f,
-0.5f, -0.5f,
0.5f, -0.5f,
-0.5f, 0.5f,
0.5f, 0.5f,
};
static const GLfloat backgroundTextureCoordinates[] = {
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
};
static const GLfloat flowerTextureCoordinates[] = {
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
};
glVertexAttribPointer(positionAttribute, 2, GL_FLOAT, 0, 0, allVertices);
glVertexAttribPointer(backgroundTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, backgroundTextureCoordinates);
glVertexAttribPointer(flowerTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, flowerTextureCoordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}