I have been trying to setup an object loader for OpenGL this morning and have been making some progress, but now I am stuck on what seems to be the final step in getting my setup to work. My main OpenGL program is written in c (shift.c)
and my object loader is written in C++ (loader.cpp)
. I have also written the linker for the two loader.h
based on this SO thread.
I think that I have done something wrong in the translation, because everything I have done so far hasn't worked properly. My files are as followed.
loader.h
#ifndef LOADER_H
#define LOADER_H
#ifdef _cplusplus
class Model_OBJ
{
public:
Model_OBJ();
float* Model_OBJ::calculateNormal(float* coord1,float* coord2,float* coord3 );
int Model_OBJ::Load(char *filename); // Loads the model
void Model_OBJ::Draw(); // Draws the model on the screen
void Model_OBJ::Release(); // Release the model
float* normals; // Stores the normals
float* Faces_Triangles; // Stores the triangles
float* vertexBuffer; // Stores the points which make the object
long TotalConnectedPoints; // Stores the total number of connected verteces
long TotalConnectedTriangles; // Stores the total number of connected triangles
};
#endif /* __cplusplus */
#ifdef _cplusplus
extern "C" {
#endif
struct model_obj;
float* calculateNormal( float *coord1, float *coord2, float *coord3 );
int Load(char* filename);
void Release();
void Draw();
float* normals; // Stores the normals
float* Faces_Triangles; // Stores the triangles
float* vertexBuffer; // Stores the points which make the object
long TotalConnectedPoints; // Stores the total number of connected verteces
long TotalConnectedTriangles; // Stores the total number of connected triangles
#ifdef _cplusplus
}
#endif
#endif /* LOADER_H */
loader.cpp
/*
*
* Demonstrates how to load and display an Wavefront OBJ file.
* Using triangles and normals as static object. No texture mapping.
* http://talkera.org/opengl/
*
* OBJ files must be triangulated!!!
* Non triangulated objects wont work!
* You can use Blender to triangulate
*
*/
#include "loader.h"
// Rest of my includes
class Model_OBJ
{
public:
Model_OBJ();
float* calculateNormal(float* coord1,float* coord2,float* coord3 );
int Load(char *filename); // Loads the model
void Draw(); // Draws the model on the screen
void Release(); // Release the model
float* normals; // Stores the normals
float* Faces_Triangles; // Stores the triangles
float* vertexBuffer; // Stores the points which make the object
long TotalConnectedPoints; // Stores the total number of connected verteces
long TotalConnectedTriangles; // Stores the total number of connected triangles
};
#define POINTS_PER_VERTEX 3
#define TOTAL_FLOATS_IN_TRIANGLE 9
using namespace std;
Model_OBJ::Model_OBJ(){...}
float* Model_OBJ::calculateNormal( float *coord1, float *coord2, float *coord3 ){...}
int Model_OBJ::Load(char* filename){...}
void Model_OBJ::Release(){...}
void Model_OBJ::Draw(){...}
In my shift.c
file. I have been trying to do something like the following. But have yet to be successful.
#include "loader.h"
// Up in variable declarions
struct model_obj *obj1;
int main()
{
obj1.Load("file.obj");
}