summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/main.cpp b/main.cpp
index 9f3bf15..cf7c3b9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,6 +2,7 @@
#include "scene.h"
#include "vector.h"
#include "quadtree.h"
+#include "shader.h"
#include <SDL_image.h>
#include <FTGL/ftgl.h>
@@ -123,6 +124,12 @@ int main(int argc, char **argv) {
video::width = 1280;
video::height = 720;
video::init();
+ GLShaderProgram program;
+ GLVertexShader terrain_vertex("terrain_vertex.glsl");
+ GLFragmentShader terrain_fragment("terrain_fragment.glsl");
+ program.attach(terrain_vertex);
+ program.attach(terrain_fragment);
+ program.link();
font = new FTTextureFont("font.ttf");
font->FaceSize(10);
@@ -139,6 +146,7 @@ int main(int argc, char **argv) {
Quadtree *qt = new Quadtree(hm->w, hm->h, heightmap, level);
//Quadtree qt(qt_size, qt_size, (int)ceil(sqrt(qt_size)));
+
GLuint grass_texture;
{
SDL_Surface *surface = IMG_Load("Grass0073_3_S.jpg");
@@ -153,7 +161,7 @@ int main(int argc, char **argv) {
glGenTextures(1, &grass_texture);
glBindTexture(GL_TEXTURE_2D, grass_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(image->format->Amask) {
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, image->w, image->h, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
@@ -170,6 +178,7 @@ int main(int argc, char **argv) {
SDL_Event event;
bool running = true;
bool grid = false;
+ bool gravity = true;
SDL_WarpMouse(video::width/2, video::height/2);
unsigned int last_time = SDL_GetTicks();
/*boost::timer t;
@@ -211,6 +220,9 @@ int main(int argc, char **argv) {
case SDLK_SPACE:
scene.yvel = .05;
break;
+ case SDLK_h:
+ gravity = !gravity;
+ break;
default:
break;
}
@@ -271,7 +283,7 @@ int main(int argc, char **argv) {
right++;
}
if(keystate[SDLK_q])
- scene.pos.y -= 0.002*steps;
+ scene.pos.y -= 0.002*steps*(keystate[SDLK_LSHIFT]?10:1);
if(keystate[SDLK_e])
scene.pos.y += 0.002*steps*(keystate[SDLK_LSHIFT]?10:1);
if(moved && (forward || right))
@@ -280,27 +292,30 @@ int main(int argc, char **argv) {
std::string move_str;
Quadtree::QuadNode *node = qt->find(scene.pos.x, scene.pos.z);
if(node) {
- float y = node->get_height(scene.pos.x, scene.pos.z);
- if(scene.pos.y > y && !keystate[SDLK_e])
- scene.yvel -= 9.81 * steps / 85000;
- if(scene.yvel < -.5)
- scene.yvel = -.5;
- scene.pos.y += scene.yvel * steps;
- if(scene.pos.y < y) {
- scene.pos.y = y;
- scene.yvel = 0;
+ if(gravity) {
+ float y = node->get_height(scene.pos.x, scene.pos.z);
+ if(scene.pos.y > y && !keystate[SDLK_e])
+ scene.yvel -= 9.81 * steps / 85000;
+ if(scene.yvel < -.5)
+ scene.yvel = -.5;
+ scene.pos.y += scene.yvel * steps;
+ if(scene.pos.y < y) {
+ scene.pos.y = y;
+ scene.yvel = 0;
+ }
}
- move_str = (boost::format("%s %.2f,%.2f %dx%d %d") % scene.pos.str() % node->x % node->y % node->width % node->height % node->level).str();
+ move_str = (boost::format("%s %.2f,%.2f %.2fx%.2f %d") % scene.pos.str() % node->x % node->y % node->width % node->height % node->level).str();
}
scene.lookat();
glEnable(GL_LIGHTING);
- //const float light_pos[4] = {50, 20, 50, 1};
- const float light_pos[4] = {0, 1, 0, 0};
+ const float light_pos[4] = {50, 100, 50, 1};
+ //const float light_pos[4] = {0, 1, 0, 0};
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
if(!grid) {
+ program.use();
glBindTexture(GL_TEXTURE_2D, grass_texture);
glEnable(GL_TEXTURE_2D);
glBindBuffer(GL_ARRAY_BUFFER, qt->vbo_object);
@@ -314,11 +329,11 @@ int main(int argc, char **argv) {
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisable(GL_TEXTURE_2D);
+ glUseProgram(0);
} else {
std::queue<Quadtree::QuadNode*> q;
q.push(qt->root);
- glBindTexture(GL_TEXTURE_2D, grass_texture);
- glEnable(GL_TEXTURE_2D);
while(!q.empty()) {
Quadtree::QuadNode *node = q.front();
q.pop();
@@ -330,7 +345,6 @@ int main(int argc, char **argv) {
}
}
- glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
float px, py, pz;