Rendering mechs in OpenGL

General Mech2 related Developments go here. Discussions welcome!

Moderator: Skyfaller

Forum rules
If you are writing a guide please do not post it here! Post in the Dev FAQ section please.
Post Reply
User avatar
Skyfaller
Clan 1st MechWarrior
Clan 1st MechWarrior
Posts: 1017
Joined: Sat Apr 12, 2008 2:58 am
Location: Germany
Contact:

Rendering mechs in OpenGL

Post by Skyfaller »

quota4stupid wrote:
... unfortunately while I can successfully load & decode the data from file, my OpenGL skills are pretty poor so I haven't been able to properly render it yet :-P (Side note: for me, this MW2 project is meant to be a combo of reverse engineering something for the first time AND learning to use OpenGL properly... I'm definately doing better with the former than the later ;-)) I think to properly test this theory I might follow Col Kells lead and go to town on the project file with a hex editor when I've got some time :-D
quota4stupid wrote:I get the basics of OpenGL, but I've never really done anything significant with it (hence why I hoped to use MW2 as a learning experience for it :-))

If you can find your way thru Java, I'm happy to send you the code I wrote for this (the OpenGL portion is a spaghetti mess at this stage, but the extraction code is still pretty clean and commented ;-)) In a nutshell it looks up the TIMBRWLF.BWD in the mercs MW2.PRJ, looks for the first LOD level 0 OBJ record, reads in those OBJ records, loads the MW2_MAP[1-3].BWD and BET1MAP1.BWD files (only paying attention to the BMPJ & BMID records) and then loads the relevant WTB & XEL files.

I'm as close to positive as I can be that I'm loading the data right at this point (the camo & insignia textures that my algorithm loads for the TimbreWolf for example, look to be the right ones (I had the program dump them to disk as PNG files)), but I just can't render it properly with OpenGL at this stage, so I can't get a nice visual confirmation :-P
For rendering mechs correctly, the following things should be considered:
  • Store each limb as a separate object in an object hierarchy. This is called a scene graph, one of the basic computer graphics data structures.
  • You need to get camera settings right.
  • Model transformations between limbs by matrices.
  • Compile as many textures as possible into a larger one to save texture selection operations.
  • In general, try to get along with as few GL calls as possible, if necessary, sort primitives by state.
  • Use glDraw calls rather than glBegin/glEnd.
  • Lighting and shading give important clues to the shape of an object. It is wortwhile to get that correct.
Debugging an OpenGL renderer can take days. MechVM does most of the above correctly, I just need to add texture extraction for MW2.

Sorry, I will not debug your code, but if you post screen shots, I'll take a look. If you feel your code is a mess, clean it up and add comments.

Another way of testing if the extraction went correctly is to export the .WTB in a format readable to current 3D modelling suites like Blender.

If you're more happy about doing reverse engineering, that could be more valuable to me and Kell as well. In trying to render mechs you are duplicating code in MechVM that is licensed under GPL.
Post Reply