Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln	(revision 2800)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln	(revision 2961)
@@ -2,5 +2,7 @@
 Microsoft Visual Studio Solution File, Format Version 9.00
 # Visual Studio 2005
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chc_revisited", "FriendlyCulling.vcproj", "{03661866-4093-4B02-B26A-028EA91AF023}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "friendlyculling", "FriendlyCulling.vcproj", "{03661866-4093-4B02-B26A-028EA91AF023}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Converter", "Converter.vcproj", "{93A522E1-76F0-4D46-9C97-30DC2DDB531D}"
 EndProject
 Global
@@ -14,4 +16,8 @@
 		{03661866-4093-4B02-B26A-028EA91AF023}.Release|Win32.ActiveCfg = Release|Win32
 		{03661866-4093-4B02-B26A-028EA91AF023}.Release|Win32.Build.0 = Release|Win32
+		{93A522E1-76F0-4D46-9C97-30DC2DDB531D}.Debug|Win32.ActiveCfg = Debug|Win32
+		{93A522E1-76F0-4D46-9C97-30DC2DDB531D}.Debug|Win32.Build.0 = Debug|Win32
+		{93A522E1-76F0-4D46-9C97-30DC2DDB531D}.Release|Win32.ActiveCfg = Release|Win32
+		{93A522E1-76F0-4D46-9C97-30DC2DDB531D}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/gzstream.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/gzstream.h	(revision 2961)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/gzstream.h	(revision 2961)
@@ -0,0 +1,146 @@
+// ============================================================================
+// gzstream, C++ iostream classes wrapping the zlib compression library.
+// Copyright (C) 2001  Deepak Bandyopadhyay, Lutz Kettner
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+// ============================================================================
+//
+// File          : gzstream.h
+// Revision      : $Revision: 1.1 $
+// Revision_date : $Date: 2004/02/16 14:46:00 $
+// Author(s)     : Deepak Bandyopadhyay, Lutz Kettner
+// 
+// Standard streambuf implementation following Nicolai Josuttis, "The 
+// Standard C++ Library".
+// ============================================================================
+
+#ifndef GZSTREAM_H
+#define GZSTREAM_H 1
+
+#include <zlib.h>
+
+// standard C++ with new header file names and std:: namespace
+#include <iostream>
+#include <fstream>
+
+#ifdef GZSTREAM_NAMESPACE
+namespace GZSTREAM_NAMESPACE {
+#endif
+
+// ----------------------------------------------------------------------------
+// Internal classes to implement gzstream. See below for user classes.
+// ----------------------------------------------------------------------------
+
+   // size of data buff
+#define gzbufferSize  303   
+
+
+
+#define STREAMBUF std::streambuf 
+#define ISTREAM std::istream
+#define OSTREAM std::ostream
+
+//#define STREAMBUF streambuf 
+//#define ISTREAM istream
+//#define OSTREAM ostream
+
+class gzstreambuf : public STREAMBUF {
+
+private:
+    // totals 512 bytes under g++ for igzstream at the end.
+
+    gzFile           file;               // file handle for compressed file
+    char             buffer[gzbufferSize]; // data buffer
+    char             opened;             // open/close state of stream
+    int              mode;               // I/O mode
+
+    int flush_buffer();
+public:
+    gzstreambuf() : opened(0) {
+        setp( buffer, buffer + (gzbufferSize-1));
+        setg( buffer + 4,     // beginning of putback area
+              buffer + 4,     // read position
+              buffer + 4);    // end position      
+        // ASSERT: both input & output capabilities will not be used together
+    }
+    int is_open() const { return opened; }
+    gzstreambuf* open( const char* name, int open_mode);
+    gzstreambuf* close();
+    ~gzstreambuf() { close(); }
+  
+    virtual int     overflow( int c = EOF);
+    virtual int     underflow();
+    virtual int     sync();
+
+};
+
+class gzstreambase : virtual public std::ios {
+
+protected:
+    gzstreambuf buf;
+public:
+  gzstreambase() { init(&buf); }
+  gzstreambase( const char* name, int open_mode);
+  ~gzstreambase();
+  void open( const char* name, int open_mode);
+  void close();
+  gzstreambuf* rdbuf() { return &buf; }
+  int is_open() const { return buf.is_open(); }
+};
+
+// ----------------------------------------------------------------------------
+// User classes. Use igzstream and ogzstream analogously to ifstream and
+// ofstream respectively. They read and write files based on the gz* 
+// function interface of the zlib. Files are compatible with gzip compression.
+// ----------------------------------------------------------------------------
+
+  
+
+  class igzstream : public gzstreambase, public ISTREAM {
+  
+  public:
+    igzstream() : gzstreambase(), ISTREAM( &buf )  {} 
+    
+    igzstream( const char* name, int open_mode = std::ios::in)
+      : gzstreambase( name, open_mode), ISTREAM( &buf) {}
+    
+    gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
+    
+    void open( const char* name, int open_mode = std::ios::in) {
+      gzstreambase::open( name, open_mode);
+    }
+  };
+  
+class ogzstream : public gzstreambase, public OSTREAM {
+  
+public:
+  ogzstream() : OSTREAM( &buf) {}
+  ogzstream( const char* name, int mode = std::ios::out)
+    : gzstreambase( name, mode), OSTREAM( &buf) {}  
+  gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
+  void open( const char* name, int open_mode = std::ios::out) {
+    gzstreambase::open( name, open_mode);
+  }
+  
+};
+
+#ifdef GZSTREAM_NAMESPACE
+} // namespace GZSTREAM_NAMESPACE
+#endif
+
+#endif // GZSTREAM_H
+// ============================================================================
+// EOF //
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 2961)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp	(revision 2961)
@@ -0,0 +1,395 @@
+#include "ObjConverter.h"
+#include "gzstream.h"
+#include <iostream>
+
+
+using namespace std;
+
+
+static void LoadIndices(char *str, 
+						const VertexArray &vertices, 
+						const VertexArray &normals, 
+						const vector<pair<float, float> > &texcoords,
+						VertexArray &faceVertices,
+						VertexArray &faceNormals,
+						vector<Texcoord> &faceTexcoords
+						)
+{
+	vector<char *> substrings;
+
+	char *next_token;
+
+	// extract the triples of the form v/t/n v/t/n ...
+	char *pch = strtok_s(str + 1, " ", &next_token);
+
+	while (pch != NULL)
+	{
+		substrings.push_back(pch);
+		pch = strtok_s(NULL, " ", &next_token);	  
+	}
+
+	vector<int> indices;
+	vector<int> nIndices;
+	vector<int> tIndices;
+
+	//cout << "number of vertices=" << (int)vertices.size() << endl;
+
+	for (size_t i = 0; i < substrings.size(); ++ i)
+	{
+		// vertex, normal and texture indices
+		char *str = strtok_s(substrings[i], "/", &next_token);	  
+		int index = (int)strtol(str, NULL, 10) - 1;
+
+		str = strtok_s(substrings[i], "/", &next_token);	  
+		int tIndex = (int)strtol(str, NULL, 10) - 1;
+
+		str = strtok_s(substrings[i], "/", &next_token);	  
+		int nIndex = (int)strtol(str, NULL, 10) - 1;
+
+		// store indices
+		if (index >= 0)
+		{
+			indices.push_back(index);
+			nIndices.push_back(nIndex);
+			tIndices.push_back(tIndex);
+		}
+
+		// new triangle found
+		if (indices.size() > 2)
+		{
+#if 1
+			int idx1 = 0;
+			int idx2 = (int)indices.size() - 2;
+			int idx3 = (int)indices.size() - 1;
+#else
+			int idx3 = 0;
+			int idx2 = (int)indices.size() - 2;
+			int idx1 = (int)indices.size() - 1;
+#endif
+			faceVertices.push_back(vertices[indices[idx1]]);
+			faceVertices.push_back(vertices[indices[idx2]]);
+			faceVertices.push_back(vertices[indices[idx3]]);
+		
+			faceNormals.push_back(normals[nIndices[idx1]]);
+			faceNormals.push_back(normals[nIndices[idx2]]);
+			faceNormals.push_back(normals[nIndices[idx3]]);
+
+			faceTexcoords.push_back(texcoords[tIndices[idx1]]);
+			faceTexcoords.push_back(texcoords[tIndices[idx2]]);
+			faceTexcoords.push_back(texcoords[tIndices[idx3]]);
+		}
+	}
+}
+
+
+ObjConverter::ObjConverter()
+{}
+
+
+ObjConverter::~ObjConverter()
+{
+	for (size_t i = 0; i < mGeometry.size(); ++ i)
+	{
+		delete [] mGeometry[i]->mVertices;
+		delete [] mGeometry[i]->mNormals;
+		delete [] mGeometry[i]->mTexcoords;
+
+		delete mGeometry[i];
+	}
+	
+	mGeometry.clear();
+}
+
+
+void ObjConverter::LoadShape(const VertexArray &faceVertices,
+							 const VertexArray &faceNormals,
+							 const vector<Texcoord> &faceTexcoords)
+{
+	int numElements = (int)faceVertices.size();
+	Geometry *geom = new Geometry();
+
+	// convert the triangles to geometry
+	geom->mVertices = new Vector3[numElements];
+	geom->mNormals = new Vector3[numElements];
+	geom->mTexcoords = new Texcoord[numElements];
+
+	geom->mVertexCount = numElements;
+	geom->mTexcoordCount = (int)faceTexcoords.size();
+
+	cout << "number of vertices=" << numElements << endl;
+
+	for (int i = 0; i < numElements; ++ i)
+	{
+		geom->mVertices[i].x = faceVertices[i].x;
+		geom->mVertices[i].y = -faceVertices[i].z;
+		geom->mVertices[i].z = faceVertices[i].y;
+
+		geom->mNormals[i].x = faceNormals[i].x;
+		geom->mNormals[i].y = -faceNormals[i].z;
+		geom->mNormals[i].z = faceNormals[i].y;
+
+		geom->mTexcoords[i].first = faceTexcoords[i].first;
+		geom->mTexcoords[i].second = faceTexcoords[i].second;
+	}
+
+	mGeometry.push_back(geom);
+}
+
+
+bool ObjConverter::Convert(const string &filename, const std::string &outputFilename)
+{
+	mNumShapes = 0;
+	
+	for (size_t i = 0; i < mGeometry.size(); ++ i)
+	{
+		delete [] mGeometry[i]->mVertices;
+		delete [] mGeometry[i]->mNormals;
+		delete [] mGeometry[i]->mTexcoords;
+
+		delete mGeometry[i];
+	}
+	
+	mGeometry.clear();
+
+	if (!ReadFile(filename))
+	{
+		cerr << "could not read file" << endl;
+		return false;
+	}
+
+	if (!WriteFile(outputFilename))
+	{
+		cerr << "could not write file" << endl;
+		return false;
+	}
+
+
+	return true;
+}
+
+
+bool ObjConverter::ReadFile(const string &filename) 
+{
+	FILE *file;
+
+	if ((file = fopen(filename.c_str(), "r")) == NULL)
+	{	
+		return false;
+	}
+	
+	VertexArray faceVertices; 
+	VertexArray faceNormals;
+	vector<Texcoord> faceTexcoords;
+
+	VertexArray vertices; 
+	VertexArray normals;
+	vector<Texcoord> texcoords;
+
+	vector<int> indices;
+
+	int line = 0;
+
+	const int len = 10000;
+	char str[len];
+
+	while (fgets(str, len, file) != NULL)
+	{
+		//cout << str;
+		switch (str[0]) 
+		{
+		case 'v': // vertex or normal
+			{
+				float x, y, z;
+
+				switch (str[1]) 
+				{
+				case 'n' :
+					sscanf(str + 2, "%f %f %f", &x, &y, &z);
+					normals.push_back(Vector3(x, y, z));
+					break;
+				case 't':
+					sscanf(str + 2, "%f %f", &x, &y);
+					texcoords.push_back(pair<float, float>(x, y));
+					break;
+				default:
+					sscanf(str + 1, "%f %f %f", &x, &y, &z);
+					vertices.push_back(Vector3(x, y, z));
+					//cout <<"v " << x << " " << y << " "<< z << " ";
+				}
+				break;
+			}
+		case 'f': 
+			{
+				//////////
+				//-- indices in the current line
+
+				LoadIndices(str, 
+					        vertices, normals, texcoords, 
+					        faceVertices, faceNormals, faceTexcoords);
+
+				break;
+			}   // end face
+		case 'g':
+			{/*
+				if (!faceVertices.empty())
+				{
+					++ mNumShapes;
+
+					LoadShape(faceVertices, faceNormals, faceTexcoords);
+
+					faceVertices.clear();
+					faceNormals.clear();
+					faceTexcoords.clear();
+				}*/
+			}
+			break;
+		default:
+			break;
+		}
+
+		++ line;
+	}
+
+	if (!faceVertices.empty())
+	{
+		++ mNumShapes;
+
+		LoadShape(faceVertices, faceNormals, faceTexcoords);
+
+		faceVertices.clear();
+		faceNormals.clear();
+		faceTexcoords.clear();
+	}
+
+	fclose(file);
+	
+	return true;
+}
+
+
+void ObjConverter::WriteGeometry(ogzstream &str, Geometry *geom)
+{
+	int vertexCount = geom->mVertexCount;
+	str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int));
+  
+	str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(Vector3) * vertexCount);
+	str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(Vector3) * vertexCount);
+
+	int texCoordCount = geom->mTexcoordCount;
+	str.write(reinterpret_cast<char *>(&texCoordCount), sizeof(int));
+
+	if (texCoordCount)
+		str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2);
+	
+
+	///////
+	//-- texture
+
+	//int texId = -1;
+	int texId = 0;
+	str.write(reinterpret_cast<char *>(&texId), sizeof(int));
+
+	bool alphaTestEnabled = false;
+	bool cullFaceEnabled = false;
+	//bool cullFaceEnabled = true;
+
+	str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool));
+	str.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool));
+
+	// material
+	//bool hasMaterial = true;
+	bool hasMaterial = false;
+	str.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool));
+	
+	if (hasMaterial)
+	{
+		Vector3 ambient, diffuse, black;
+
+		ambient.x = ambient.y = ambient.z = 0.2f;
+		diffuse.x = diffuse.y = diffuse.z = 1.0f;
+		black.x = black.y = black.z = .0f;
+
+		// only write rgb part of the material
+		str.write(reinterpret_cast<char *>(&ambient), sizeof(Vector3));
+		str.write(reinterpret_cast<char *>(&diffuse), sizeof(Vector3));
+		str.write(reinterpret_cast<char *>(&black), sizeof(Vector3));
+		str.write(reinterpret_cast<char *>(&black), sizeof(Vector3));
+	}
+}
+
+
+bool ObjConverter::WriteFile(const string &filename)
+{
+	ogzstream ofile(filename.c_str());
+
+	if (!ofile.is_open())
+		return false;
+	
+
+	/////////
+	//-- write textures
+
+	int textureCount = 1;
+	//int textureCount = 0;
+
+	ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int));
+
+	if (textureCount > 0)
+	{
+		const string texName("wood.jpg");
+
+		int texnameSize = (int)texName.length() + 1;
+		ofile.write(reinterpret_cast<char *>(&texnameSize), sizeof(int));
+
+		ofile.write(texName.c_str(), sizeof(char) * texnameSize);
+
+		int boundS = 1;
+		int boundT = 1;
+
+		ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int));
+		ofile.write(reinterpret_cast<char *>(&boundT), sizeof(int));
+	}
+
+
+	///////////
+	//-- write shapes
+
+	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
+
+	vector<Geometry *>::const_iterator it, it_end = mGeometry.end();
+
+	for (it = mGeometry.begin(); it != it_end; ++ it)
+	{
+		WriteGeometry(ofile, *it);
+	}
+
+
+	int entityCount = 1;
+	ofile.write(reinterpret_cast<char *>(&entityCount), sizeof(int));
+
+
+	//////////
+	//-- write single scene entity
+
+	// no transformation
+	bool hasTrafo = false;
+	ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool));
+
+	// a dummy lod
+	int numLODs = 1;
+	ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int));
+
+	float dist = 0;
+	ofile.write(reinterpret_cast<char *>(&dist), sizeof(float));
+
+	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
+
+	// all shapes belong to this scene entity
+	for (int i = 0; i < mNumShapes; ++ i)
+	{
+		int shapeId = i;
+		ofile.write(reinterpret_cast<char *>(&shapeId), sizeof(int));
+	}
+
+	return true;
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp	(revision 2961)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp	(revision 2961)
@@ -0,0 +1,32 @@
+#include "ObjConverter.h"
+#include <iostream>
+
+
+using namespace std;
+
+static string model_path("data/city/model/");
+
+int main(int argc, char* argv[])
+{
+	int returnCode = 0;
+
+	ObjConverter converter;
+
+	cout << "converting obj to dem format" << endl;
+
+/*	if (!converter.Convert(model_path + argv[1], model_path + argv[2]))
+	{
+		cerr << "conversion failed" << endl;
+		exit(0);
+	}
+*/
+	if (!converter.Convert(model_path + "toyplane.obj", model_path + "toyplane.dem"))
+		cerr << "conversion failed" << endl;
+
+	//if (!converter.Convert(model_path + "sky.obj", model_path + "sky.dem"))
+	//	cerr << "conversion failed" << endl;
+
+	cout << "conversion successful" << endl;
+	return 0;
+}
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h	(revision 2961)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h	(revision 2961)
@@ -0,0 +1,63 @@
+#ifndef _OBJCONVERTER_H
+#define _OBJCONVERTER_H
+
+#include <string>
+#include <vector>
+
+struct Vector3
+{
+	Vector3() {}
+	Vector3(float _x, float _y, float _z): x(_x), y(_y), z(_z) {}
+
+	float x, y, z;
+};
+
+typedef std::vector<Vector3> VertexArray;
+typedef std::pair<float, float> Texcoord;
+
+class ogzstream;
+
+/** Converts obj format into objects readable by our format
+*/
+class ObjConverter
+{
+public:
+
+	ObjConverter();
+
+	bool Convert(const std::string &inputFilename, 
+		         const std::string &outputFilename);
+	// const std::string textureFilename) const;
+
+	~ObjConverter();
+
+protected:
+
+	struct Geometry
+	{
+		Vector3 *mVertices;
+		Vector3 *mNormals;
+		Texcoord *mTexcoords;
+
+		int mVertexCount;
+		int mTexcoordCount;
+	};
+
+	void LoadShape(const VertexArray &faceVertices,
+		           const VertexArray &faceNormals,
+				   const std::vector<Texcoord> &faceTexcoords);
+
+	void WriteGeometry(ogzstream &str, Geometry *geom);
+
+	bool ReadFile(const std::string &inputFilename);
+	bool WriteFile(const std::string &outputFilename);
+
+
+	std::vector<Geometry *> mGeometry;
+
+	int mNumShapes;
+};
+
+
+
+#endif
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/gzstream.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/gzstream.cpp	(revision 2961)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/gzstream.cpp	(revision 2961)
@@ -0,0 +1,175 @@
+// ============================================================================
+// gzstream, C++ iostream classes wrapping the zlib compression library.
+// Copyright (C) 2001  Deepak Bandyopadhyay, Lutz Kettner
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+// ============================================================================
+//
+// File          : gzstream.C
+// Revision      : $Revision: 1.1 $
+// Revision_date : $Date: 2004/02/16 14:46:00 $
+// Author(s)     : Deepak Bandyopadhyay, Lutz Kettner
+// 
+// Standard streambuf implementation following Nicolai Josuttis, "The 
+// Standard C++ Library".
+// ============================================================================
+
+#include "gzstream.h"
+#include <string.h>  // for memcpy
+
+#ifdef GZSTREAM_NAMESPACE
+namespace GZSTREAM_NAMESPACE {
+#endif
+
+// ----------------------------------------------------------------------------
+// Internal classes to implement gzstream. See header file for user classes.
+// ----------------------------------------------------------------------------
+
+// --------------------------------------
+// class gzstreambuf:
+// --------------------------------------
+
+gzstreambuf*
+gzstreambuf::open( const char* name, int open_mode) {
+  if ( is_open() )
+    return (gzstreambuf*)0;
+  mode = open_mode;
+  // no append nor read/write mode
+  if ((mode & std::ios::ate) || (mode & std::ios::app)
+      || ((mode & std::ios::in) && (mode & std::ios::out)))
+    return (gzstreambuf*)0;
+  char fmode[10];
+  char* fmodeptr = fmode;
+  if ( mode & std::ios::in)
+    *fmodeptr++ = 'r';
+  else
+    if ( mode & std::ios::out)
+      *fmodeptr++ = 'w';
+  *fmodeptr++ = 'b';
+  *fmodeptr = '\0';
+  file = gzopen( name, fmode);
+  if (file == 0)
+    return (gzstreambuf*)0;
+  opened = 1;
+  return this;
+}
+  
+gzstreambuf *
+gzstreambuf::close() {
+  if ( is_open()) {
+    sync();
+    opened = 0;
+    if ( gzclose( file) == Z_OK)
+      return this;
+  }
+  return (gzstreambuf*)0;
+}
+  
+int
+gzstreambuf::underflow() { // used for input buffer only
+  if ( gptr() && ( gptr() < egptr()))
+    return * reinterpret_cast<unsigned char *>( gptr());
+  
+  if ( ! (mode & std::ios::in) || ! opened)
+    return EOF;
+  // Josuttis' implementation of inbuf
+  int n_putback = gptr() - eback();
+  if ( n_putback > 4)
+    n_putback = 4;
+  memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback);
+  
+  int num = gzread( file, buffer+4, gzbufferSize-4);
+  if (num <= 0) // ERROR or EOF
+    return EOF;
+  
+  // reset buffer pointers
+  setg( buffer + (4 - n_putback),   // beginning of putback area
+	buffer + 4,                 // read position
+	buffer + 4 + num);          // end of buffer
+  
+  // return next character
+  return * reinterpret_cast<unsigned char *>( gptr());    
+}
+  
+int
+gzstreambuf::flush_buffer() {
+  // Separate the writing of the buffer from overflow() and
+  // sync() operation.
+  int w = pptr() - pbase();
+  if ( gzwrite( file, pbase(), w) != w)
+    return EOF;
+  pbump( -w);
+  return w;
+}
+  
+int
+gzstreambuf::overflow( int c) { // used for output buffer only
+  if ( ! ( mode & std::ios::out) || ! opened)
+    return EOF;
+  if (c != EOF) {
+    *pptr() = c;
+    pbump(1);
+  }
+  if ( flush_buffer() == EOF)
+    return EOF;
+  return c;
+}
+  
+int
+gzstreambuf::sync() {
+  // Changed to use flush_buffer() instead of overflow( EOF)
+  // which caused improper behavior with std::endl and flush(),
+  // bug reported by Vincent Ricard.
+  if ( pptr() && pptr() > pbase()) {
+    if ( flush_buffer() == EOF)
+      return -1;
+  }
+  return 0;
+}
+  
+  
+  // --------------------------------------
+  // class gzstreambase:
+// --------------------------------------
+
+gzstreambase::gzstreambase( const char* name, int mode)
+{
+  init( &buf);
+  open( name, mode);
+}
+  
+  gzstreambase::~gzstreambase()
+  {
+    buf.close();
+  }
+  
+  void
+  gzstreambase::open( const char* name, int open_mode) {
+    if ( ! buf.open( name, open_mode))
+      clear( rdstate() | std::ios::badbit);
+}
+
+void gzstreambase::close() {
+    if ( buf.is_open())
+        if ( ! buf.close())
+            clear( rdstate() | std::ios::badbit);
+}
+
+#ifdef GZSTREAM_NAMESPACE
+} // namespace GZSTREAM_NAMESPACE
+#endif
+
+// ============================================================================
+// EOF //
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.h	(revision 2961)
@@ -38,8 +38,8 @@
 	/** See Get
 	*/
