I've been working on an exporter for a simple file format that I need for a game I'm working on, and I'm having some trouble with coordinates.
The game is based on a modified copy of the cube game engine. I've added a new format for the models, and a great whacking pile of functions to the script language to make it do what I need done. All of that is no problem.
The difficulty is that the coordinates as I export them from Blender don't seem to be the same when I import them into the game - and I don't know if the problem lies on the export side or the import side.
For the Vertex coordinates, I'm having to invert the Y coordinates (-1*y.) If I don't do this, the faces face inwards and the figure is pointed the wrong way. When "looking" at the object in the game, the near side is transparent and you see the far side through it.
The UV coordinates are also driving me batty. For the only half way working model I've got, I have to invert the U component (1-U) for the texture to get where it should be. No other models (I've got three I've made in the course of things) show their textures properly.
If I exchange the U and V coordinates and use the inverse of the V component (1-V,U) then two of the models show more or less correctly - although rotated onto their sides. The third model still doesn't work, though.
The first two are basically disks, and the symmetry lets them look OK even though something is still wrong. The third model is intentionally non-symmetrical, and the textures never match properly no matter what I do.
The thing that really bugs me about this is that none of this twiddling should be neccesary.
I'm taking the data as Blender Python gives it to me, and feeding it back to the OpenGL functions in the same order. The vertexes should be in the same order, so there shouldn't be any trouble with the faces or the normals the OpenGL calculates. I'm certain that I'm using the same number of UV coordinates as I have Vertex coordinates (they're loaded with the same loop) so that shouldn't be a problem.
Blender appears to use (0,0) as the lower left for UV coordinates just as OpenGL does, so that should be fine - except it isn't.
I've tried my script under Blender 2.25 and 2.28a, and both give the same results. I using SuSe Linux 8.2, if that matters.
I've been chasing this for twelve hours straight, and I am stumped. I've been through what OpenGL documents I've got (mostly the .h files and some gleanings from the internet) and through the C code for the Python API in Blender 2.28, and I can't figure out what I'm doing wrong.
Has any one got Blender bat they smack me with?
Many game engines use left-handed geometry while blender uses right-handed geometry i believe.
You can tell OpenGL the facingness of your faces with glFrontFace(GL_CW) (clockwise specification of vertices) or glFrontFace(GL_CCW) (counterclockwise).
The culling of faces that face away from the viewer is controlled by this.
Thanks for the tips folks.
A couple of hours after I posted here, I figured out what was wrong. Blender uses left handed coordinates, and OpenGL wants right handed ones (if you don't specify otherwise.) I reordered the coordinates on export and that fixed that problem.
I decided to flip the faces rather than telling OpenGL to do it because the game engine still supports another file format, and I didn't want to diddle around switching coordinate systems. It is much easier to fix on export than to add a bunch of "IF THEN flip coordinate" crap to the C++ code.
Next is that blender textures use (0,0) for the top left corner and OpenGL uses (0,0) for the lower left corner. Using (U,1-V) fixes that.
Now my models are right side out with their skins on right side up.
Sorry to have been a bother.
Blender use right hand coordinates.
Martin
_________________
Life is what happens to you when you're busy making other plans.
- John Lennon
Look, whoever said that either made a mistake by accident or don't know the defintion of left and right systems correctly. On a right hand system, X x Y = Z. On a left hand system, Y x X = Z
Martin
_________________
Life is what happens to you when you're busy making other plans.
- John Lennon
Sorry. I didn't mean to look like I was trying to argue about it, I just wanted to provide a cite for why I thought blender was left handed.
At any rate, I've been over and over and around and round the whole thing and finally have things working together.