Quake3World.com Forums
     Programming Discussion
        MD3 c++ opengl loader help


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: MD3 c++ opengl loader help

Recruit
Recruit
Joined: 25 Apr 2012
Posts: 3
PostPosted: 04-25-2012 02:20 AM           Profile Send private message  E-mail  Edit post Reply with quote


Hey guys, Im looking for some help with a MD3 loader im coding with C++,
I have some basic code written, I have the header wirtten and some of the cpp file, at the moment im looking for a website to actually explain how the C++ file to be written, there is enough information about the header file but none about coding/createing the cpp file. I have seen the other post on this forum about a MD3 loader but i have luck in making that one work,

Here is my header file
Code:
#include <GL/glew.h>
#include <GL/gl.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vectormath/scalar/cpp/vectormath_aos.h>

#include "GameAsset.h"

using namespace std;
using namespace Vectormath::Aos;

#ifndef MD3ASSET_H_
#define MD3ASSET_H_

class Md3Asset : public GameAsset{
public:
   Md3Asset();
   Md3Asset(const string &filename);
   virtual ~Md3Asset();

   virtual void update();
private:

   void import_md3_asset(const string &filename);

   struct md3_header
   {
      int ident;
      int version;

      char name[64];

      int flags;

      int num_frames;
      int num_tags;
      int num_surfaces;
      int num_skins;

      int ofs_frames;
      int ofs_tags;
      int ofs_surfaces;
      int ofs_eof;

      struct md3_frame
      {
         Vector3 min_bounds;
         Vector3 max_bounds;
         Vector3 local_origin;
         float radius;
         char name[16];
      };

      struct md3_tag
      {
         char name[64];
         Vector3 origin;
         Vector3 axis[3];
      };

      struct md3_surface
      {
         int ident;

         char name[64];

         int flags;

         int num_frames;
         int num_shaders;
         int num_verts;
         int num_triangles;

         int ofs_triangles;
         int ofs_shaders;
         int ofs_ST;
         int ofs_xyzNormal;
         int ofs_end;

         struct md3_shader
         {
            char name[64];
            int shader_index;
         };
         struct md3_triangle
         {
            int indexes[3];
         };

         struct md3_st
         {
            float st[3];
         };

         struct md3_vertex
         {
            short coord[3];
            short normal;
         };

      };

   };
   //Not sure about this
   typedef float vec3[3];
   //Not sure about this

   md3_header::md3_surface::md3_triangle * triangles;
   md3_header::md3_surface * surfaces;

};
#endif /* MD3ASSET_H_ */


Here is my cpp file code
Code:
#include "Md3Asset.h"

Md3Asset::Md3Asset(const string &filename) {

        import_md3_asset(filename);

   // make the objects to display
   if(0 == make_resources()) {
     cout << "Can't make the required OpenGL resources for Md3Asset." << endl;
     // TODO: exit nicely here
   }

}

Md3Asset::Md3Asset(){}

Md3Asset::~Md3Asset() {
  // TODO: clean up
}

void Md3Asset::update() {
}

void Md3Asset::import_md3_asset(const string &filename) {
   ifstream md3file;
   md3file.open(filename.c_str(), ios::in|ios::binary);

   // C stuff
   md3_header * md3header = (struct md3_header *)
         malloc(sizeof(struct md3_header));
   md3file.read((char*) md3header, sizeof(struct md3_header));
   if((md3header->ident != 860898377)||(md3header->version !=15))
      {
      cout << md3header->version << endl;
      cout << md3header->ident << endl;
         cerr<<"Bad Version or identifier"<<endl;
      }

   // Get the triange data
   this->triangles = (md3_header::md3_surface::md3_triangle*)
         calloc(this->surfaces->num_triangles, sizeof(struct md3_header::md3_surface));

   cout<<triangles<<endl;
}


If anyone has a some source code for the header a cpp file for me to have a look at and get to grips with,

Cheers




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 04-25-2012 03:43 PM           Profile Send private message  E-mail  Edit post Reply with quote


Why don't you copy the MD3 loader from the q3map2 or ioquake3 source code?




Top
                 

Recruit
Recruit
Joined: 25 Apr 2012
Posts: 3
PostPosted: 04-25-2012 04:14 PM           Profile Send private message  E-mail  Edit post Reply with quote


is that in C++ and also where may i find this? i dont want a C# version as i dont really understand C# cmpared to C++ :) could you give me a link if possible




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44140
PostPosted: 04-26-2012 05:53 AM           Profile   Send private message  E-mail  Edit post Reply with quote


I get the impression that you aren't asking for information about how the MD3 format works, but about how one goes about writing a computer progrma in C++.

How experienced are you in the field of programming? How much experience do you have with C++? How much experience do you have with writing 3D renderers, specifically in OpenGL?

I mean, there are probably countless of examples and tutorials about writing an OpenGL renderer. Once you're familiar with that, the specifics you need to know are how to extract the triangle data from an MD3 model. Technically speaking, all you need is a specification of the MD3 file format.

Here's some documentation on that:
http://icculus.org/homepages/phaethon/q ... ormat.html

Not sure how complete or how accurate that is though.




Top
                 

Recruit
Recruit
Joined: 25 Apr 2012
Posts: 3
PostPosted: 04-26-2012 07:00 AM           Profile Send private message  E-mail  Edit post Reply with quote


Ive done C++ for 3 years or so now, but not hardcore as im at university and im learning more then jsut C++ so i cant just sit down and keep at one thing :(, I havent done a renderer for openGL ever but we have been given one to use for us to make a MD3 loader, I have the header but i just cant seem to read the file correctly, every time i try i try and load it i get some random data that isnt correct, Im using a MD3 model that a MD3 C# programer used, so i know its not the model, Im just trying to create a C++ file that will load the MD3 file, extract the surfaces, triangles, tags bla bla bla, nothing else at the moment, i just want to be able to extract the correct data. thats it :)




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.