diff options
author | Stijn Buys <ingar@osirion.org> | 2010-10-06 12:11:46 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-10-06 12:11:46 +0000 |
commit | 64a2a6d71023ab382c996ccdb8e403660fa19916 (patch) | |
tree | ab6a181c528deda6033ffa9c274ea87bfffffee1 | |
parent | fed29d9ddc3b8372b9c3fe8bffe221a5a55e5ce9 (diff) |
replaces skydomes with skyboxes
-rw-r--r-- | doc/world.html | 16 | ||||
-rw-r--r-- | src/core/zone.cc | 2 | ||||
-rw-r--r-- | src/core/zone.h | 16 | ||||
-rw-r--r-- | src/render/Makefile.am | 10 | ||||
-rw-r--r-- | src/render/draw.cc | 48 | ||||
-rw-r--r-- | src/render/dust.h | 2 | ||||
-rw-r--r-- | src/render/render.cc | 20 | ||||
-rw-r--r-- | src/render/sky.cc | 147 | ||||
-rw-r--r-- | src/render/sky.h | 35 |
9 files changed, 225 insertions, 71 deletions
diff --git a/doc/world.html b/doc/world.html index e94c063..1b5a51f 100644 --- a/doc/world.html +++ b/doc/world.html @@ -115,7 +115,7 @@ zone=brogha <tr> <td class="wide"><i>sky =</i></td> <td class="narrow"><strong>[string]</strong></td> - <td>name of the sky texture in <i>textures/env</i> directory</td> + <td>name of the skybox in <i>textures/sky</i> directory</td> </tr> <tr> <td class="wide"><i>default =</i></td> @@ -133,6 +133,20 @@ sky=sky12 default=yes </pre> +<p> + If you use a skybox, the engine will look in the <i>textures/sky</i> directory for six images named + <i>skybox_up</i>, <i>skybox_down</i>, <i>skybox_left</i>, <i>skybox_right</i>, <i>skybox_front</i> and <i>skybox_back</i>. + The coordinates are setup to match the output of the <A href="http://alexcpeterson.com/spacescape">Spacescape</a> skybox generator +</p> +<p> + If you want to use skyboxes made for quake3 you will have to convert them: +<ul> + <li>The _left and _right images have to be swapped + <li>The _up image has to be rotated, 90 degrees clockwise + <li>The _down image has to be rotated, 90 degrees counter-clockwise +</ul> +</p> + <h3> [entity] </h3> diff --git a/src/core/zone.cc b/src/core/zone.cc index 7fc3f4d..3791b93 100644 --- a/src/core/zone.cc +++ b/src/core/zone.cc @@ -120,7 +120,6 @@ Zone::Zone(std::string const & label) { zone_id = 0; zone_sky.clear(); - zone_sky_texture = 0; zone_defaultview = 0; set_label(label); @@ -129,7 +128,6 @@ Zone::Zone(std::string const & label) Zone::Zone(std::istream & is) { zone_id = 0; - zone_sky_texture = 0; receive_server_update(is); } diff --git a/src/core/zone.h b/src/core/zone.h index c96f7f9..38a9298 100644 --- a/src/core/zone.h +++ b/src/core/zone.h @@ -85,16 +85,11 @@ public: return zone_id; } - /// the name of the texture to be used as sky for this zone + /// name of the skybox inline std::string const & sky() const { return zone_sky; } - /// texture id for the sky - inline size_t sky_texture() const { - return zone_sky_texture; - } - /// default zone view inline Entity *default_view() { return zone_defaultview; @@ -114,16 +109,11 @@ public: /* ---- mutators ------------------------------------------- */ - /// set the sky texture name to be used for this zone + /// set the skybox name inline void set_sky(std::string const & sky) { zone_sky.assign(sky); } - /// set the texture id for the sky - inline void set_sky_texture(size_t texture) { - zone_sky_texture = texture; - } - ///set the default view inline void set_default_view(Entity *entity) { zone_defaultview = entity; @@ -155,8 +145,6 @@ private: std::string zone_sky; - size_t zone_sky_texture; - Content zone_content; static Registry zone_registry; diff --git a/src/render/Makefile.am b/src/render/Makefile.am index 9fd8f50..4636250 100644 --- a/src/render/Makefile.am +++ b/src/render/Makefile.am @@ -10,8 +10,8 @@ endif librender_la_LDFLAGS = -avoid-version -no-undefined @GL_LIBS@ librender_la_LIBADD = $(top_builddir)/src/math/libmath.la librender_la_SOURCES = camera.cc draw.cc dust.cc gl.cc image.cc jpgfile.cc \ - particles.cc pngfile.cc render.cc renderext.cc screenshot.cc state.cc text.cc \ - textures.cc tgafile.cc -noinst_HEADERS = camera.h draw.h dust.h gl.h image.h jpgfile.h particles.h \ - pngfile.h render.h renderext.h screenshot.h state.h text.h \ - textures.h tgafile.h + particles.cc pngfile.cc render.cc renderext.cc screenshot.cc sky.cc \ + state.cc text.cc textures.cc tgafile.cc +noinst_HEADERS = camera.h draw.h dust.h gl.h image.h jpgfile.h \ + particles.h pngfile.h render.h renderext.h screenshot.h sky.h \ + state.h text.h textures.h tgafile.h diff --git a/src/render/draw.cc b/src/render/draw.cc index f5978f7..068c4dc 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -18,6 +18,7 @@ #include "render/draw.h" #include "render/dust.h" #include "render/gl.h" +#include "render/sky.h" #include "math/functions.h" namespace render @@ -136,6 +137,7 @@ void pass_prepare(float seconds) /* ----- Skybox ---------------------------------------------------- */ +/* void draw_sphere_inside(math::Color const & color, float radius) { gl::scale(radius, radius, radius); @@ -152,6 +154,7 @@ void draw_sphere_inside(math::Color const & color, float radius) } } +*/ void draw_pass_sky() { @@ -164,27 +167,7 @@ void draw_pass_sky() if (!core::localplayer()->zone()->sky().size()) return; - if (!core::localplayer()->zone()->sky_texture()) { - - std::string texture_name("textures/env/"); - texture_name.append(core::localplayer()->zone()->sky()); - core::localplayer()->zone()->set_sky_texture(Textures::load(texture_name)); - - if (!core::localplayer()->zone()->sky_texture()) { - core::localplayer()->zone()->set_sky(""); - return; - } - } - - Textures::bind(core::localplayer()->zone()->sky_texture()); - gl::enable(GL_TEXTURE_2D); - gl::push(); - - gl::translate(Camera::eye()); - draw_sphere_inside(math::Color(), 1016.0f); - - gl::pop(); - gl::disable(GL_TEXTURE_2D); + Sky::draw(core::localplayer()->zone()->sky()); } @@ -702,12 +685,16 @@ void draw_model_fragments(model::Model *model, if (material->flags() & model::Material::Environment) { if (!(material->flags() & model::Material::Texture)) { + /* // use sky as envmap if the material defines no texture + // FIXME broken since skybox if (core::localplayer()->zone()->sky_texture()) { Textures::bind(core::localplayer()->zone()->sky_texture()); gl::enable(GL_TEXTURE_2D); use_texture = true; - } else if (use_texture) { + } else + */ + if (use_texture) { gl::disable(GL_TEXTURE_2D); use_texture = false; } @@ -1239,25 +1226,18 @@ void draw(float seconds) glPolygonMode(GL_FRONT, GL_FILL); } + gl::disable(GL_DEPTH_TEST); + gl::depthmask(GL_FALSE); // disable depth buffer writing + + draw_pass_sky(); // draw the skybox + // set vertex array pointers glInterleavedArrays(GL_T2F_N3F_V3F, 0, core::game()->vertexarray()->ptr()); - /* - // this doesnt work - glTexCoordPointer(2, GL_FLOAT, 6 * sizeof(float), core::game()->vertexarray()->ptr()); - glNormalPointer(GL_FLOAT, 5 * sizeof(float), &core::game()->vertexarray()->ptr()[2]); - glVertexPointer(3, GL_FLOAT, 5 * sizeof(float), &core::game()->vertexarray()->ptr()[5]); - */ - // enable vertex arrays glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); - - gl::disable(GL_DEPTH_TEST); - gl::depthmask(GL_FALSE); // disable depth buffer writing - - draw_pass_sky(); // draw the skysphere gl::depthmask(GL_TRUE); // enable writing to the depth buffer gl::enable(GL_DEPTH_TEST); diff --git a/src/render/dust.h b/src/render/dust.h index 4a3b7bd..4653550 100644 --- a/src/render/dust.h +++ b/src/render/dust.h @@ -1,5 +1,5 @@ /* - render/text.h + render/dust.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ diff --git a/src/render/render.cc b/src/render/render.cc index 5a6c6bc..acc9c86 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -21,6 +21,7 @@ #include "render/dust.h" #include "render/render.h" #include "render/screenshot.h" +#include "render/sky.h" #include "render/textures.h" #include "sys/sys.h" @@ -150,14 +151,8 @@ void init(int width, int height) // unload game assets (zone change) void unload() { - // clear zone sky textures - for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { - core::Zone *zone = (*it).second; - if (zone->sky_texture()) { - render::Textures::unload(zone->sky_texture()); - zone->set_sky_texture(0); - } - } + // unload skybox + Sky::unload(); for (core::Entity::Registry::iterator it = core::Entity::registry().begin(); it != core::Entity::registry().end(); it++) { core:: Entity *entity = (*it).second; @@ -179,12 +174,9 @@ void unload() // clear all assets void clear() { - // clear zone sky textures - for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { - core::Zone *zone = (*it).second; - zone->set_sky_texture(0); - } - + // unload skybox + Sky::unload(); + // clear entity models, and globe textures, this will force a reload for (core::Entity::Registry::iterator it = core::Entity::registry().begin(); it != core::Entity::registry().end(); it++) { core::Entity *entity = (*it).second; diff --git a/src/render/sky.cc b/src/render/sky.cc new file mode 100644 index 0000000..e40c4be --- /dev/null +++ b/src/render/sky.cc @@ -0,0 +1,147 @@ +/* + render/sky.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "render/camera.h" +#include "render/sky.h" +#include "render/textures.h" + +namespace render +{ + +size_t Sky::sky_texture_up = 0; +size_t Sky::sky_texture_down = 0; +size_t Sky::sky_texture_left = 0; +size_t Sky::sky_texture_right = 0; +size_t Sky::sky_texture_front = 0; +size_t Sky::sky_texture_back = 0; + +std::string Sky::sky_name; + +void Sky::draw(const std::string & name) +{ + if (sky_name.compare(name) != 0) { + unload(); + } + + if (!sky_name.size()) { + + if (name.size()) { + const std::string basename("textures/sky/" + name); + + sky_texture_up = Textures::load(basename + "_up"); + sky_texture_down = Textures::load(basename + "_down"); + sky_texture_left = Textures::load(basename + "_left"); + sky_texture_right = Textures::load(basename + "_right"); + sky_texture_front = Textures::load(basename + "_front"); + sky_texture_back = Textures::load(basename + "_back"); + } + sky_name.assign(name); + } + + /* + * NOTE + * for quake3 skyboxes: the _left texture is actually the right side of the skybox + */ + gl::push(); + gl::translate(Camera::eye()); + gl::enable(GL_TEXTURE_2D); + gl::color(1.0f, 1.0f, 1.0f, 1.0f); + + // front + Textures::bind(sky_texture_front); + gl::begin(gl::Quads); + gl::texcoord(0, 0); gl::vertex(1, 1, 1); + gl::texcoord(1, 0); gl::vertex(1, -1, 1); + gl::texcoord(1, 1); gl::vertex(1, -1, -1); + gl::texcoord(0, 1); gl::vertex(1, 1, -1); + gl::end(); + + // right + Textures::bind(sky_texture_right); + gl::begin(gl::Quads); + gl::texcoord(0, 0); gl::vertex(1, -1, 1); + gl::texcoord(1, 0); gl::vertex(-1, -1, 1); + gl::texcoord(1, 1); gl::vertex(-1, -1, -1); + gl::texcoord(0, 1); gl::vertex(1, -1, -1); + gl::end(); + + // back + Textures::bind(sky_texture_back); + gl::begin(gl::Quads); + gl::texcoord(0, 0); gl::vertex(-1, -1, 1); + gl::texcoord(1, 0); gl::vertex(-1, 1, 1); + gl::texcoord(1, 1); gl::vertex(-1, 1, -1); + gl::texcoord(0, 1); gl::vertex(-1, -1, -1); + gl::end(); + + // left + Textures::bind(sky_texture_left); + gl::begin(gl::Quads); + gl::texcoord(0, 0); gl::vertex(-1, 1, 1); + gl::texcoord(1, 0); gl::vertex(1, 1, 1); + gl::texcoord(1, 1); gl::vertex(1, 1, -1); + gl::texcoord(0, 1); gl::vertex(-1, 1, -1); + gl::end(); + + // up + Textures::bind(sky_texture_up); + gl::begin(gl::Quads); + gl::texcoord(0, 0); gl::vertex(-1, 1, 1); + gl::texcoord(1, 0); gl::vertex(-1, -1, 1); + gl::texcoord(1, 1); gl::vertex(1, -1, 1); + gl::texcoord(0, 1); gl::vertex(1, 1, 1); + gl::end(); + + // down + Textures::bind(sky_texture_down); + gl::begin(gl::Quads); + gl::texcoord(0, 0); gl::vertex(1, 1, -1); + gl::texcoord(1, 0); gl::vertex(1, -1, -1); + gl::texcoord(1, 1); gl::vertex(-1, -1, -1); + gl::texcoord(0, 1); gl::vertex(-1, 1, -1); + gl::end(); + + gl::pop(); + + gl::disable(GL_TEXTURE_2D); +} + +void Sky::unload() +{ + if (sky_texture_up) { + Textures::unload(sky_texture_up); + sky_texture_up = 0; + } + + if (sky_texture_down) { + Textures::unload(sky_texture_down); + sky_texture_down = 0; + } + + if (sky_texture_left) { + Textures::unload(sky_texture_left); + sky_texture_left = 0; + } + + if (sky_texture_right) { + Textures::unload(sky_texture_right); + sky_texture_right = 0; + } + + if (sky_texture_front) { + Textures::unload(sky_texture_front); + sky_texture_front = 0; + } + + if (sky_texture_back) { + Textures::unload(sky_texture_back); + sky_texture_back = 0; + } + + sky_name.clear(); +} + +} // namespace render diff --git a/src/render/sky.h b/src/render/sky.h new file mode 100644 index 0000000..d922d75 --- /dev/null +++ b/src/render/sky.h @@ -0,0 +1,35 @@ +/* + render/sky.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_RENDER_SKY_H__ +#define __INCLUDED_RENDER_SKY_H__ + +#include <string> + +namespace render +{ + +class Sky { +public: + + static void unload(); + + static void draw(const std::string & name); + +private: + + static size_t sky_texture_up; + static size_t sky_texture_down; + static size_t sky_texture_left; + static size_t sky_texture_right; + static size_t sky_texture_front; + static size_t sky_texture_back; + + static std::string sky_name; +}; + +} // namespace render +#endif // __INCLUDED_RENDER_SKY_H__
\ No newline at end of file |