Results 1 to 5 of 5

Thread: Moving texture OpenGL ES 2.0

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    5

    Moving texture OpenGL ES 2.0

    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

    Code :
      gl.glMatrixMode(GL10.GL_TEXTURE);
    	    gl.glLoadIdentity();
    	    gl.glPushMatrix();
    	    gl.glTranslatef(0.0f, 0.2f, 0f);
                gl.glPopMatrix();


    This are the matrix that I am using atm

    Code :
      /**
    	 * 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];

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,673
    There is no texture matrix in OpenGL ES 2.0. It doesn't have any of that old stuff. You have to use a shader.

    If you want to offset your texture coordinates by a value, then you pass that value to the shader and offset them. It's much simpler and more obvious what's happening.

    Or, better yet, you could just pass the right texture coordinates to begin with.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    5
    Quote Originally Posted by Alfonse Reinheart View Post
    There is no texture matrix in OpenGL ES 2.0. It doesn't have any of that old stuff. You have to use a shader.

    If you want to offset your texture coordinates by a value, then you pass that value to the shader and offset them. It's much simpler and more obvious what's happening.

    Or, better yet, you could just pass the right texture coordinates to begin with.
    Hi, thanks for the reply I follow your steps and I am nearly get but I cant figure out how to do the last step

    If I change this line in the vertex shader, the texture scale but I want to move not scale!:

    Code :
    v_TexCoordinate = a_TexCoordinate*vec2(1.5,1.5);

    this is my shader
    Code :
    uniform mat4 u_MVPMatrix;       // A constant representing the combined model/view/projection matrix.                  
    uniform mat4 u_MVMatrix;        // A constant representing the combined model/view matrix.              
    uniform mat4 u_TextureMatrix;
     
     
    attribute vec4 a_Position;      // Per-vertex position information we will pass in.                             
    attribute vec3 a_Normal;        // Per-vertex normal information we will pass in.      
    attribute vec2 a_TexCoordinate; // Per-vertex texture coordinate information we will pass in.       
     
    varying vec3 v_Position;        // This will be passed into the fragment shader.                            
    varying vec3 v_Normal;          // This will be passed into the fragment shader.  
    varying vec2 v_TexCoordinate;   // This will be passed into the fragment shader.            
     
    // The entry point for our vertex shader.  
    void main()                                                     
    {                                                         
    // Transform the vertex into eye space.     
        v_Position = vec3(u_MVMatrix * a_Position);                 
     
    // Pass through the texture coordinate.
        v_TexCoordinate = a_TexCoordinate;                                     
     
    // Transform the normal's orientation into eye space.
        v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0));
     
    // gl_Position is a special variable used to store the final position.
    // Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
        gl_Position = u_MVPMatrix * a_Position;                               
    }

    This is my draw call:

    Code :
    private void drawMagia()
    {
        GLES20.glUseProgram(mMagiaProgramHandle);
        mTextureMatrixHandle = GLES20.glGetUniformLocation(mMagiaProgramHandle, "u_TextureMatrix");
        mMagiaTextureCoordinateHandle = GLES20.glGetAttribLocation(mMagiaProgramHandle, "a_TexCoordinate");
     
     
     
        mMagiaPositions.position(0);        
        GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
                0, mMagiaPositions);        
     
        GLES20.glEnableVertexAttribArray(mPositionHandle);        
     
     
        // Pass in the normal information
        mMagiaNormals.position(0);
        GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false, 
                0, mMagiaNormals);
     
        GLES20.glEnableVertexAttribArray(mNormalHandle);
     
        // Pass in the texture coordinate information
        mMagiaTextureCoordinates.position(0);
        GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false, 
                0, mMagiaTextureCoordinates);
     
        GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
     
        // This multiplies the view matrix by the model matrix, and stores the
        // result in the MVP matrix
        // (which currently contains model * view).
        Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
     
        // Pass in the modelview matrix.
        GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
     
        GLES20.glUniformMatrix4fv(mTextureMatrixHandle, 1, false, mTextureMatrix, 0);
     
        // This multiplies the modelview matrix by the projection matrix, and
        // stores the result in the MVP matrix
        // (which now contains model * view * projection).
        Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
     
        // Pass in the combined matrix.
        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
     
        // Pass in the light position in eye space.
        GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
     
     
        // Draw the square.
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
    }

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,673
    the texture scale but I want to move not scale!:

    Code :
    a_TexCoordinate*vec2(1.5,1.5);
    ... Then stop scaling it. Multiplication is a scaling operation. If you want an offset operation, use addition.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    5
    Quote Originally Posted by Alfonse Reinheart View Post
    ... Then stop scaling it. Multiplication is a scaling operation. If you want an offset operation, use addition.
    And how I can use addition there? because If I add a vec2 nothing change
    v_TexCoordinate = a_TexCoordinate+vec2(3.5,3.5);
    maybe I understand it wrong?

Similar Threads

  1. texture not moving OGLES2
    By Johnathon332 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-26-2013, 02:12 PM
  2. Jerky moving texture...
    By Kromagnon in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-27-2013, 08:59 PM
  3. Moving Texture and Stack Order
    By VASIMR in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-30-2011, 02:03 PM
  4. Cropped Moving 2D Texture
    By Gilla in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-21-2010, 02:51 PM
  5. Moving texture?
    By Vince in forum OpenGL ES
    Replies: 0
    Last Post: 09-19-2010, 09:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean