2
\$\begingroup\$

I have one texture atlas of which I select the "non-animated textures", I put all vertex and UV coordinates in two array:

vertices = new float[] {
            // background
            0.0f, 1920f, 0.0f, 
            0.0f, 0.0f, 0.0f, 
            1080f, 0.0f, 0.0f, 
            1080f, 1920f, 0.0f, 
            // character
            240f, 760.0f, 0.0f, 
            240f, 14.0f, 0.0f, 
            770f, 14.0f, 0.0f, 
            770f, 760.0f, 0.0f, 
            // object (Will be transformed)
            360f, 800f, 0.0f, 
            360f, 600.0f, 0.0f, 
            500f, 600.0f, 0.0f, 
            500f, 800f, 0.0f,
    };

uv = new float[] {
            // background
            0.50f, 0.25f,
            0.50f, 0.75f,
            1.0f, 0.75f,
            1.0f, 0.25f,
            // character
            0.0f, 0.25f,
            0.0f, 0.75f,
            0.25f, 0.75f,
            0.25f, 0.25f,
            // object
            0.0f, 0.75f,
            0.0f, 1.0f,
            0.25f, 1.0f,
            0.25f, 0.75f
    };

My vertex shader:

uniform mat4 matrix;
attribute vec4 vPosition;
attribute vec2 a_texCoord;
varying vec2 v_texCoord;

void main() {
    gl_Position = matrix * vPosition;
    v_texCoord = a_texCoord;
}

And my fragment shader:

precision mediump float;

varying vec2 v_texCoord;
uniform sampler2D a_texture;

void main() {
    gl_FragColor = texture2D(a_texture, v_texCoord);
}

I don't know how to animate just a part of the arrangements, also I try to create one more texture but when I run the app I only see the last texture.

\$\endgroup\$
2
  • \$\begingroup\$ What do your shaders look like in this case? \$\endgroup\$ Commented Jun 19, 2018 at 3:09
  • \$\begingroup\$ I added my shader above. \$\endgroup\$ Commented Jun 19, 2018 at 3:34

1 Answer 1

2
\$\begingroup\$

So the first thing I notice is that you only have 3 rectangles that you are drawing. This is a very small number and unlikely to tax the GPU. Your best bet may be to simply make 3 separate draw calls. Setting things up to do this in a more complicated way seems needlessly complex.

Second, if you want to use more than 1 texture, you need to sample from more than 1 texture. You are only ever sampling from a single texture in your fragment shader, so that's all you'll see. Again, you could put drawing of all 3 objects into a single shader, but that just makes things more complicated without any benefit. If it were me, I would use the shader you have. I would set the texture unit used to a different texture unit before each draw call. So before each draw call, make a call to glUniform1i(a_texture_location, x) where a_texture_location is the result of glGetUniformLocation("a_texture"); and x is the texture unit where the texture for that object lives (i.e. GL_TEXTURE0, GL_TEXTURE1, etc.).

\$\endgroup\$
1
  • \$\begingroup\$ Thank. Now I can see the last texture but if I transform the array (i.e. rotate) the transformation applies to everything, I suppose just for transform a part I need to have the rectangle that I want to apply the transform in another array, and if I'm not so wrong also I suppose that I need to create another vertex buffer, pass the new vertex data to the shader, and I do not know what else needs to be done. I tried but the app crashes. \$\endgroup\$ Commented Jun 19, 2018 at 7:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.