summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-04-09 14:31:18 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-04-09 14:31:18 +0200
commite9d6ab657235ebbf3eb9fcb35537c9b2181a1360 (patch)
tree7607687d7c778a4a76a4ecc70f119f02e557bc48 /main.cpp
parent095be9811eaccd92cee156b4c486fb92b77cdcd2 (diff)
Moved from dynamic LOD to chunked loading.
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp77
1 files changed, 40 insertions, 37 deletions
diff --git a/main.cpp b/main.cpp
index eee70dd..c0871a5 100644
--- a/main.cpp
+++ b/main.cpp
@@ -102,26 +102,6 @@ int main(int argc, char **argv) {
case SDLK_t:
terrain = !terrain;
break;
- case SDLK_KP_PLUS:
- case SDLK_PLUS:
- scene.qt->create_nodes(scene.qt->levels+1);
- break;
- case SDLK_KP_MINUS:
- case SDLK_MINUS:
- if(scene.qt->levels > 1) {
- scene.qt->create_nodes(scene.qt->levels-1);
- }
- break;
- case SDLK_KP_MULTIPLY:
- node = scene.qt->find(scene.pos.x, scene.pos.z);
- node->parent->merge();
- scene.qt->make_vbo();
- break;
- case SDLK_KP_DIVIDE:
- node = scene.qt->find(scene.pos.x, scene.pos.z);
- node->subdivide();
- scene.qt->make_vbo();
- break;
case SDLK_SPACE:
scene.yvel = .05;
break;
@@ -131,9 +111,6 @@ int main(int argc, char **argv) {
case SDLK_u:
scene.update();
break;
- case SDLK_c:
- scene.qt->fix_cracks();
- break;
default:
break;
}
@@ -216,7 +193,7 @@ int main(int argc, char **argv) {
scene.yvel = 0;
}
}
- move_str = (boost::format("%s %.2f,%.2f %.2fx%.2f %d") % scene.pos.str() % node->x % node->y % node->width % node->height % node->level).str();
+ move_str = (boost::format("%s %.2f,%.2f %.2fx%.2f") % scene.pos.str() % node->x % node->y % node->width % node->height).str();
if(last_node != node) {
last_node = node;
@@ -231,21 +208,42 @@ int main(int argc, char **argv) {
//const float light_pos[4] = {0, 1, 0, 0};
//glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
+ unsigned int chunks_rendered = 0;
if(terrain) {
program.use();
glBindTexture(GL_TEXTURE_2D, grass_texture);
glEnable(GL_TEXTURE_2D);
- glBindBuffer(GL_ARRAY_BUFFER, scene.qt->vbo_object);
+ //for(int i = 0; i < scene.qt->chunk_count; i++) {
+ std::queue<Quadtree::QuadChunk*> q;
+ q.push(scene.qt->root);
+ while(!q.empty()) {
+ Quadtree::QuadChunk *chunk = q.front();
+ q.pop();
+ if(!chunk->nodes) {
+ for(int i = 0; i < 4; i++)
+ q.push(chunk->children[i]);
+ continue;
+ } else if(!chunk->vbo_object)
+ continue;
+ chunks_rendered++;
+ //std::cout << (boost::format("vertices: %d nodes: %d") % scene.qt->chunks[i]->vertices % scene.qt->chunks[i]->node_count).str() << std::endl;
+ //glBindBuffer(GL_ARRAY_BUFFER, scene.qt->vbo_object);
+ //glBindBuffer(GL_ARRAY_BUFFER, scene.qt->chunks[i]->vbo_object);
+ glBindBuffer(GL_ARRAY_BUFFER, chunk->vbo_object);
glVertexPointer(3, GL_FLOAT, 0, NULL);
- glNormalPointer(GL_FLOAT, 0, (GLvoid*)(scene.qt->vertices*3*sizeof(float)));
- glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*)(scene.qt->vertices*3*sizeof(float)*2));
+ //glNormalPointer(GL_FLOAT, 0, (GLvoid*)(scene.qt->vertices*3*sizeof(float)));
+ glNormalPointer(GL_FLOAT, 0, (GLvoid*)(chunk->vertices*3*sizeof(float)));
+ //glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*)(scene.qt->vertices*3*sizeof(float)*2));
+ glTexCoordPointer(2, GL_FLOAT, 0, (GLvoid*)(chunk->vertices*3*sizeof(float)*2));
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glDrawArrays(GL_TRIANGLES, 0, scene.qt->vertices);
+ //glDrawArrays(GL_TRIANGLES, 0, scene.qt->vertices);
+ glDrawArrays(GL_TRIANGLES, 0, chunk->vertices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
glDisable(GL_TEXTURE_2D);
glUseProgram(0);
}
@@ -254,16 +252,19 @@ int main(int argc, char **argv) {
glColor3f(0, 0, 0);
else
glColor3f(1, 1, 1);
- std::queue<Quadtree::QuadNode*> q;
+ std::queue<Quadtree::QuadChunk*> q;
q.push(scene.qt->root);
while(!q.empty()) {
- Quadtree::QuadNode *node = q.front();
+ Quadtree::QuadChunk *chunk = q.front();
q.pop();
- if(node->vertex_array) {
- grid ? node->draw_grid() : node->draw();
- } else
+ if(!chunk->nodes) {
for(int i = 0; i < 4; i++)
- q.push(node->children[i]);
+ q.push(chunk->children[i]);
+ continue;
+ } else if(chunk->vbo_object) {
+ for(unsigned int i = 0; i < chunk->node_count; i++)
+ chunk->nodes[i]->draw_grid();
+ }
}
}
@@ -287,8 +288,10 @@ int main(int argc, char **argv) {
float height = font->LineHeight();
glColor3f(1, 1, 1);
glTranslatef(0, video::height-height, 0);
- font->Render((boost::format("%dx%d %d levels %d nodes tree creation time: %f steps: %d update: %d")
- % scene.qt->width % scene.qt->height % scene.qt->levels % scene.qt->nodes % scene.qt->init_time % steps % scene.qt->thread_running).str().c_str());
+ font->Render((boost::format("%dx%d chunks: %d steps: %d")
+ % scene.qt->width % scene.qt->height % chunks_rendered % steps).str().c_str());
+ //font->Render((boost::format("%dx%d %d levels %d nodes tree creation time: %f steps: %d update: %d")
+ // % scene.qt->width % scene.qt->height % scene.qt->levels % scene.qt->nodes % scene.qt->init_time % steps % scene.qt->thread_running).str().c_str());
//glTranslatef(0, height, 0);
//font->Render((boost::format("selected: %x") % selected).str().c_str());
glTranslatef(0, -height, 0);
@@ -301,7 +304,7 @@ int main(int argc, char **argv) {
SDL_GL_SwapBuffers();
- usleep(1000);
+ SDL_Delay(1);
}
video::free();