-	inline void SetMatrix(const Matrix4x4 &trafo) { mMatrix = trafo; }
+	inline void SetMatrix(const Matrix4x4 &trafo) { mIsIdentity = false; mMatrix = trafo; }
 	/** Right multiplies with the given matrix.
 	*/
-	inline void MultMatrix(const Matrix4x4 &trafo);
+	void MultMatrix(const Matrix4x4 &trafo);
 	/** Resets trafo to identiy.
 	*/
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.h	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.h	(revision 2961)
@@ -1,4 +1,4 @@
-#ifndef __ObjConverter_H
-#define __ObjConverter_H
+#ifndef _OBJCONVERTER_H
+#define _OBJCONVERTER_H
 
 #include "common.h"
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 2961)
@@ -42,4 +42,5 @@
 	if (!hasTrafo)
 	{
+		// identity
 		trafo = new Transform3();
 	}
@@ -72,4 +73,5 @@
 		str.read(reinterpret_cast<char *>(&numShapes), sizeof(int));
 
+		
 		LODLevel *lodLevel = new LODLevel(dist);
 
@@ -102,10 +104,9 @@
 	int numTextures;
 	str.read(reinterpret_cast<char *>(&numTextures), sizeof(int));
-
+	
 	for (int i = 0; i < numTextures; ++ i)
 	{
-		// texture
+		// load texture name
 		int texnameSize;
-
 		str.read(reinterpret_cast<char *>(&texnameSize), sizeof(int));
 
@@ -201,6 +202,5 @@
 	
 	// end of file reached
-	if (str.eof())
-		return NULL;
+	if (str.eof()) return NULL;
 
 	//cout << "vertexcount: " << vertexCount << endl;
@@ -218,5 +218,5 @@
 	{
 		texcoords = new float[texCoordCount * 2];
-		str.read(reinterpret_cast<char *>(texcoords), sizeof(float) * vertexCount * 2);
+		str.read(reinterpret_cast<char *>(texcoords), sizeof(float) * texCoordCount * 2);
 	}
 	else
@@ -225,15 +225,4 @@
 	}
 	
