I am trying to implement a sprite of 8 columns and 8 rows in OpenGL ES 2.0
I made appear the first imagen but I cant figure out how to translate the Texture matrix in OpenGL ES 2.0 , the equivalent of the code in OpenGL 1.0 that I am looking is

        gl.glTranslatef(0.0f, 0.2f, 0f);

This are the matrix that I am using atm

 * Store the model matrix. This matrix is used to move models from object space (where each model can be thought
 * of being located at the center of the universe) to world space.
private float[] mModelMatrix = new float[16];

 * Store the view matrix. This can be thought of as our camera. This matrix transforms world space to eye space;
 * it positions things relative to our eye.
private float[] mViewMatrix = new float[16];

/** Store the projection matrix. This is used to project the scene onto a 2D viewport. */
private float[] mProjectionMatrix = new float[16];

/** Allocate storage for the final combined matrix. This will be passed into the shader program. */
private float[] mMVPMatrix = new float[16];

 * Stores a copy of the model matrix specifically for the light position.
private float[] mLightModelMatrix = new float[16];  

Answer by OFE in StackOverFlow:

You will need to perform transformations to the texture co-ordinates yourself, you could do this in one of four places:

-Apply the transformation to your raw model data.

-Apply the transformation in the CPU (not recommended unless you have good reason as this is what vertex shaders are for).

-Apply the transformation in the vertex shader (recommended).

-Apply the transformation in the fragment shader.

If you are going to apply a translation to the texture coordinates the most flexible way will be to use your maths library to create a translation matrix and pass the new matrix to your vertex shader as a uniform (the same way you pass the mMVPMatrix and mLightModelMatrix). You can then multiply the translation matrix by the texture coordinate in the vertex shader and output the result as a varying vector.

Vertex Shader:

 texture_coordinate_varying = texture_matrix_uniform * texture_coordinate_attribute;

Fragment Shader:

 gl_FragColor = texture2D(texture_sampler, texture_coordinate_varying);

Please note: Your GLES 1.0 code does not actually perform a translation as you surrounded it with a push and pop.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.