From 0986cf8f33df8926dd8da67f98ed18f696141313 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 11 Apr 2011 22:06:54 +0200 Subject: Draw a selection marker on the terrain. --- scene.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'scene.cpp') diff --git a/scene.cpp b/scene.cpp index 180c90d..f994627 100644 --- a/scene.cpp +++ b/scene.cpp @@ -35,12 +35,15 @@ Scene::Scene() { glUniform1i(tex1loc, 1); GLint tex2loc = glGetUniformLocation(terrain_program.get_program(), "tex[2]"); glUniform1i(tex2loc, 2); + GLint markloc = glGetUniformLocation(terrain_program.get_program(), "marktex"); + glUniform1i(markloc, 3); glUseProgram(0); /* load textures */ grass_texture = load_texture("textures/zooboing-366-grass.jpg"); rock_texture = load_texture("textures/zooboing-825-stone-modified.jpg"); soil_texture = load_texture("textures/zooboing-469-sand-modified.jpg"); + marker_texture = load_texture("textures/cross.png"); /* load heightmap */ SDL_Surface *hm = IMG_Load("heightmap.png"); @@ -250,7 +253,6 @@ void Scene::render() { CEGUI::System::getSingleton().injectTimePulse(0.001*(float)steps); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glLoadIdentity(); video::persp(); unsigned char *keystate = SDL_GetKeyState(NULL); @@ -316,6 +318,13 @@ void Scene::render() { unsigned int chunks_rendered = 0; if(terrain) { terrain_program.use(); + GLint show_sel = glGetUniformLocation(terrain_program.get_program(), "show_sel"); + glUniform1i(show_sel, show_selection ? 1 : 0); + if(show_selection) { + GLint selpos = glGetUniformLocation(terrain_program.get_program(), "selpos"); + glUniform3f(selpos, selected.x, selected.y, selected.z); + } + glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); @@ -327,6 +336,9 @@ void Scene::render() { glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, soil_texture); + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, marker_texture); + std::queue q; q.push(qt->root); while(!q.empty()) { @@ -386,17 +398,6 @@ void Scene::render() { selected = Vector3(px, py, pz); show_selection = true; } - if(show_selection) { - glColor3f(1, 0, 0); - glBegin(GL_TRIANGLE_FAN); - glVertex3f(selected.x, selected.y, selected.z); - glVertex3f(selected.x+.5, selected.y+1, selected.z-.5); - glVertex3f(selected.x+.5, selected.y+1, selected.z+.5); - glVertex3f(selected.x-.5, selected.y+1, selected.z+.5); - glVertex3f(selected.x-.5, selected.y+1, selected.z-.5); - glVertex3f(selected.x+.5, selected.y+1, selected.z-.5); - glEnd(); - } video::ortho(); float height = font->LineHeight(); -- cgit v1.2.3