-#if 0
-	// construct normals
-	for (int i = 0; i < vertexCount; i += 3)
-	{
-		Triangle3 tri(vertices[i], vertices[i + 1], vertices[i + 2]);
-
-		normals[i] = tri.GetNormal();
-		normals[i+1] = tri.GetNormal();
-		normals[i+2] = tri.GetNormal();
-	}
-#endif
 
 	return new Geometry(vertices, normals, texcoords, vertexCount, true);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2960)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 2961)
@@ -114,4 +114,5 @@
 
 	const float scaleFactor = 80.0f;
+	//const float scaleFactor = 5.0f;
 
 	position.z -= 3 * scaleFactor;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2957)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 2961)
@@ -152,6 +152,5 @@
 AxisAlignedBox3 SceneEntity::GetTransformedBoundingBox() const
 {
-	if (mTransform->IsIdentity())
-		return mBox;
+	if (mTransform->IsIdentity()) return mBox;
 
 	Matrix4x4 mat = mTransform->GetMatrix();
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.cpp	(revision 2959)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ObjConverter.cpp	(revision 2961)
@@ -6,5 +6,4 @@
 #include "Material.h"
 #include "Texture.h"
-#include <map>
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2960)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2961)
@@ -1,3 +1,3 @@
-// occquery.cpp : Defines the entry point for the console application.
+// chcdemo.cpp : Defines the entry point for the console application.
 //
 #include "glInterface.h"
