Sign in to follow this  

C++/openGL MD3 loader help

This topic is 2056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello again, i did already post this but it got deleted for some reason, could i get a message why it was deleted, but anyway, Ive been asked to create a MD3 loader with C++ and openGL, i have got some of the basic done, but still trying to work out the cpp file,

here is the 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_ */
[/CODE]

here is the cpp file
[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;
}
[/CODE]

Ive been following a MD2 loader, but they are quite different so i got stuck, any help would be awesome or even some source code of a MD3 loader in C++ would be cool

Cheers

Share this post


Link to post
Share on other sites
[quote name='Canvas' timestamp='1335348577' post='4934687']
Hello again, i did already post this but it got deleted for some reason, could i get a message why it was deleted, ...
[/quote]
It has not been deleted. It is, at the moment, still on the first page of posts on the same forum. [url="http://www.gamedev.net/topic/623968-c-opengl-md3-loader-help/"]Here[/url] it is. Closing this since the other thread already has an answer.

Share this post


Link to post
Share on other sites

This topic is 2056 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this