Compare commits
No commits in common. "master" and "v1.0" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
driver
|
|
11
Makefile
11
Makefile
@ -1,7 +1,10 @@
|
|||||||
export SCONSFLAGS := -Q
|
|
||||||
|
|
||||||
all:
|
TARGET := WFObj.o
|
||||||
@scons
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
%.o: %.cc
|
||||||
|
$(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@scons -c
|
-rm -f *~ *.o
|
||||||
|
18
Makefile.driver
Normal file
18
Makefile.driver
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
CXX := g++
|
||||||
|
CXXFLAGS := -O2
|
||||||
|
SOURCE := WFObj.cc driver.cc
|
||||||
|
OBJS := $(SOURCE:.cc=.o)
|
||||||
|
LDFLAGS := -lGL
|
||||||
|
TARGET := driver
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
$(TARGET): $(OBJS)
|
||||||
|
$(CXX) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
%.o: %.cc %.hh
|
||||||
|
$(CXX) -c -o $@ $< $(CXXFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-rm -f *~ *.o $(TARGET)
|
6
README
6
README
@ -1,5 +1,5 @@
|
|||||||
WFObj version 2.0
|
WFObj version 1.0
|
||||||
Author: Josh Holtrop
|
Author: Josh Holtrop
|
||||||
|
|
||||||
This utility uses OpenGL vertex buffer objects to render an Alias Wavefront
|
This utility uses OpenGL 1.x functionality to render an Alias Wavefront object
|
||||||
object file for efficient repeated rendering.
|
file into a display list for repeated rendering.
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
# vim:filetype=python
|
|
||||||
|
|
||||||
env = Environment(LIBS = ['GL'], CXXFLAGS = ['-Wall', '-DGL_GLEXT_PROTOTYPES'])
|
|
||||||
|
|
||||||
env.Program('driver', Glob('*.cc'))
|
|
164
WFObj.h
164
WFObj.h
@ -2,12 +2,9 @@
|
|||||||
#ifndef WFOBJ_H
|
#ifndef WFOBJ_H
|
||||||
#define WFOBJ_H
|
#define WFOBJ_H
|
||||||
|
|
||||||
#ifdef GL_INCLUDE_FILE
|
#include "FileLoader/FileLoader.h"
|
||||||
#include GL_INCLUDE_FILE
|
#include "TextureLoader/TextureLoader.h"
|
||||||
#else
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
@ -15,124 +12,81 @@
|
|||||||
class WFObj
|
class WFObj
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* types */
|
|
||||||
class Buffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Buffer() : m_alloc(false) {data = NULL; length = 0;}
|
|
||||||
~Buffer() { if (m_alloc) delete data; }
|
|
||||||
uint8_t *data;
|
|
||||||
size_t length;
|
|
||||||
void alloc(size_t sz)
|
|
||||||
{
|
|
||||||
length = sz;
|
|
||||||
data = new uint8_t[sz];
|
|
||||||
m_alloc = true;
|
|
||||||
}
|
|
||||||
protected:
|
|
||||||
bool m_alloc;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Material
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum {
|
|
||||||
SHININESS_BIT = 0x01,
|
|
||||||
AMBIENT_BIT = 0x02,
|
|
||||||
DIFFUSE_BIT = 0x04,
|
|
||||||
SPECULAR_BIT = 0x08,
|
|
||||||
TEXTURE_BIT = 0x10
|
|
||||||
};
|
|
||||||
Material() : flags(0) {}
|
|
||||||
GLfloat shininess;
|
|
||||||
GLfloat ambient[4];
|
|
||||||
GLfloat diffuse[4];
|
|
||||||
GLfloat specular[4];
|
|
||||||
GLuint texture;
|
|
||||||
int flags;
|
|
||||||
int first_vertex;
|
|
||||||
int num_vertices;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef bool (*loadfile_t)(const char *fname, Buffer & buff);
|
|
||||||
typedef GLuint (*loadtexture_t)(const char *fname);
|
|
||||||
|
|
||||||
enum { VERTEX, VERTEX_TEXTURE, VERTEX_NORMAL, VERTEX_TYPES };
|
|
||||||
|
|
||||||
/* constructors */
|
|
||||||
WFObj();
|
WFObj();
|
||||||
|
WFObj(FileLoader & fileLoader);
|
||||||
|
WFObj(TextureLoader & textureLoader);
|
||||||
|
WFObj(FileLoader & fileLoader, TextureLoader & textureLoader);
|
||||||
~WFObj();
|
~WFObj();
|
||||||
|
|
||||||
/* methods */
|
class WFMtl
|
||||||
bool load(const char *fname, loadfile_t lf = NULL, loadtexture_t lt = NULL);
|
{
|
||||||
bool load(const Buffer &buff);
|
public:
|
||||||
|
WFMtl(WFObj * obj) { m_obj = obj; }
|
||||||
|
bool load(const FileLoader::Path & path);
|
||||||
|
void renderBegin(const std::string & mtlname,
|
||||||
|
bool doTextureInfo = true,
|
||||||
|
bool enableBlending = false);
|
||||||
|
void renderEnd(const std::string & mtlname,
|
||||||
|
bool doTextureInfo = true,
|
||||||
|
bool enableBlending = false);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/* methods */
|
||||||
|
void clear();
|
||||||
|
void processInputLine(const std::string & input);
|
||||||
|
void pushAttributes();
|
||||||
|
bool load(std::istream & istr, unsigned int size);
|
||||||
|
|
||||||
|
/* variables */
|
||||||
|
std::map< std::string, std::vector< std::vector<std::string> > > m_data;
|
||||||
|
std::string m_currentMaterialName;
|
||||||
|
bool m_attributesPushed;
|
||||||
|
FileLoader::Path m_path;
|
||||||
|
WFObj * m_obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
class WFFileLoader : public FileLoader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual int getSize(const Path & path);
|
||||||
|
virtual Buffer load(const Path & path);
|
||||||
|
};
|
||||||
|
|
||||||
|
bool load(const FileLoader::Path & path);
|
||||||
|
GLuint render(bool doTextureInfo = true,
|
||||||
|
bool enableBlending = false);
|
||||||
const float * const getAABB() { return m_aabb; }
|
const float * const getAABB() { return m_aabb; }
|
||||||
size_t getStride() { return sizeof(GLfloat) * m_n_floats_per_vref; }
|
|
||||||
size_t getVertexOffset() { return 0; }
|
|
||||||
size_t getNormalOffset() { return 3 * sizeof(GLfloat); }
|
|
||||||
size_t getTextureCoordOffset() { return 6 * sizeof(GLfloat); }
|
|
||||||
void bindBuffers();
|
|
||||||
size_t getNumMaterials() { return m_num_materials; }
|
|
||||||
std::map<std::string, Material> & getMaterials() { return m_materials; }
|
|
||||||
bool doTextures() { return m_do_textures; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* types */
|
/* types */
|
||||||
class Vertex
|
class Vertex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float operator[](int idx) const { return data[idx]; }
|
float operator[](int idx) const { return data[idx]; }
|
||||||
float & operator[](int idx) { return data[idx]; }
|
float & operator[](int idx) { return data[idx]; }
|
||||||
float * getData() { return data; }
|
float * getData() { return data; }
|
||||||
private:
|
private:
|
||||||
float data[4];
|
float data[4];
|
||||||
};
|
|
||||||
|
|
||||||
class VertexRef
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
VertexRef() : vertex(0), texture(0), normal(0) {}
|
|
||||||
size_t vertex;
|
|
||||||
size_t texture;
|
|
||||||
size_t normal;
|
|
||||||
bool operator<(const VertexRef & other) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Face
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
VertexRef vertices[3];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* methods */
|
/* methods */
|
||||||
|
void init(FileLoader * fileLoader = NULL,
|
||||||
|
TextureLoader * textureLoader = NULL);
|
||||||
void clear();
|
void clear();
|
||||||
void processInputLine(const std::string & input);
|
void processInputLine(const std::string & input);
|
||||||
Vertex readVertex(const std::vector<std::string> & parts);
|
Vertex readVertex(const std::vector<std::string> & parts);
|
||||||
std::vector<Face> readFaces(const std::vector<std::string> & parts);
|
void parseVertexIndices(const std::string & vtxref, int * ret);
|
||||||
VertexRef readVertexRef(const std::string ref);
|
void updateAABB(const float * const vertex);
|
||||||
void updateAABB();
|
bool load(std::istream & istr, unsigned int size);
|
||||||
static bool loadfile(const char *path, Buffer & buff);
|
|
||||||
std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
|
|
||||||
void loadMaterial(const std::string & name);
|
|
||||||
bool buildVBO();
|
|
||||||
GLuint loadTexture(const std::string & path);
|
|
||||||
std::string resolvePath(const std::string & name);
|
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
std::vector<Vertex> m_vertices[VERTEX_TYPES];
|
std::vector< std::vector<std::string> > m_data;
|
||||||
std::map< std::string, std::vector< Face > > m_faces;
|
FileLoader::Path m_path;
|
||||||
std::map< std::string, Material > m_materials;
|
|
||||||
float m_aabb[6];
|
float m_aabb[6];
|
||||||
std::string m_path;
|
bool m_loadedVertex;
|
||||||
loadfile_t m_loadfile;
|
FileLoader * m_fileLoader;
|
||||||
loadtexture_t m_loadtexture;
|
TextureLoader * m_textureLoader;
|
||||||
std::string m_current_material_name;
|
bool m_iCreatedFileLoader;
|
||||||
bool m_valid;
|
|
||||||
GLuint m_data_vbo, m_index_vbo;
|
|
||||||
bool m_do_textures;
|
|
||||||
size_t m_n_floats_per_vref;
|
|
||||||
size_t m_num_materials;
|
|
||||||
std::map<std::string, GLuint> m_textures;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
11
driver.cc
11
driver.cc
@ -1,9 +1,15 @@
|
|||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "WFObj.h"
|
#include "WFObj.hh"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
GLuint loadTexture(const char * texture)
|
||||||
|
{
|
||||||
|
cout << "got texture request: '" << texture << "'" << endl;
|
||||||
|
return 33;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
WFObj w;
|
WFObj w;
|
||||||
@ -12,10 +18,11 @@ int main(int argc, char * argv[])
|
|||||||
cout << "Usage: " << argv[0] << " <filename>" << endl;
|
cout << "Usage: " << argv[0] << " <filename>" << endl;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (!w.load(argv[1]))
|
if (!w.load(argv[1], &loadTexture))
|
||||||
{
|
{
|
||||||
cout << "Couldn't open '" << argv[1] << "'!" << endl;
|
cout << "Couldn't open '" << argv[1] << "'!" << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
w.render();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user