@@ -149,6 +149,4 @@
 bool flyMode = true;
 
-SceneEntityContainer skyGeometry;
-
 bool leftKeyPressed = false;
 bool rightKeyPressed = false;
@@ -415,65 +413,66 @@
 
 
+	glEnable(GL_MULTISAMPLE_ARB);
+	glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
+
+	LeftMotion(0, 0);
+	MiddleMotion(0, 0);
+
+	perfGraph = new PerformanceGraph(1000);
+
+	loader = new ResourceManager();
+
+	//const string filename("data/city/model/city.dem");
+	const string filename = string(model_path + "city.dem");
+
+	if (loader->Load(filename, sceneEntities))
+		cout << "scene " << filename << " loaded" << endl;
+	else
+	{
+		cerr << "loading scene " << filename << " failed" << endl;
+		CleanUp();
+		exit(0);
+	}
+
+	const string bvh_filename = string(model_path + "city.bvh");
+	BvhLoader bvhLoader;
+	bvh = bvhLoader.Load(bvh_filename, sceneEntities);
+
+	if (!bvh)
+	{
+		cerr << "loading bvh " << bvh_filename << " failed" << endl;
+		CleanUp();
+		exit(0);
+	}
+
+	
 	Vector3 cubeCenter(470.398f, 240.364f, 182.5f);
