Compare commits

...

55 Commits
v1.0 ... master

Author SHA1 Message Date
Josh Holtrop
e4dc0f4d36 error loading object file when "usemtl" references an undefined material 2011-05-27 15:39:53 -04:00
Josh Holtrop
e6b8c17345 initialize WFObj::Buffer parameters 2011-05-21 23:32:39 -04:00
Josh Holtrop
1ecc6d749b specify GL_GLEXT_PROTOTYPES in build environment 2011-05-16 15:54:35 -04:00
Josh Holtrop
08e558482f add resolvePath() to find files rel to .obj path 2011-05-16 15:32:11 -04:00
Josh Holtrop
1918cc89bf changed loadfile and loadtexture to load() params 2011-05-16 15:24:00 -04:00
Josh Holtrop
e999bf67b7 add texture support 2011-05-16 15:16:40 -04:00
Josh Holtrop
01a90fdef7 change VertexRef elements to unsigned values to fix compile warnings 2011-05-16 15:01:36 -04:00
Josh Holtrop
c5c76f0033 compile with -Wall, fix a warning 2011-05-16 15:00:43 -04:00
Josh Holtrop
1c17d3b398 Merge branch 'master' of ssh://holtrop.homelinux.com/wfobj 2011-05-04 20:38:53 -04:00
Josh Holtrop
6bdaecd9f7 add GL_INCLUDE_FILE capability 2011-05-04 20:38:38 -04:00
Josh Holtrop
2fcba86aad add doTextures() 2011-05-04 19:44:09 -04:00
Josh Holtrop
2ffcdfb3dc remove draw(); add get*() methods for client access 2011-05-04 16:12:00 -04:00
Josh Holtrop
4e76817336 make Material a public subclass, remove renderMaterial() 2011-05-04 15:50:18 -04:00
Josh Holtrop
933c4b457a update README for version info 2011-04-25 17:22:32 -04:00
Josh Holtrop
2e599ab86b bugfix in index calculation for material group > 0 2011-04-25 17:20:10 -04:00
Josh Holtrop
e1f2d5a04a remove unnecessary 'num' variable 2011-04-25 17:17:13 -04:00
Josh Holtrop
ce0a8e608d fix populating buffer data 2011-04-25 16:38:17 -04:00
Josh Holtrop
a12c4ec42d fill out draw() 2011-04-25 14:48:47 -04:00
Josh Holtrop
e07ed46297 bind buffers 2011-04-24 23:31:08 -04:00
Josh Holtrop
53d4bebbc2 add draw() and renderMaterial() 2011-04-24 23:28:53 -04:00
Josh Holtrop
fea2100741 fill indices VBO 2011-04-24 23:16:13 -04:00
Josh Holtrop
02a3f85fc1 use two VBOs, filling in data VBO 2011-04-24 22:46:56 -04:00
Josh Holtrop
0bdfff50e7 store face indices per material for drawing 2011-04-24 22:35:58 -04:00
Josh Holtrop
d13e3a60b2 fill in client-side data 2011-04-24 22:19:24 -04:00
Josh Holtrop
5eed1256ef allocate client-side data for VBO 2011-04-24 21:03:14 -04:00
Josh Holtrop
0f816ded34 bugfix with readFaces() 2011-04-24 20:52:45 -04:00
Josh Holtrop
e980b60044 use atof() instead of sscanf() 2011-04-24 20:46:29 -04:00
Josh Holtrop
40c37dacb2 working on buildVBO() 2011-04-24 19:54:51 -04:00
Josh Holtrop
6dab4e48a6 build flat_vertices collection for VBO 2011-04-24 19:14:07 -04:00
Josh Holtrop
67ef0c4009 add initial buildVBO() 2011-04-20 16:29:59 -04:00
Josh Holtrop
66d4bb50e4 fix basePath(); load .mtl relative to .obj path 2011-04-20 15:46:30 -04:00
Josh Holtrop
d78d956826 fix readFaces() segfault 2011-04-20 15:37:00 -04:00
Josh Holtrop
a6eca59683 build driver program as well 2011-04-20 15:32:26 -04:00
Josh Holtrop
806f7890f3 call updateAABB() 2011-04-20 15:25:58 -04:00
Josh Holtrop
0daac5781e loadfile_t takes Buffer ref instead of ptr 2011-04-20 15:22:35 -04:00
Josh Holtrop
a46b5baa05 fill WFObj::loadfile(), add Buffer allocation 2011-04-20 15:20:10 -04:00
Josh Holtrop
ffe2fe1d92 load materials into Material objects 2011-04-20 15:08:42 -04:00
Josh Holtrop
874be25658 update trimString(), add tokenize() 2011-04-20 14:45:55 -04:00
Josh Holtrop
cf4e09814f add valid flag, expand clear() 2011-04-20 12:22:59 -04:00
Josh Holtrop
d33b4826e2 add WFObj::VertexRef::operator<() 2011-04-20 12:19:55 -04:00
Josh Holtrop
3506ad6b57 update updateAABB() 2011-04-20 11:34:02 -04:00
Josh Holtrop
8e6cd37dc9 use scons to build 2011-04-20 11:30:00 -04:00
Josh Holtrop
51c0ded005 fix compilation errors; compiling! 2011-04-19 17:05:17 -04:00
Josh Holtrop
18c4be6a42 remove WFMtl, I didn't like it 2011-04-19 16:58:19 -04:00
Josh Holtrop
a9ad715e4b finish readFaces() 2011-04-19 16:51:25 -04:00
Josh Holtrop
96737a0386 finish processInputLine() 2011-04-19 16:43:08 -04:00
Josh Holtrop
dffa5a98a5 add readFaces() and readVertexRef() 2011-04-19 16:26:59 -04:00
Josh Holtrop
476f4cde66 remove render(), gut processInputLine(), add m_faces map 2011-04-19 16:16:41 -04:00
Josh Holtrop
3f78016e26 coding style update 2011-04-19 16:00:25 -04:00
Josh Holtrop
e7f7ca4b3f add VertexRef 2011-04-19 15:59:55 -04:00
Josh Holtrop
f46f887472 replace m_data with m_vertices 2011-04-19 15:58:18 -04:00
Josh Holtrop
594642f489 finish load() 2011-04-18 12:40:59 -04:00
Josh Holtrop
28722f4c94 add WFObj::getLine() 2011-04-18 12:35:09 -04:00
Josh Holtrop
d59eb2ffe5 break compile; begin to modify for v2.0 2011-04-18 12:21:13 -04:00
Josh Holtrop
ebb39c8750 update README for v2.0 2011-04-18 10:56:34 -04:00
8 changed files with 531 additions and 619 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
driver

