0
\$\begingroup\$

I cannot seem to understand how texture coordinates work. I try to render a texture into two triangles and this is what I get

enter image description here

Where the expected output is a normal continuous image as you can imagine.

Triangles coordinates (where w = 1080, h = 1920):

0, 0, w, 0, 0, h,
w, 0, 0, h, w, h

Texture coordinates

0, 1, 1, 1, 0, 0,
1, 1, 1, 0, 0, 0

Texture parameters

gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
\$\endgroup\$
  • \$\begingroup\$ The fact that the moon/planet doesn't look spherical to me seems to suggest that you might have perspective correct texturing turned on but haven't set the "W" (and I don't mean your width value) set correctly. \$\endgroup\$ – Simon F Jun 7 '18 at 10:40
  • \$\begingroup\$ @SimonF updated the question adding used texture parameters. I tried using REPEAT instead of CLAMP_TO_EDGE but this hasn't changed the output. \$\endgroup\$ – Yaroslav Mytkalyk Jun 7 '18 at 11:40
1
\$\begingroup\$

Take a piece of paper and draw your 2 triangles vertices coords and uv coords. They seem to be misplaced (e.g. 0,h corresponds one time to 0,0 and other time to 1,0)


For such cases I could also recommend to use textures with clearly defined characteristics, e.g. a checkerboard with marked uv coords:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Thanks, your answer made me think in a right direction and google the UV picture again. Now I get it. The correct sequence for my scenario is 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0. \$\endgroup\$ – Yaroslav Mytkalyk Jun 7 '18 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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