-	AxisAlignedBox3 box(cubeCenter - Vector3(2.0f), cubeCenter + Vector3(2.0f));
+	/*AxisAlignedBox3 box(cubeCenter - Vector3(2.0f), cubeCenter + Vector3(2.0f));
 
 	Material *mat = new Material(RgbaColor(1, 0.4, 0.4, 0));
 	Transform3 *tf = new Transform3();
 	cube = SceneEntityConverter().ConvertBox(box, mat, tf);
-
-	//aeroplane = ObjConverter().Load(model_path + "toyplane.obj");
-	//if (!aeroplane)	cerr << "loadig plane failed" << endl;
-
-	skyDome = ObjConverter().Load(model_path + "sky.obj");
-	if (!skyDome) cerr << "loadig plane failed" << endl;
-
-	const float turbitiy = 3.0f;
-	preetham = new SkyPreetham(turbitiy, skyDome);
-
-	glEnable(GL_MULTISAMPLE_ARB);
-	glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
-
-	LeftMotion(0, 0);
-	MiddleMotion(0, 0);
-
-	perfGraph = new PerformanceGraph(1000);
-
-	loader = new ResourceManager();
-
-	//const string filename("data/city/model/city.dem");
-	const string filename = string(model_path + "city.dem");
-
-	if (loader->Load(filename, sceneEntities))
-		cout << "scene " << filename << " loaded" << endl;
+*/
+
+	Matrix4x4 transl = TranslationMatrix(cubeCenter);
+	
+	const string aeroplaneStr = model_path + "toyplane.dem";
+
+	SceneEntityContainer dummy;
+
+	if (loader->Load(aeroplaneStr, dummy))
+		cout << "successfully loaded " << dummy.size() << " scene entities" << endl;
 	else
 	{
-		cerr << "loading scene " << filename << " failed" << endl;
+		cerr << "loading file " << aeroplaneStr << " failed" << endl;
+
 		CleanUp();
 		exit(0);
 	}
 
