1

Im loading a bitmap into the renderer class and I want to render the texture centered in the screen with the right ratio and as big as it can be

The vertices and texture data:

private final float[] mVerticesData = { -1f, 1f, 0.0f, // Position 0 0.0f, 0.0f, // TexCoord 0 -1f, -1f, 0.0f, // Position 1 0.0f, 1.0f, // TexCoord 1 1f, -1f, 0.0f, // Position 2 1.0f, 1.0f, // TexCoord 2 1f, 1f, 0.0f, // Position 3 1.0f, 0.0f // TexCoord 3 };

private final short[] mIndicesData = { 0, 1, 2, 0, 2, 3 }; 

And the draw method :

public void onDrawFrame(GL10 glUnused) {

 // Set the viewport GLES20.glViewport(0, 0, bitmap.width, bitmap.height); // Clear the color buffer GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // Use the program object GLES20.glUseProgram(mProgramObject); // Load the vertex position mVertices.position(0); GLES20.glVertexAttribPointer ( mPositionLoc, 3, GLES20.GL_FLOAT, false, 5 * 4, mVertices ); // Load the texture coordinate mVertices.position(3); GLES20.glVertexAttribPointer ( mTexCoordLoc, 2, GLES20.GL_FLOAT, false, 5 * 4, mVertices ); GLES20.glEnableVertexAttribArray ( mPositionLoc ); GLES20.glEnableVertexAttribArray ( mTexCoordLoc ); // Bind the texture GLES20.glActiveTexture ( GLES20.GL_TEXTURE0 ); GLES20.glBindTexture ( GLES20.GL_TEXTURE_2D, mTextureId ); // Set the sampler texture unit to 0 GLES20.glUniform1i ( mSamplerLoc, 0 ); GLES20.glDrawElements ( GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, mIndices ); } 

Right now Im setting the viewport with the bitmap dimensions(not working). How should I calculate the viewport dimensions for the texture to fit the screen keeping the ratio?

thank you.

1 Answer 1

0

May be you should use ModelViewPrjoection matrix. Look at this source http://code.google.com/p/android-opengles-samples-for-vikulov-blogspot-com/source/browse/trunk/OpenglTemplate/src/com/vikulov/opengl/MyGLRenderer.java

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.