0

I have a trouble with understanding mapping of texture in OpenGL ES. For example, i have a little obj-file containing information like this:

  1. v -75 75 -50
  2. v 75 75 -50
  3. v -75 -75 -50
  4. v 75 -75 -50

  5. vt 0 0

  6. vt 0 1
  7. vt 1 1
  8. vt 1 0

  9. f 4/3 3/2 1/1

  10. f 2/4 4/3 1/1

If I use this vts then texture isn't mapping correctly. But If I switch vts like this:

  1. vt 1 0
  2. vt 0 1
  3. vt 1 1
  4. vt 0 0

all start working fine. I tryed to draw this coordinates just to get visual representation of them and get image like this (I inverted y-axis coordinates). http://imgur.com/BRQgKay In first case I see good representation, but it doesn't work, heh. In second case, I see something horrible, but it work. Why it works, I completely cannot understand. Any ideas? Thanks for any help. EDIT: https://i.stack.imgur.com/4YdpM.jpg I added a little explanation of result that I got. We can divide texture by two parts (triangles). In first case, I get this part switched around diagonal. In second case, I get a good mapping according to divided texture, but I cannot understand why it works. Sorry, if my explanation not so clear.

Ilya
  • 13
  • 4
  • The coordinates in the model seem fine. What is the result you get and what is the expected result? Please try to add some details on the issue, not just "texture isn't mapping correctly". – Matic Oblak Jul 14 '14 at 06:44
  • Yes, you are right, I should tgought about it early. I added a little explanation of results that I got. Thanks for yours remark. – Ilya Jul 16 '14 at 13:55

1 Answers1

0

If I take a pencil and paper and try to draw this rectangle all seems fine. I take a coordinate system where X increases to the right and Y increases upwards. Doing so the texture coordinates seem fine as the left upper part is (0,0) and bottom right is (1,1). What bothers me here at first are the Z coordinates. Since they are negative the camera position should be less then Z (< -50) to se it from the front face.

Now again, the model seems fine though it depends on what you are trying to do. But looking at your result where you see the image mirrored both in X and Y (mirrored diagonally) I would start looking for the issue in your matrices. The X mirroring is most likely caused by you looking it in the back: Camera position at (0,0,0) and looking towards the negative Z. The second is most likely caused by inverting the Y coordinate in one of the two possible methods, glOrtho or glFrustum. Since both of this methods take parameters top and bottom it is most common to set bottom larger then top which makes Y coordinate turned downwards.

Please check all of these parameters as this is more of a guess then anything else. You should also consider using culling, using this will not display polygons you are looking in the back so it might help you understand if you are seeing the front or the back of the face.

Note about Y coordinate being swapped: This is not a bug or wrong approach, it is a pretty standard procedure by now. You must understand that most desktop UI elements have the coordinate system so that Y is pointing upwards, mobile devices are first that massively use the inverted system where Y is inverted on UI. That is the reason why (at least in 2D) it is best to use the same coordinate system as the view uses, but all applications creating the model will most likely consider that Y is pointing upwards.

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43
  • Thanks for explanation. Not all is clear for me still, but I'll try to understand this. – Ilya Jul 17 '14 at 22:24
  • What part do you not understand? Take a peace of paper and draw something on it. Then get a light (so you can see through the paper), turn the paper so the drawing is facing away from you and turn it upside-down. The result will be exactly what you claim to see as "incorrectly" drawn object. The point is that looking at the object from an unexpected perspective might seem as if the object is not drawn correctly. – Matic Oblak Jul 18 '14 at 06:42
  • http://imgur.com/BRQgKay There is two images where I tryed to draw vts in OpenGL's coordinate system. In first case, I get texture divided by two triangles with general hypotenuse. In second case, I get the same two triangles but with intersection of its hypotenuses. I cannot understand that fact if we take part of texture designated by vts why case with general hypotenuse (that uses all space of texture) don't work and at the same time case with intersected hypotenuses (don't uses all space of texture) is working correctly? – Ilya Jul 18 '14 at 17:10