-	SceneEntityContainer dummy;
-
-	const string envname = string(model_path + "env.dem");
-
-	if (loader->Load(envname, skyGeometry))
-		cout << "sky box " << filename << " loaded" << endl;
-	else
-	{
-		cerr << "loading sky box " << filename << " failed" << endl;
-		CleanUp();
-		exit(0);
-	}
-
-	const string bvh_filename = string(model_path + "city.bvh");
-	BvhLoader bvhLoader;
-	bvh = bvhLoader.Load(bvh_filename, sceneEntities);
-
-	if (!bvh)
-	{
-		cerr << "loading bvh " << bvh_filename << " failed" << endl;
-		CleanUp();
-		exit(0);
-	}
+	aeroplane = dummy[0];
+	aeroplane->GetTransform()->MultMatrix(transl);
+	dummy.clear();
+
 
 	// set far plane based on scene extent
@@ -488,4 +487,21 @@
 	SkyPreetham::Init(sCgContext);
 
+	
+	string skyDomeStr(model_path + "sky.dem");
+
+	if (loader->Load(skyDomeStr, dummy))
+		cout << "successfully loaded " << dummy.size() << " scene entities" << endl;
+	else
+	{
+		cerr << "loading file " << skyDomeStr << " failed" << endl;
+
+		CleanUp();
+		exit(0);
+	}
+
+	skyDome = dummy[0];
+	
+	const float turbitiy = 3.0f;
+	preetham = new SkyPreetham(turbitiy, skyDome);
 
 	// initialize the render traverser
