1
\$\begingroup\$

I created a uv sphere model in Blender, and I'm loading it as an obj into my OpenGL game. I'm attempting to model a 2d image as a texture for this sphere to make the moon, but I've run into this issue.

enter image description here

The moon texture WITH my attempted fix is here: enter image description here

I have looked hard for a solution, and I've found others with similar problems. However, I can't figure out how to implement their solutions. I don't understand what they're trying to say enough to fix it. They mention something about the wrapping of the texture coordinates from 1.0 to 0.0 where the triangles meet.

What is being rendered appears to be the entire correct moon model for 95% of the sphere and then the entire image file rendering between this 0.95 and 1.0.

Any help with understanding this or solving it would be greatly appreciated. I'm loading the obj with the code seen here.

\$\endgroup\$
2
  • \$\begingroup\$ How is this different from your previous question about texture wrapping a sphere? \$\endgroup\$ – Pikalek Mar 22 at 18:19
  • \$\begingroup\$ You will need to "break" the UV along the seam. Duplicate the vertices and map U to one side and U+1 to another side, while keeping the normals the same. \$\endgroup\$ – Kromster Mar 23 at 5:02
0
\$\begingroup\$

It looks like in your code you are trying to fix the seam by resetting the texture coordinates to match up where they join:

addedTextures.put(currentVertexPointer * 2 + 0, tex.x == 0 ? 1 : tex.x);

This creates the problem. One strip of longitude triangles contains texture coordinates that should go from 0 up to slightly above 0, and you've changed them to be from 1 down to slightly above 0. This creates the "entire image file rendering between this 0.95 and 1.0" effect you are seeing.

Remove this code.

You should get a seamless sphere if the texture coordinates on the model vary from 0 to 1 exactly, and the texture parameters have GL_TEXTURE_WRAP_S set to GL_REPEAT (not strictly necessary for this particular model, but useful in general for wrapping textures).

\$\endgroup\$
5
  • \$\begingroup\$ The code you are referring to is my attempted solution that was disabled for the images shown. I will edit the link to show that, sorry. As for it being 1.0 to 0.0, I did that when I noticed that the opposite didn't solve it. Neither did \$\endgroup\$ – TheGamerPlayz Mar 22 at 23:16
  • \$\begingroup\$ I edited the post to better explain the issue. \$\endgroup\$ – TheGamerPlayz Mar 22 at 23:36
  • \$\begingroup\$ No matter what you remove, there still will be a UV 0..1->0 jump somewhere, unless the vertices are split up. \$\endgroup\$ – Kromster Mar 23 at 5:03
  • \$\begingroup\$ I just can't picture what you mean there. Do you mean the texture coords are like [0.99,y], [0.99,y] ->[0.02.y]? And going from the high value to the low value is causing this? \$\endgroup\$ – TheGamerPlayz Mar 23 at 9:35
  • 1
    \$\begingroup\$ @TheGamerPlayz Yes, that's the problem. Good texture coordinates should go from 0.0 to 1.0 around the sphere without ever going back down. \$\endgroup\$ – Kevin Reid Mar 23 at 14:01

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.