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?

4
  • Would you elaborate on what are you trying to achieve, as it is not very clear from your question? Apr 20, 2015 at 12:31
  • Sorry ,I do not understand your question .The problem is very simple , 1 file png with some sprites that I want to draw with opengl2
    – james_sp
    Apr 20, 2015 at 13:28
  • I found the answer here: stackoverflow.com/questions/9609423/…
    – james_sp
    Apr 20, 2015 at 13:51
  • Yes that should be what you wanted. Apr 20, 2015 at 13:57

1 Answer 1

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 );\
        }";
1
  • yes, you're right, I'll complete it a little later. Apr 22, 2015 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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