Texture coordinates in opengl android show reverse image

I wrote an Android android code to show a bitmap in a square. But the bitmap was reversed. When I change the texture array combination to commented code, it is drawn correctly. But I insist that my texture array is as shown below. I think wrong?

/** The initial vertex definition */ private float vertices[] = { -1.0f, 1.0f, 0.0f, //Top Left -1.0f, -1.0f, 0.0f, //Bottom Left 1.0f, -1.0f, 0.0f, //Bottom Right 1.0f, 1.0f, 0.0f //Top Right }; /** Our texture pointer */ private int[] textures = new int[1]; /** The initial texture coordinates (u, v) */ private float texture[] = { //Mapping coordinates for the vertices // 1.0f, 0.0f, // 1.0f, 1.0f, // 0.0f, 1.0f, // 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, }; /** The initial indices definition */ private byte indices[] = { //2 triangles 0,1,2, 2,3,0, }; 
+4
source share
3 answers

While Android uses the top left corner as the 0.0 coordinate system, OpenGL uses the bottom left corner as 0.0, so your texture is upside down.

A common solution for this is to flip the texture at boot time,

 Matrix flip = new Matrix(); flip.postScale(1f, -1f); Bitmap bmp = Bitmap.createBitmap(resource, 0, 0, resource.getWidth(), resource.getHeight(), flip, true); 
+5
source

Actually, I think the Will Kru solution was to flip the background around both axes

 flip.postScale(-1f, -1f); 

This solution worked for me!

0
source

It worked for me. (no need to create another bitmap and scale)

  private float vertices[] = { 1.0f, -1.0f, 0.0f, //Bottom Right 1.0f, 1.0f, 0.0f, //Top Right -1.0f, 1.0f, 0.0f, //Top Left -1.0f, -1.0f, 0.0f, //Bottom Left }; 
0
source

Source: https://habr.com/ru/post/1333184/


All Articles