View File

@ -1,10 +1,7 @@
export SCONSFLAGS := -Q
TARGET := WFObj.o
all: $(TARGET)
%.o: %.cc
$(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
all:
@scons
clean:
-rm -f *~ *.o
@scons -c

View File

@ -1,18 +0,0 @@
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
View File

@ -1,5 +1,5 @@
WFObj version 1.0
WFObj version 2.0
Author: Josh Holtrop
This utility uses OpenGL 1.x functionality to render an Alias Wavefront object
file into a display list for repeated rendering.
This utility uses OpenGL vertex buffer objects to render an Alias Wavefront
object file for efficient repeated rendering.

6
SConstruct Normal file
View File

@ -0,0 +1,6 @@
# vim:filetype=python
env = Environment(LIBS = ['GL'], CXXFLAGS = ['-Wall', '-DGL_GLEXT_PROTOTYPES'])
env.Program('driver', Glob('*.cc'))

921
WFObj.cc

File diff suppressed because it is too large Load Diff

150
WFObj.h
View File

@ -2,9 +2,12 @@
#ifndef WFOBJ_H
#define WFOBJ_H
#include "FileLoader/FileLoader.h"
#include "TextureLoader/TextureLoader.h"
#ifdef GL_INCLUDE_FILE
#include GL_INCLUDE_FILE
#else
#include <GL/gl.h>
#endif
#include <vector>
#include <string>
#include <map>
@ -12,50 +15,66 @@
class WFObj
{
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(FileLoader & fileLoader);
WFObj(TextureLoader & textureLoader);
WFObj(FileLoader & fileLoader, TextureLoader & textureLoader);
~WFObj();
class WFMtl
{
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);
bool load(const char *fname, loadfile_t lf = NULL, loadtexture_t lt = NULL);
bool load(const Buffer &buff);
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:
/* types */
@ -69,24 +88,51 @@ protected:
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 */
void init(FileLoader * fileLoader = NULL,
TextureLoader * textureLoader = NULL);
void clear();
void processInputLine(const std::string & input);
Vertex readVertex(const std::vector<std::string> & parts);
void parseVertexIndices(const std::string & vtxref, int * ret);
void updateAABB(const float * const vertex);
bool load(std::istream & istr, unsigned int size);
std::vector<Face> readFaces(const std::vector<std::string> & parts);
VertexRef readVertexRef(const std::string ref);
void updateAABB();
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 */
std::vector< std::vector<std::string> > m_data;
FileLoader::Path m_path;
std::vector<Vertex> m_vertices[VERTEX_TYPES];
std::map< std::string, std::vector< Face > > m_faces;
std::map< std::string, Material > m_materials;
float m_aabb[6];
bool m_loadedVertex;
FileLoader * m_fileLoader;
TextureLoader * m_textureLoader;
bool m_iCreatedFileLoader;
std::string m_path;
loadfile_t m_loadfile;
loadtexture_t m_loadtexture;
std::string m_current_material_name;
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

View File

@ -1,15 +1,9 @@
#include <GL/gl.h>
#include <iostream>
#include "WFObj.hh"
#include "WFObj.h"
using namespace std;
GLuint loadTexture(const char * texture)
{
cout << "got texture request: '" << texture << "'" << endl;
return 33;
}
int main(int argc, char * argv[])
{
WFObj w;
@ -18,11 +12,10 @@ int main(int argc, char * argv[])
cout << "Usage: " << argv[0] << " <filename>" << endl;
return -2;
}
if (!w.load(argv[1], &loadTexture))
if (!w.load(argv[1]))
{
cout << "Couldn't open '" << argv[1] << "'!" << endl;
return -1;
}
w.render();
return 0;
}