#include "mesh.h"
#include "meshgen.h"
#include "scene.h"
+#include "datamap.h"
static void draw_scene();
float ambient[] = {0.0, 0.0, 0.0, 0.0};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
+ datamap_set_path("data");
+ if(!datamap_load_map("data.map")) {
+ fprintf(stderr, "failed to load datafile mappings\n");
+ }
+
unsigned int sflags = SCNLOAD_FLIPTEX;
scn = new Scene(&texman);
if(!(scn->load("data/testscene/patoma.fbx", sflags)) ||
}
// hardcoded texture assignment hack
- Texture *tex_girogiromarmaro = texman.get("data/testscene/girogiromarmarodiffuse.jpg");
- Texture *tex_kafemarble = texman.get("data/testscene/kafemarblediffuse.jpg");
- Texture *tex_kentrikokafemarble = texman.get("data/testscene/kentrikokafemarblediffuse.jpg");
- Texture *tex_paliomarmaro = texman.get("data/testscene/paliomarmarodiffuse.jpg");
- Texture *tex_steelgreygranite = texman.get("data/testscene/steel-grey-granitediffuse.jpg");
- Texture *tex_whitemarble = texman.get("data/testscene/whitemarblediffuse.jpg");
- Texture *tex_kolones_lightmap = texman.get("data/testscene/kolones_lighmap.jpg");
- Texture *tex_patoma_lightmap = texman.get("data/testscene/patomacorona_lightmap.jpg");
+ Texture *tex_kolones_lightmap = texman.get_texture("data/testscene/kolones_lighmap.jpg", TEX_2D);
+ Texture *tex_patoma_lightmap = texman.get_texture("data/testscene/patomacorona_lightmap.jpg", TEX_2D);
+ /*
for(int i=0; i<(int)scn->objects.size(); i++) {
Object *obj = scn->objects[i];
if(obj->mtl.name == "WiteMarble") {
- obj->mtl.add_texture(tex_whitemarble, MTL_TEX_DIFFUSE);
obj->mtl.add_texture(tex_patoma_lightmap, MTL_TEX_LIGHTMAP);
} else if(obj->mtl.name == "BrownMarble") {
- obj->mtl.add_texture(tex_kafemarble, MTL_TEX_DIFFUSE);
obj->mtl.add_texture(tex_patoma_lightmap, MTL_TEX_LIGHTMAP);
} else if(obj->mtl.name == "GiroGiroMarmaro") {
- obj->mtl.add_texture(tex_girogiromarmaro, MTL_TEX_DIFFUSE);
obj->mtl.add_texture(tex_patoma_lightmap, MTL_TEX_LIGHTMAP);
} else if(obj->mtl.name == "KentrikoKafeMarmaro") {
- obj->mtl.add_texture(tex_kentrikokafemarble, MTL_TEX_DIFFUSE);
obj->mtl.add_texture(tex_patoma_lightmap, MTL_TEX_LIGHTMAP);
+
} else if(obj->mtl.name == "SkouroGrizoMarmaro") {
- obj->mtl.add_texture(tex_steelgreygranite, MTL_TEX_DIFFUSE);
obj->mtl.add_texture(tex_kolones_lightmap, MTL_TEX_LIGHTMAP);
} else if(obj->mtl.name == "PalioMarmaro") {
- obj->mtl.add_texture(tex_paliomarmaro, MTL_TEX_DIFFUSE);
obj->mtl.add_texture(tex_kolones_lightmap, MTL_TEX_LIGHTMAP);
}
}
+ */
if(!(sdr = create_program_load("sdr/test.v.glsl", "sdr/test.p.glsl"))) {
fprintf(stderr, "failed to load test shaders\n");
scn->update(dt);
- float walk_speed = 10.0 * dt;
+ float walk_speed = 2000.0 * dt;
Vec3 dir;
if(keystate[(int)'w']) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- gluPerspective(50.0, (float)x / (float)y, 0.5, 1000.0);
+ gluPerspective(50.0, (float)x / (float)y, 1.0, 10000.0);
}
void app_keyboard(int key, bool pressed)
#include <vector>
#include <map>
#include <string>
-#include <regex>
+//#include <regex>
#include "datamap.h"
#ifdef WIN32
static char *clean_line(char *s);
-static std::vector<std::pair<std::regex, std::string>> dmap;
+//static std::vector<std::pair<std::regex, std::string>> dmap;
+static std::vector<std::pair<std::string, std::string>> dmap;
static std::map<std::string, std::string> cache;
static std::string root;
void datamap_reset()
{
- root.clear();
dmap.clear();
cache.clear();
}
}
*colon = 0;
- std::pair<std::regex, std::string> pair;
- pair.first = std::regex(line);
+ //std::pair<std::regex, std::string> pair;
+ //pair.first = std::regex(line);
+ std::pair<std::string, std::string> pair;
+ pair.first = std::string(line);
char *value = clean_line(colon + 1);
if(!value || !*value) {
void datamap_map(const char *re, const char *path)
{
- std::pair<std::regex, std::string> mapping;
- mapping.first = std::regex(re);
+ //std::pair<std::regex, std::string> mapping;
+ //mapping.first = std::regex(re);
+ std::pair<std::string, std::string> mapping;
+ mapping.first = std::string(re);
mapping.second = std::string(path);
dmap.push_back(std::move(mapping));
}
res = it->second;
} else {
// try matching with the available mappings
+ res = std::string(in);
+
int num = dmap.size();
for(int i=0; i<num; i++) {
- if(std::regex_match(in, dmap[i].first)) {
+ //if(std::regex_search(in, dmap[i].first)) {
+ if(strstr(in, dmap[i].first.c_str())) {
res = root.empty() ? dmap[i].second : root + "/" + dmap[i].second;
cache[in] = res; // add it to the cache
break;
}
}
- return 0;
}
// copy result in buf, truncating if necessary and return the size of the
}
T res = create();
+ data[name] = res;
resman_lookup(rman, name, res);
return res;
}
#include <stdio.h>
+#include <assert.h>
#include <vector>
#include <map>
#include <gmath/gmath.h>
/*static const char *mprop_semantic(int x);
static int count_textures(const aiMaterial *aimat);*/
static int assimp_textype(aiTextureType type);
+static const char *assimp_textypestr(aiTextureType type);
static Mat4 assimp_matrix(const aiMatrix4x4 &aim);
aiProcess_Triangulate |
aiProcess_SortByPType |
aiProcess_GenUVCoords |
+ //aiProcess_PreTransformVertices |
aiProcess_TransformUVCoords;
if(flags & SCNLOAD_FLIPTEX) {
ppflags |= aiProcess_FlipUVs;
}
+ printf("Loading scene file: %s\n", fname);
+
const aiScene *aiscn = aiImportFile(fname, ppflags);
if(!aiscn) {
fprintf(stderr, "failed to load scene file: %s\n", fname);
} else {
mat->name = "unknown";
}
- //printf("load_material: %s\n", mat->name.c_str());
+ printf("load_material: %s\n", mat->name.c_str());
if(aiGetMaterialColor(aimat, AI_MATKEY_COLOR_DIFFUSE, &aicol) == 0) {
mat->diffuse = Vec3(aicol[0], aicol[1], aicol[2]);
} while(*sptr++);
}
- Texture *tex = scn->texset->get(fname);
- if(!tex) {
- fprintf(stderr, "failed to load texture: %s\n", fname);
- delete [] fname;
- continue;
- }
- delete [] fname;
+ int textype = assimp_textype(aitype);
+ printf("loading %s texture: %s\n", assimp_textypestr(aitype), fname);
+ Texture *tex = scn->texset->get_texture(fname, TEX_2D);
+ assert(tex);
mat->textures.push_back(tex);
- int textype = assimp_textype(aitype);
+ printf(" DBG(%p)\n", (void*)tex);
+
if(textype != MTL_TEX_UNKNOWN && !mat->stdtex[textype]) {
mat->stdtex[textype] = tex;
}
iptr += 3;
}
+ AABox bbox = mesh->get_aabbox();
+ printf("mesh bounding box: %f %f %f -> %f %f %f\n", bbox.min.x, bbox.min.y, bbox.min.z,
+ bbox.max.x, bbox.max.y, bbox.max.z);
+
return mesh;
}
case aiTextureType_NORMALS:
return MTL_TEX_NORMALMAP;
case aiTextureType_LIGHTMAP:
+ case aiTextureType_EMISSIVE:
return MTL_TEX_LIGHTMAP;
case aiTextureType_REFLECTION:
return MTL_TEX_ENVMAP;
return MTL_TEX_UNKNOWN;
}
+static const char *assimp_textypestr(aiTextureType type)
+{
+ switch(type) {
+ case aiTextureType_DIFFUSE:
+ return "diffuse";
+ case aiTextureType_SPECULAR:
+ return "specular";
+ case aiTextureType_NORMALS:
+ return "normalmap";
+ case aiTextureType_LIGHTMAP:
+ case aiTextureType_EMISSIVE:
+ return "lightmap";
+ case aiTextureType_REFLECTION:
+ return "envmap";
+ default:
+ break;
+ }
+ return "unknown";
+}
+
static Mat4 assimp_matrix(const aiMatrix4x4 &aim)
{
Mat4 m;
#include <math.h>
+#include <assert.h>
#include "texture.h"
#include "image.h"
#include "opengl.h"
} else {
glActiveTexture(GL_TEXTURE0 + tunit);
glBindTexture(cur_target[tunit], 0);
+ assert(glGetError() == GL_NO_ERROR);
glActiveTexture(GL_TEXTURE0);
}
}
}
glBindTexture(target, id);
+ assert(glGetError() == GL_NO_ERROR);
glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap);
glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap);
glTexParameteri(target, GL_TEXTURE_WRAP_R, wrap);
void Texture::set_filtering(unsigned int min_filt, unsigned int mag_filt)
{
glBindTexture(target, id);
+ assert(glGetError() == GL_NO_ERROR);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, min_filt);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, mag_filt);
}
{
glActiveTexture(GL_TEXTURE0 + tex_unit);
glBindTexture(target, id);
+ assert(glGetError() == GL_NO_ERROR);
glActiveTexture(GL_TEXTURE0);
cur_target[tex_unit] = target;
target = type_to_target(textype);
glBindTexture(target, id);
+ assert(glGetError() == GL_NO_ERROR);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
pixels[1] = 64;
pixels[2] = chess ? 32 : 255;
pixels[3] = 255;
+ pixels += 4;
}
}
+ default_img->save("/tmp/foo.png");
}
switch(type) {
target = GL_TEXTURE_2D;
glBindTexture(target, id);
+ assert(glGetError() == GL_NO_ERROR);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
target = GL_TEXTURE_CUBE_MAP;
glBindTexture(target, id);
+ assert(glGetError() == GL_NO_ERROR);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
}
Texture *res = create();
+ data[name] = res;
res->create_default(type);
resman_lookup(rman, name, res);
return res;