0

I have a png file with different sprites , in opengl 1. I have selected the picture with:

// the png dimensions are 512x512

gl.glMatrixMode(GL10.GL_TEXTURE);

// x and y are the coordinates of the selected drawing

gl.glTranslatef(x/512f, y/512f, 0);

// w and h are the width and

height of the selected drawing

gl.glScalef(w/512f, h/512f, 0);

I have no idea in opengl2 , i read this tutorial:

http://www.learnopengles.com/android-lesson-four-introducing-basic-texturing/

it is not difficult ,but you can only change the values of w and h (equivalent of

gl.glScalef(w/512f, h/512f, 0);

)

Do any other tutorial or solution?

Cherry
  • 393
  • 1
  • 4
  • 15
james_sp
  • 1
  • 4

1 Answers1

0

So a tutorial you've read is what you need. Read previous tutorials from that website. The main difference in gles2 from gles1 is that all drawing happens inside shaders(fragment and vertex). Here is a part of texture bounding from my code and fragment shader source.

GLuint textureId;
// Generate a texture object
glGenTextures ( 1, textureId );
// Bind the texture object
glBindTexture ( GL_TEXTURE_2D, textureId );
/ Load the texture
glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, where_you_store_unpacked_texture_data );

// Set the filtering mode
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );

// Bind the texture
glActiveTexture ( GL_TEXTURE0 );
glBindTexture ( GL_TEXTURE_2D, textureId );

Then after you have bound a texture, you can pass its id into fragment shader.

Fragment shader is something like this:

const char* pszFragShader_text = "\
        precision mediump float;\
        \
        varying       vec3  v_texCoord_text;\
        uniform  sampler2D  s_texture_text;\
        void main (void)\
        {\
            gl_FragColor = texture2D( s_texture_text, v_texCoord_text.xy );\
        }";