@@ -628,5 +644,5 @@
 void InitGLstate() 
 {
-	glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
+	glClearColor(1.4f, 0.4f, 0.4f, 1.0f);
 	
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -1087,5 +1103,4 @@
 	
 
-
 	///////////////
 	//-- render sky
@@ -1095,10 +1110,12 @@
 
 	RenderSky();
-	
+
+	//state.Reset(); glEnable(GL_TEXTURE_2D);
+	aeroplane->Render(&state);
+
 
 	if ((renderMethod == RENDER_DEFERRED) ||
 		(renderMethod == RENDER_DEPTH_PASS_DEFERRED))
 	{
-		//glPopAttrib();
 		FrameBufferObject::Release();
 
@@ -1954,5 +1971,4 @@
 void RenderSky()
 {
-	//glEnable(GL_LIGHTING);
 	cgGLEnableProfile(RenderState::sCgVertexProfile);
 
@@ -1960,15 +1976,6 @@
 		state.SetRenderPassType(RenderState::DEFERRED);
 
-	SceneEntityContainer::const_iterator sit, sit_end = skyGeometry.end();
-
-	//	for (sit = skyGeometry.begin(); sit != sit_end; ++ sit)
-	//		(*sit)->Render(&state);
-
-	//cube->Render(&state);
-	//aeroplane->Render(&state);
-	//glEnable(GL_LIGHTING);
-
 	preetham->RenderSkyDome(-light->GetDirection(), camera, &state);
-	
+
 	cgGLDisableProfile(RenderState::sCgVertexProfile);
 	cgGLDisableProfile(RenderState::sCgFragmentProfile);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h	(revision 2913)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h	(revision 2961)
@@ -163,5 +163,5 @@
 // Clears a container (i.e., a vector of pointers) and deletes the pointers
 #ifndef CLEAR_CONTAINER
-#define CLEAR_CONTAINER(co) do { for (size_t _i = 0; _i < (int)(co).size(); ++ _i) { \
+#define CLEAR_CONTAINER(co) do { for (size_t _i = 0; _i < (co).size(); ++ _i) { \
 	DEL_PTR((co)[_i]);} \
 	(co).clear(); } \
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter.vcproj	(revision 2961)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter.vcproj	(revision 2961)
@@ -0,0 +1,217 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8,00"
+	Name="Converter"
+	ProjectGUID="{93A522E1-76F0-4D46-9C97-30DC2DDB531D}"
+	RootNamespace="Converter"
+	Keyword="Win32Proj"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalOptions=" /D &quot;_CRT_SECURE_NO_WARNINGS&quot;"
+				Optimization="0"
+				AdditionalIncludeDirectories="libs\Zlib\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="zlib.lib"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="libs\Zlib\lib"
+				IgnoreDefaultLibraryNames="libCMT"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalOptions=" /D &quot;_CRT_SECURE_NO_WARNINGS&quot;"
+				AdditionalIncludeDirectories="libs\Zlib\include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="zlib.lib"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="libs\Zlib\lib"
+				IgnoreDefaultLibraryNames="libCMT"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\Converter\gzstream.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Converter\main.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Converter\ObjConverter.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\Converter\gzstream.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Converter\ObjConverter.h"
+				>
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2960)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2961)
@@ -248,12 +248,4 @@
 			</File>
 			<File
-				RelativePath=".\src\ObjConverter.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\src\ObjConverter.h"
-				>
-			</File>
-			<File
 				RelativePath=".\src\PerformanceGraph.cpp"
 				>
