From: Charles McGarvey Date: Mon, 21 Jun 2010 21:47:41 +0000 (-0600) Subject: converted image management to resource handles X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=382626aad0a683ed8642a6a807eea743db45f7f8;p=chaz%2Fyoink converted image management to resource handles --- diff --git a/Makefile b/Makefile index 95ed652..b5a149f 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ COMMAND_LDX = $(CXX) $(LDFLAGS) $(LF_TGT) -o $@ $^ $(LL_TGT) $(LIBS) COMMAND_CCLD = $(COMPILE) $(CC) $(CFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS) COMMAND_CXXLD = $(COMPILE) $(CXX) $(CXXFLAGS) $(CF_TGT) $(LDFLAGS) $(LF_TGT) -o $@ $< $(LL_TGT) $(LIBS) COMMAND_AR = $(AR) rcs $@ $^; $(RANLIB) $@ -COMMAND_RC = $(WINDRES) $(DDEFINES) $(DF_TGT) -o $@ -i $< +COMMAND_RC = $(WINDRES) -I. $(DF_TGT) -o $@ -i $< COMMAND_INSTALL = ./tools/install.sh -m $1 $2 -d $3 COMMAND_RM = rm -f $1 COMMAND_IN = sed -f config.sed <"$1" >"$2" @@ -101,15 +101,15 @@ SHELL_LINE_PREFIX = else DO_CC = @echo " CC $@"; $(COMMAND_CC) DO_CXX = @echo " CXX $@"; $(COMMAND_CXX) -DO_LD = @echo " LD $@"; $(COMMAND_LD) -DO_LDX = @echo " LD $@"; $(COMMAND_LDX) -DO_CCLD = @echo " CCLD $@"; $(COMMAND_CCLD) -DO_CXXLD = @echo " CXXLD $@"; $(COMMAND_CXXLD) +DO_LD = @echo " LINK $@"; $(COMMAND_LD) +DO_LDX = @echo " LINK $@"; $(COMMAND_LDX) +DO_CCLD = @echo " LINK $@"; $(COMMAND_CCLD) +DO_CXXLD = @echo " LINK $@"; $(COMMAND_CXXLD) DO_AR = @echo " AR $@"; $(COMMAND_AR) DO_RC = @echo " RC $@"; $(COMMAND_RC) DO_INSTALL = @echo " CP $2"; $(COMMAND_INSTALL) DO_RM = @echo " RM $1"; $(COMMAND_RM) -DO_IN = @echo " MAKE $2"; $(COMMAND_IN) +DO_IN = @echo " GEN $2"; $(COMMAND_IN) SHELL_LINE_PREFIX = @ endif diff --git a/configure b/configure index d443516..9f97b64 100755 --- a/configure +++ b/configure @@ -71,8 +71,8 @@ end -- Setup a temporary file to collect error messages. -- -error_log = "config.log" -os.remove(error_log) +config_log = "config.log" +os.remove(config_log) -- @@ -89,10 +89,10 @@ function die(...) for _,value in ipairs(arg) do print("fatal: "..tostring(value)) end - if file_exists(error_log) then + if file_exists(config_log) then print() print("Look through the file `config.log' for more information:\n") - os.execute("tail "..error_log) + os.execute("tail "..config_log) end os.exit(1) end @@ -100,7 +100,8 @@ end -- Execute a command and return its output or nil if the command failed to -- run. function backtick_run(command) - local fd = io.popen(command.." 2>>"..error_log) + os.execute("echo '# "..command.."' >>"..config_log) + local fd = io.popen(command.." 2>>"..config_log) if fd then local stdout = fd:read("*l") fd:close() @@ -112,7 +113,8 @@ end -- Try to execute a command and return true if the command finished -- successfully (with an exit code of zero). function try_run(command) - return os.execute(command.." >/dev/null 2>>"..error_log) == 0 + os.execute("echo '# "..command.."' >>"..config_log) + return os.execute(command.." >/dev/null 2>>"..config_log) == 0 end -- Remove the whitespace surrounding a string. @@ -388,7 +390,7 @@ else end -- Check for CXX. -tmpname = os.tmpname()..".c" +tmpname = os.tmpname()..".cpp" tmpfile, err = io.open(tmpname, "w") if tmpfile then tmpfile:write([[ diff --git a/src/Character.cc b/src/Character.cc index 01b4753..ccb2f97 100644 --- a/src/Character.cc +++ b/src/Character.cc @@ -98,37 +98,27 @@ void Character::update(moof::scalar t, moof::scalar dt) aabb_.init(a, b); sphere_.init(center, a); + + int frame = animation.getFrame(); + tilemap.tile(frame); } void Character::draw(moof::scalar alpha) const { moof::state2 state = moof::rigid_body2::state(alpha); - moof::vector2 position = state.position; - - //glColor3f(1.0f, 1.0f, 1.0f); - tilemap.bind(); - - int frame = animation.getFrame(); - moof::texture::orientation orientation = moof::texture::normal; + const moof::vector2& position = state.position; - if (state_.velocity[0] < 0.0) orientation = moof::texture::reverse; + const moof::scalar s = 0.5; - moof::scalar coords[8]; - tilemap.tile_coordinates(frame, coords, orientation); + moof::vector3 coords[4]; - moof::scalar s = 0.5; + coords[0] = moof::vector3(position[0] - s, position[1] - s, SCALAR(0.0)); + coords[1] = moof::vector3(position[0] + s, position[1] - s, SCALAR(0.0)); + coords[2] = moof::vector3(position[0] + s, position[1] + s, SCALAR(0.0)); + coords[3] = moof::vector3(position[0] - s, position[1] + s, SCALAR(0.0)); - glBegin(GL_TRIANGLE_FAN); - glTexCoord(coords[0], coords[1]); - glVertex(position[0]-s, position[1]-s); - glTexCoord(coords[2], coords[3]); - glVertex(position[0]+s, position[1]-s); - glTexCoord(coords[4], coords[5]); - glVertex(position[0]+s, position[1]+s); - glTexCoord(coords[6], coords[7]); - glVertex(position[0]-s, position[1]+s); - glEnd(); + tilemap.draw(coords); } diff --git a/src/Character.hh b/src/Character.hh index 651cc88..bdbdb29 100644 --- a/src/Character.hh +++ b/src/Character.hh @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include "Animation.hh" @@ -51,8 +51,8 @@ public: //virtual int getOctant(const moof::Aabb<3>& aabb) const; - moof::texture tilemap; - Animation animation; + moof::sprite tilemap; + Animation animation; }; diff --git a/src/GameLayer.cc b/src/GameLayer.cc index 8299d63..86b8710 100644 --- a/src/GameLayer.cc +++ b/src/GameLayer.cc @@ -187,7 +187,7 @@ void GameLayer::draw(moof::scalar alpha) const state_.camera.upload_to_gl(alpha); // DRAW THE SCENE - moof::texture::reset_binding(); + moof::image::reset_binding(); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); diff --git a/src/Hud.cc b/src/Hud.cc index d5ed412..58bc721 100644 --- a/src/Hud.cc +++ b/src/Hud.cc @@ -17,12 +17,11 @@ #include "Hud.hh" -ProgressBar::ProgressBar(const moof::texture& tilemap, int index) : +ProgressBar::ProgressBar(const moof::sprite& tilemap, int index) : mProgress(0.0), - mTilemap(tilemap) + mTilemap(tilemap, index) { - tilemap.tile_coordinates(index, mTexCoords); - + // TODO this is now broken moof::scalar half = (mTexCoords[2] - mTexCoords[0]) / 2.0 + mTexCoords[0]; mMidCoords[0] = half - 0.01; mMidCoords[1] = half + 0.01; @@ -105,8 +104,8 @@ void ProgressBar::draw(moof::scalar alpha) const Hud::Hud(GameState& state) : state_(state), - mBar1(moof::texture("StatusBars"), 0), - mBar2(moof::texture("StatusBars"), 2), + mBar1(moof::sprite("StatusBars"), 0), + mBar2(moof::sprite("StatusBars"), 2), mFont("Font") { moof::video* video = moof::video::current(); diff --git a/src/Hud.hh b/src/Hud.hh index 7cf2504..1bb5576 100644 --- a/src/Hud.hh +++ b/src/Hud.hh @@ -20,7 +20,7 @@ #include #include //#include -#include +#include #include #include "GameState.hh" @@ -34,7 +34,7 @@ class ProgressBar : public moof::drawable { public: - ProgressBar(const moof::texture& tilemap, int index); + ProgressBar(const moof::sprite& tilemap, int index); void resize(const moof::rectangle& rect); @@ -49,7 +49,7 @@ private: moof::vector2 mVertices[8]; moof::scalar mWidth; - moof::texture mTilemap; + moof::sprite mTilemap; moof::scalar mTexCoords[8]; moof::scalar mMidCoords[2]; }; @@ -97,7 +97,7 @@ private: ProgressBar mBar2; unsigned mNumber; - moof::texture mFont; + moof::sprite mFont; moof::matrix4 mProjection; }; diff --git a/src/Main.cc b/src/Main.cc index adda533..046c7bc 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -216,9 +216,9 @@ void Main::printInfo(int argc, char* argv[]) #ifdef YOINK_GITHEAD << " Commit: "YOINK_GITHEAD << std::endl #endif - << " Version: "PACKAGE_VERSION << std::endl + << " Version: " << PACKAGE_VERSION << std::endl << " Built: " << COMPILE_TIME << std::endl - << " Compiler: "COMPILER_STRING << std::endl + << " Compiler: " << COMPILER_STRING << std::endl << " Assets: " << assets << std::endl << "Build options: " #ifndef HAVE_CLOCK_GETTIME @@ -272,8 +272,21 @@ void goodbye() } +#include +#include +#include + + int main(int argc, char* argv[]) { + //moof::backend backend; + //moof::resource::add_search_paths(Main::getSearchPath()); + + //moof::image hey("textures/AlienWarrior.png"); + + //return 0; + + // FIXME: This is temporary. moof::timer reloadTimer(boost::bind(&moof::resource::reload_as_needed), SCALAR(2.0), @@ -307,10 +320,12 @@ int main(int argc, char* argv[]) try { - std::string iconPath(PACKAGE".png"); - iconPath = moof::resource::find_file(iconPath); - moof::image icon(iconPath); - icon.set_as_icon(); + //std::string iconPath(PACKAGE".png"); + //iconPath = moof::resource::find_file(iconPath); + //moof::image icon(iconPath); + //icon.set_as_icon(); + moof::image_handle icon(PACKAGE".png"); + if (icon) icon->set_as_icon(); class moof::video::attributes attributes(settings); moof::video video(PACKAGE_STRING, attributes); diff --git a/src/Scene.cc b/src/Scene.cc index 2d8f120..c756ec8 100644 --- a/src/Scene.cc +++ b/src/Scene.cc @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "Character.hh" #include "Scene.hh" @@ -41,7 +41,7 @@ struct Scene::impl : public moof::manager Quad(const moof::vector3* vertices[4], const std::string& texture, int tileIndex) : - mTilemap(texture), + mTilemap(texture, tileIndex), mBlending(false), mFog(false), mSurface(NONE) @@ -55,17 +55,6 @@ struct Scene::impl : public moof::manager //} } - if (!mTilemap.tile_coordinates(tileIndex, mTexCoords)) - { - moof::log_warning << "no index " << tileIndex << - " in texture " << texture << std::endl; - - mTexCoords[0] = mTexCoords[1] = - mTexCoords[3] = mTexCoords[6] = 0.0; - mTexCoords[2] = mTexCoords[4] = - mTexCoords[5] = mTexCoords[7] = 1.0; - } - aabb_.enclose_vertices(mVertices, 4); sphere_.point = aabb_.center(); sphere_.radius = (aabb_.min - sphere_.point).length(); @@ -106,12 +95,7 @@ struct Scene::impl : public moof::manager } //glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - mTilemap.bind(); - - glVertexPointer(3, GL_SCALAR, 0, mVertices[0].data()); - glTexCoordPointer(2, GL_SCALAR, 0, mTexCoords); - - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + mTilemap.draw(mVertices); glDisable(GL_BLEND); glDisable(GL_FOG); @@ -123,10 +107,9 @@ struct Scene::impl : public moof::manager } - moof::vector3 mVertices[4]; - moof::scalar mTexCoords[8]; + moof::vector3 mVertices[4]; - moof::texture mTilemap; + moof::sprite mTilemap; bool mBlending; bool mFog; @@ -135,8 +118,8 @@ struct Scene::impl : public moof::manager - moof::matrix4 mTransform; - std::string mTexture; + moof::matrix4 mTransform; + std::string mTexture; std::list< boost::shared_ptr > mObjects; std::list mLines; @@ -348,7 +331,7 @@ struct Scene::impl : public moof::manager vertices[h][wPlus1] = moof::demote(mTransform * moof::vector4(wPlus1, h, 0.0, 1.0)); - if (index == moof::texture::no_tile) continue; + if (index == moof::image::no_tile) continue; const moof::vector3* corners[4] = { &vertices[h][w], diff --git a/src/TilemapFont.cc b/src/TilemapFont.cc index cc995ba..b060ccf 100644 --- a/src/TilemapFont.cc +++ b/src/TilemapFont.cc @@ -14,6 +14,7 @@ #include "TilemapFont.hh" +/* TilemapFont::TilemapFont() : moof::texture("Font") {} @@ -38,4 +39,5 @@ void TilemapFont::tile_coordinates(char symbol, moof::scalar coords[8], moof::texture::tile_coordinates(index, coords, what); } +*/ diff --git a/src/TilemapFont.hh b/src/TilemapFont.hh index 5820a5a..3a7d378 100644 --- a/src/TilemapFont.hh +++ b/src/TilemapFont.hh @@ -17,9 +17,10 @@ * Text on the screen. */ -#include +#include +/* class TilemapFont : public moof::texture { public: @@ -29,6 +30,7 @@ public: void tile_coordinates(char symbol, moof::scalar coords[8], moof::texture::orientation what = moof::texture::normal); }; +*/ #endif // _TILEMAPFONT_HH_ diff --git a/src/moof/aabb.hh b/src/moof/aabb.hh index 64e8968..b2fc4b0 100644 --- a/src/moof/aabb.hh +++ b/src/moof/aabb.hh @@ -24,8 +24,8 @@ #include #include // FIXME: this file is quite broken +#include #include -#include namespace moof { @@ -245,7 +245,7 @@ inline void aabb<3>::draw(scalar alpha) const glVertexPointer(3, GL_SCALAR, 0, vertices); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - texture::reset_binding(); + image::reset_binding(); glDrawElements(GL_QUADS, sizeof(indices), GL_UNSIGNED_BYTE, indices); diff --git a/src/moof/image.cc b/src/moof/image.cc index 93ef6d6..abe1677 100644 --- a/src/moof/image.cc +++ b/src/moof/image.cc @@ -11,8 +11,7 @@ #include // FILE #include // strncmp - -#include +#include #include #include @@ -20,271 +19,345 @@ #include "backend.hh" #include "image.hh" #include "log.hh" -#include "manager.hh" +#include "opengl.hh" +#include "script.hh" +#include "video.hh" namespace moof { -class image::impl : public manager -{ -public: +//static int power_of_two(int input) +//{ + //int value = 1; - explicit impl() : - context_(0), - pixels_(0) {} - - ~impl() - { - SDL_FreeSurface(context_); - delete[] pixels_; - } + //while (value < input) + //{ + //value <<= 1; + //} + //return value; +//} +unsigned image::global_object_ = 0; - void flip() - { - unsigned char* pixels = (Uint8*)(context_->pixels); - unsigned pitch = context_->pitch; - unsigned char line[pitch]; +image::image(const std::string& path) : + pixels_(0), + object_(0), + min_filter_(GL_NEAREST), + mag_filter_(GL_NEAREST), + wrap_s_(GL_CLAMP), + wrap_t_(GL_CLAMP), + tile_width_(1), + tile_height_(1) +{ + FILE* fp = resource::open_file(path); + if (!fp) throw std::runtime_error("image not found at " + path); - int yBegin = 0; - int yEnd = context_->h - 1; + png_byte signature[8]; + size_t bytesRead; - if (SDL_MUSTLOCK(context_)) SDL_LockSurface(context_); - while (yBegin < yEnd) - { - memcpy(line, pixels + pitch * yBegin, pitch); - memcpy(pixels + pitch * yBegin, pixels + pitch * yEnd, pitch); - memcpy(pixels + pitch * yEnd, line, pitch); - yBegin++; - yEnd--; - } - if (SDL_MUSTLOCK(context_)) SDL_UnlockSurface(context_); - } + png_infop pngInfo = 0; + png_infop pngInfoEnd = 0; + png_structp pngObj = 0; - void set_as_icon() const - { - SDL_WM_SetIcon(context_, 0); - } + int bpp; + png_byte colors; + png_bytepp rows = 0; - void init(const std::string& name, bool flipped = false) - { - std::string path(name); + png_textp texts = 0; + int nutext_s; - FILE* fp = resource::open_file(path); - if (!fp) return; + bytesRead = fread(signature, 1, sizeof(signature), fp); + if (bytesRead < sizeof(signature) || + png_sig_cmp(signature, 0, sizeof(signature)) != 0) goto cleanup; - png_byte signature[8]; - size_t bytesRead; + pngObj = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); + if (!pngObj) goto cleanup; - png_infop pngInfo = 0; - png_infop pngInfoEnd = 0; - png_structp pngObj = 0; + pngInfo = png_create_info_struct(pngObj); + if (!pngInfo) goto cleanup; - int width; - int height; - int pitch; - int bpp; - int channels; + pngInfoEnd = png_create_info_struct(pngObj); + if (!pngInfoEnd) goto cleanup; - png_byte colors; - png_bytepp rows = 0; + if (setjmp(png_jmpbuf(pngObj))) goto cleanup; - png_textp texts = 0; - int nutext_s; + png_init_io(pngObj, fp); + png_set_sig_bytes(pngObj, sizeof(signature)); + png_read_info(pngObj, pngInfo); - bytesRead = fread(signature, 1, sizeof(signature), fp); - if (bytesRead < sizeof(signature) || - png_sig_cmp(signature, 0, sizeof(signature)) != 0) goto cleanup; + bpp = png_get_bit_depth(pngObj, pngInfo); + colors = png_get_color_type(pngObj, pngInfo); + switch (colors) + { + case PNG_COLOR_TYPE_PALETTE: + png_set_palette_to_rgb(pngObj); + break; - pngObj = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); - if (!pngObj) goto cleanup; + case PNG_COLOR_TYPE_GRAY: + if (bpp < 8) png_set_expand(pngObj); + break; - pngInfo = png_create_info_struct(pngObj); - if (!pngInfo) goto cleanup; + case PNG_COLOR_TYPE_GRAY_ALPHA: + png_set_gray_to_rgb(pngObj); + break; + } - pngInfoEnd = png_create_info_struct(pngObj); - if (!pngInfoEnd) goto cleanup; + if (bpp == 16) png_set_strip_16(pngObj); - if (setjmp(png_jmpbuf(pngObj))) goto cleanup; + png_read_update_info(pngObj, pngInfo); - png_init_io(pngObj, fp); - png_set_sig_bytes(pngObj, sizeof(signature)); - png_read_info(pngObj, pngInfo); + bpp = png_get_bit_depth(pngObj, pngInfo); + channels_ = png_get_channels(pngObj, pngInfo); + depth_ = bpp * channels_; - bpp = png_get_bit_depth(pngObj, pngInfo); - colors = png_get_color_type(pngObj, pngInfo); - switch (colors) + // read comments + png_get_text(pngObj, pngInfo, &texts, &nutext_s); + for (int i = 0; i < nutext_s; ++i) + { + if (strncmp(texts[i].key, "TextureInfo", 11) == 0) { - case PNG_COLOR_TYPE_PALETTE: - png_set_palette_to_rgb(pngObj); - break; - - case PNG_COLOR_TYPE_GRAY: - if (bpp < 8) png_set_expand(pngObj); - break; - - case PNG_COLOR_TYPE_GRAY_ALPHA: - png_set_gray_to_rgb(pngObj); - break; + set_texture_info(texts[i].text); + break; } + } - if (bpp == 16) png_set_strip_16(pngObj); + width_ = png_get_image_width(pngObj, pngInfo); + height_ = png_get_image_height(pngObj, pngInfo); - png_read_update_info(pngObj, pngInfo); + pitch_ = png_get_rowbytes(pngObj, pngInfo); + pixels_ = new char[width_ * pitch_]; - bpp = png_get_bit_depth(pngObj, pngInfo); - channels = png_get_channels(pngObj, pngInfo); - depth_ = bpp * channels; + rows = new png_bytep[height_]; + for (int i = 0; i < height_; ++i) + { + rows[i] = (png_bytep)(pixels_ + i * channels_ * width_); + } - if (channels == 3) color_mode_ = GL_RGB; - else color_mode_ = GL_RGBA; - - // read comments - png_get_text(pngObj, pngInfo, &texts, &nutext_s); - for (int i = 0; i < nutext_s; ++i) - { - if (strncmp(texts[i].key, "TextureInfo", 11) == 0) - { - comment_ = texts[i].text; - break; - } - } + png_read_image(pngObj, rows); + png_read_end(pngObj, 0); - width = png_get_image_width(pngObj, pngInfo); - height = png_get_image_height(pngObj, pngInfo); +cleanup: - pitch = png_get_rowbytes(pngObj, pngInfo); - pixels_ = new char[width * pitch]; + delete[] rows; + png_destroy_read_struct(pngObj ? &pngObj : 0, + pngInfo ? &pngInfo : 0, + pngInfoEnd ? &pngInfoEnd : 0); + fclose(fp); +} - rows = new png_bytep[height]; - if (flipped) - { - for (int i = 0; i < height; ++i) - { - rows[height - 1 - i] = (png_bytep)(pixels_ + - i * channels * width); - } - } - else - { - for (int i = 0; i < height; ++i) - { - rows[i] = (png_bytep)(pixels_ + i * channels * width); - } - } +image::~image() +{ + unload_from_gl(); + delete[] pixels_; +} - png_read_image(pngObj, rows); - png_read_end(pngObj, 0); - context_ = SDL_CreateRGBSurfaceFrom - ( - pixels_, - width, - height, - bpp * channels, - pitch, +void image::set_as_icon() const +{ + backend backend; + + SDL_Surface* context = SDL_CreateRGBSurfaceFrom + ( + pixels_, + width_, + height_, + depth_, + pitch_, #if SDL_BYTEORDER == SDL_LIL_ENDIAN - 0x000000FF, - 0x0000FF00, - 0x00FF0000, - 0xFF000000 + 0x000000FF, + 0x0000FF00, + 0x00FF0000, + 0xFF000000 #else - 0xFF000000, - 0x00FF0000, - 0x0000FF00, - 0x000000FF + 0xFF000000, + 0x00FF0000, + 0x0000FF00, + 0x000000FF #endif - ); - - cleanup: - - delete[] rows; - png_destroy_read_struct(pngObj ? &pngObj : 0, - pngInfo ? &pngInfo : 0, - pngInfoEnd ? &pngInfoEnd : 0); - fclose(fp); - } - - - SDL_Surface* context_; - char* pixels_; - - unsigned depth_; - GLuint color_mode_; + ); - std::string comment_; + SDL_WM_SetIcon(context, 0); -private: - - backend backend_; -}; - - -image::image(const std::string& name) : - // pass through - impl_(image::impl::instance(name)) {} + SDL_FreeSurface(context); +} -bool image::is_valid() const +bool image::tile_coordinates(int index, scalar coords[8]) const { - return impl_->context_; + // make sure the index represents a real tile + if (index < 0 && index >= tile_width_ * tile_height_) return false; + + scalar w = 1.0 / scalar(tile_width_); + scalar h = 1.0 / scalar(tile_height_); + + coords[0] = scalar(index % tile_width_) * w; + coords[1] = (scalar(tile_height_ - 1) - scalar(index / tile_width_)) * h; + coords[2] = coords[0] + w; + coords[3] = coords[1]; + coords[4] = coords[2]; + coords[5] = coords[1] + h; + coords[6] = coords[0]; + coords[7] = coords[5]; + + return true; } -int image::width() const -{ - return impl_->context_->w; -} -int image::height() const +void image::bind() const { - return impl_->context_->h; -} + ASSERT(video::current() && "should have a video context set"); -unsigned image::depth() const -{ - return impl_->depth_; + if (object_ == 0) + { + upload_to_gl(); + } + if (object_ != global_object_) + { + glBindTexture(GL_TEXTURE_2D, (GLuint)object_); + global_object_ = object_; + } } -unsigned image::pitch() const +void image::reset_binding() { - return impl_->context_->pitch; + ASSERT(video::current() && "should have a video context set"); + + glBindTexture(GL_TEXTURE_2D, 0); + global_object_ = 0; } -GLuint image::mode() const + +/* + * Upload the image to GL so that it will be accessible by a much more + * manageable handle and hopefully reside in video memory. + */ +void image::upload_to_gl() const { - return impl_->color_mode_; + if (object_) + { + // already loaded + return; + } + + glGenTextures(1, (GLuint*)&object_); + glBindTexture(GL_TEXTURE_2D, (GLuint)object_); + + GLuint mode; + if (channels_ == 3) mode = GL_RGB; + else mode = GL_RGBA; + + glTexImage2D + //gluBuild2DMipmaps + ( + GL_TEXTURE_2D, + 0, + mode, + //3, + width_, + height_, + 0, + mode, + GL_UNSIGNED_BYTE, + pixels_ + ); + + set_properties(); + + // we want to know when the GL context is recreated + //dispatcher& dispatcher = dispatcher::global(); + //new_context_ = dispatcher.add_target("video.newcontext", + //boost::bind(&image::context_recreated, this)); + // FIXME this has const issues } -std::string image::comment() const +void image::unload_from_gl() const { - return impl_->comment_; + if (object_) + { + if (object_ == global_object_) + { + global_object_ = 0; + } + + glDeleteTextures(1, (GLuint*)&object_); + object_ = 0; + } } -const char* image::pixels() const +void image::context_recreated() { - return impl_->pixels_; + object_ = global_object_ = 0; + upload_to_gl(); } -char* image::pixels() +/* + * Sets some texture properties such as the filters and external + * coordinate behavior. + */ +void image::set_properties() const { - return impl_->pixels_; + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); } -void image::flip() +void image::set_texture_info(const std::string& info) { - // pass through - impl_->flip(); + script script; + log::import(script); + + script::slot g = script.globals(); + g.set_field("CLAMP", GL_CLAMP); + g.set_field("REPEAT", GL_REPEAT); + g.set_field("LINEAR", GL_LINEAR); + g.set_field("NEAREST", GL_NEAREST); + g.set_field("LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR); + g.set_field("LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST); + g.set_field("NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR); + g.set_field("NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST); + + if (script.do_string(info) != script::success) + { + std::string str; + script[-1].get(str); + log_warning(str); + } + else + { + log_info("loading texture information..."); + + script::slot globals = script.globals(); + globals.get(tile_width_, "tiles_s"); + globals.get(tile_height_, "tiles_t"); + globals.get(min_filter_, "min_filter"); + globals.get(mag_filter_, "mag_filter"); + globals.get(wrap_s_, "wrap_s"); + globals.get(wrap_t_, "wrap_t"); + } } -void image::set_as_icon() const + +class image_resource_loader { - // pass through - impl_->set_as_icon(); -} +public: + + image_resource_loader() + { + resource::register_type("png"); + } + + ~image_resource_loader() + { + resource::unregister_type("png"); + } +}; + +static image_resource_loader loader; } // namespace moof diff --git a/src/moof/image.hh b/src/moof/image.hh index 614e614..82c8f55 100644 --- a/src/moof/image.hh +++ b/src/moof/image.hh @@ -17,56 +17,121 @@ * Defines classes for loading and manipulating images. */ -#include +#include -#include +#include +#include #include namespace moof { -class image; -typedef boost::shared_ptr image_ptr; - -class image : public resource +class image : public boost::noncopyable { public: - static image_ptr alloc(const std::string& name) + static const int no_tile = -1; + + + explicit image(const std::string& path); + + ~image(); + + int width() const { - return image_ptr(new image(name)); + return width_; } - explicit image(const std::string& name); + int height() const + { + return height_; + } - bool is_valid() const; + int depth() const + { + return depth_; + } - int width() const; - int height() const; + int pitch() const + { + return pitch_; + } - unsigned depth() const; - unsigned pitch() const; - GLuint mode() const; + int channels() const + { + return channels_; + } - std::string comment() const; - const char* pixels() const; - char* pixels(); + std::string comment() const + { + return comment_; + } + + const char* pixels() const + { + return pixels_; + } - void flip(); void set_as_icon() const; + /** + * Calculate texture coordinates for a tile at a certain index. Tiles + * are indexed start with zero as the top-left tile and moving across, + * then down. + * \param index The tile index. + * \param coords An array of scalars where the texture coordinates will + * be stored after this call. The first coordinate (u,v) will be in + * the first two places and so on until all four coordinates are + * stored, therefore requiring enough room for an array of eight + * scalars. The winding of the coordinates is always counter-clockwise + * (the GL default). + * \return True if index is valid, false otherwise. + */ + bool tile_coordinates(int index, scalar coords[8]) const; + + + void bind() const; + static void reset_binding(); + + private: - static FILE* open_file(std::string& name); + void upload_to_gl() const; + void unload_from_gl() const; + void context_recreated(); + void set_properties() const; + void set_texture_info(const std::string& info); - class impl; - boost::shared_ptr impl_; + + char* pixels_; + + mutable unsigned object_; + static unsigned global_object_; + + int width_; + int height_; + int depth_; + int pitch_; + int channels_; + + std::string comment_; + + unsigned min_filter_; + unsigned mag_filter_; + unsigned wrap_s_; + unsigned wrap_t_; + int tile_width_; + int tile_height_; + + //mutable dispatcher::handle new_context_; }; +typedef resource_handle image_handle; + } // namespace moof diff --git a/src/moof/line.hh b/src/moof/line.hh index 35ebf29..0ba6bb3 100644 --- a/src/moof/line.hh +++ b/src/moof/line.hh @@ -19,13 +19,13 @@ #include #include +#include #include #include #include #include #include #include -#include namespace moof { @@ -225,7 +225,7 @@ struct line : public drawable, public shape void draw(scalar alpha = 0.0) const { - texture::reset_binding(); + image::reset_binding(); glBegin(GL_LINES); glVertex(a); glVertex(b); @@ -255,7 +255,7 @@ struct polygon : public drawable, public shape void draw(scalar alpha = 0.0) const { - texture::reset_binding(); + image::reset_binding(); glBegin(GL_POLYGON); for (int i = 0; i < D; ++i) { diff --git a/src/moof/ray.hh b/src/moof/ray.hh index 9413f0d..b1f7bdd 100644 --- a/src/moof/ray.hh +++ b/src/moof/ray.hh @@ -19,9 +19,9 @@ */ #include +#include #include #include -#include namespace moof { @@ -60,7 +60,7 @@ struct ray : public drawable vector end = point + 1000.0 * direction; // FIXME: this is kinda cheesy - moof::texture::reset_binding(); + image::reset_binding(); glBegin(GL_LINES); glVertex(point); glVertex(end); diff --git a/src/moof/resource.cc b/src/moof/resource.cc index 314f80b..053fc0b 100644 --- a/src/moof/resource.cc +++ b/src/moof/resource.cc @@ -127,7 +127,7 @@ resource_ptr resource::load(const std::string& path) { std::string extension = stlplus::extension_part(path); - std::string path1 = find_file(path); + std::string path1 = path; if (!find(path1)) { log_error("trying to load missing resource:", path1); @@ -212,21 +212,35 @@ void resource::add_search_paths(const std::string& paths) bool resource::find(const std::string& path) { - std::string file = stlplus::lookup(path, search_paths_, ":"); - log_info("found file", file, "in", search_paths_); - return !stlplus::lookup(path, search_paths_, ":").empty(); + //std::string file = stlplus::lookup(path, search_paths_, ":"); + //log_info("found file", file, "in", search_paths_); + //return !stlplus::lookup(path, search_paths_, ":").empty(); + return find_file(path) != ""; } std::string resource::find_file(const std::string& name) { - log_info("looking for", name, "in", search_paths_); - return stlplus::lookup(name, search_paths_, ":"); + //log_info("looking for", name, "in", search_paths_); + //return stlplus::lookup(name, search_paths_, ":"); + + std::vector paths; + boost::split(paths, search_paths_, boost::is_any_of(":")); + + std::vector::iterator it; + for (it = paths.begin(); it != paths.end(); ++it) + { + *it += "/"; + *it += name; + log_info("looking for", name, "in", *it); + if (stlplus::file_exists(*it)) return *it; + } + + return std::string(); } FILE* resource::open_file(const std::string& path, const std::string& mode) { - std::string file = stlplus::lookup(path, search_paths_, ":"); - return fopen(file.c_str(), mode.c_str()); + return fopen(find_file(path).c_str(), mode.c_str()); } diff --git a/src/moof/resource.hh b/src/moof/resource.hh index f8fd4f6..5f1a71a 100644 --- a/src/moof/resource.hh +++ b/src/moof/resource.hh @@ -285,6 +285,9 @@ public: resource_handle(resource_ptr ptr) : resource_(ptr) {} + explicit resource_handle(const std::string& path) : + resource_(resource::load(path)) {} + /** * Get whether or not the handle is dereferenceable to the type of this diff --git a/src/moof/sound.cc b/src/moof/sound.cc index 853c21a..a6fbf03 100644 --- a/src/moof/sound.cc +++ b/src/moof/sound.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -233,7 +234,7 @@ buffer::retcount_lookup buffer::retain_counts_; // SOUND RESOURCE -class sound_resource +class sound_resource : public boost::noncopyable { public: @@ -252,7 +253,7 @@ public: } - bool read(buffer& buf) + bool read(buffer& buf) const { if (buffer_) { @@ -305,7 +306,7 @@ public: } - bool read(buffer& buf, uint64_t& sample) + bool read(buffer& buf, uint64_t& sample) const { if (ov_pcm_seek_lap(&file_, sample) != 0) { @@ -344,8 +345,8 @@ public: private: - OggVorbis_File file_; - buffer buffer_; + mutable OggVorbis_File file_; + mutable buffer buffer_; }; diff --git a/src/moof/sound.hh b/src/moof/sound.hh index a3c94f1..7fdfd09 100644 --- a/src/moof/sound.hh +++ b/src/moof/sound.hh @@ -53,10 +53,10 @@ public: void loop(bool looping); - void listener_position(const vector3& position); - void listener_velocity(const vector3& velocity); - void listener_orientation(const vector3& forward, - const vector3& up); + static void listener_position(const vector3& position); + static void listener_velocity(const vector3& velocity); + static void listener_orientation(const vector3& forward, + const vector3& up); private: diff --git a/src/moof/sprite.cc b/src/moof/sprite.cc new file mode 100644 index 0000000..7548ab0 --- /dev/null +++ b/src/moof/sprite.cc @@ -0,0 +1,142 @@ + +/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +**] All rights reserved. +* +* vi:ts=4 sw=4 tw=75 +* +* Distributable under the terms and conditions of the 2-clause BSD license; +* see the file COPYING for a complete text of the license. +* +**************************************************************************/ + +#include // FILE +#include // strncmp +#include + +#include +#include + +#include "dispatcher.hh" +#include "log.hh" +#include "opengl.hh" +#include "sprite.hh" + + +namespace moof { + + +sprite::sprite(const std::string& path, int tile) +{ + image_ = resource::load(path); + image_->tile_coordinates(tile, tile_); +} + +sprite::sprite(const image_handle& image, int tile) : + image_(image) +{ + image_->tile_coordinates(tile, tile_); +} + +sprite::sprite(const sprite& sprite, int tile) +{ + // FIXME broken + image_ = sprite.image_; +} + + +void sprite::image(const std::string& path) +{ + image_ = resource::load(path); + // FIXME what about tiles? +} + +void sprite::tile(int tile) +{ + if (image_) image_->tile_coordinates(tile, tile_); +} + + +void sprite::bind() const +{ + if (image_) image_->bind(); +} + +void sprite::reset_binding() +{ + image::reset_binding(); +} + + +void sprite::draw(const vector3 vertices[4]) const +{ + bind(); + + glVertexPointer(3, GL_SCALAR, 0, vertices[0].data()); + glTexCoordPointer(2, GL_SCALAR, 0, tile_); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); +} + + +/* + void min_filter(GLuint filter) + { + bind(); + mMinFilter = filter; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter); + } + + void mag_filter(GLuint filter) + { + bind(); + mMagFilter = filter; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter); + } + + void wrap_s(GLuint wrap) + { + bind(); + mWrapS = wrap; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS); + } + + void wrap_t(GLuint wrap) + { + bind(); + mWrapT = wrap; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT); + } + + +bool sprite::tile_coordinates(int index, scalar coords[8], + orientation orientation) const +{ + if (tile_coordinates(index, coords)) + { + if (orientation & flip) + { + // this looks kinda weird, but it's just swapping in a way that + // doesn't require an intermediate variable + coords[1] = coords[5]; + coords[5] = coords[3]; + coords[3] = coords[7]; + coords[7] = coords[5]; + } + if (orientation & reverse) + { + coords[0] = coords[2]; + coords[2] = coords[6]; + coords[4] = coords[6]; + coords[6] = coords[0]; + } + + return true; + } + + return false; +} +*/ + + +} // namespace moof + diff --git a/src/moof/sprite.hh b/src/moof/sprite.hh new file mode 100644 index 0000000..3cee872 --- /dev/null +++ b/src/moof/sprite.hh @@ -0,0 +1,57 @@ + +/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +**] All rights reserved. +* +* vi:ts=4 sw=4 tw=75 +* +* Distributable under the terms and conditions of the 2-clause BSD license; +* see the file COPYING for a complete text of the license. +* +**************************************************************************/ + +#ifndef _MOOF_SPRITE_HH_ +#define _MOOF_SPRITE_HH_ + +/** + * \file sprite.hh + * Image-loading and OpenGL texture loading. + */ + +#include + +#include +#include + + +namespace moof { + + +class sprite +{ +public: + + sprite() {} + explicit sprite(const std::string& path, int tile = image::no_tile); + explicit sprite(const image_handle& image, int tile = image::no_tile); + explicit sprite(const sprite& sprite, int tile = image::no_tile); + + void image(const std::string& path); + void tile(int tile); + + void bind() const; + static void reset_binding(); + + void draw(const vector3 vertices[4]) const; + + +private: + + image_handle image_; + scalar tile_[8]; +}; + + +} // namespace moof + +#endif // _MOOF_SPRITE_HH_ + diff --git a/src/moof/texture.cc b/src/moof/texture.cc deleted file mode 100644 index 94d792d..0000000 --- a/src/moof/texture.cc +++ /dev/null @@ -1,399 +0,0 @@ - -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** -**] All rights reserved. -* -* vi:ts=4 sw=4 tw=75 -* -* Distributable under the terms and conditions of the 2-clause BSD license; -* see the file COPYING for a complete text of the license. -* -**************************************************************************/ - -#include // FILE -#include // strncmp -#include - -#include -#include - -#include "dispatcher.hh" -#include "manager.hh" -#include "log.hh" -#include "opengl.hh" -#include "script.hh" -#include "texture.hh" -#include "video.hh" - - -namespace moof { - - -/** - * The texture implementation just contains all the information about the - * image which is worth having in memory. The image data itself is not - * worth keeping in memory if the texture has been loaded to GL, but the - * name of the resource is retained so that it can be reloaded if - * necessary. The implementation is a manager so that multiple texture - * objects can share the same internal objects and avoid having duplicate - * textures loaded to GL. - */ - -class texture::impl : public manager -{ - - /** - * Delete the texture (if it is loaded) from GL. - */ - - void unload_from_gl() - { - if (mObject) - { - if (mObject == gObject) - { - gObject = 0; - } - - glDeleteTextures(1, &mObject); - mObject = 0; - } - } - - /** - * If the GL context was recreated, we need to reload the texture. - * This may involve reading it from disk again, but hopefully the OS - * was smart enough to cache it if the client has plenty of RAM. - */ - - void context_recreated() - { - mObject = gObject = 0; - upload_to_gl(); - } - - /** - * This is a helper method used by some of the texture loading code. - * It returns the first power of two which is greater than the input - * value. - */ - - static int power_of_two(int input) - { - int value = 1; - - while (value < input) - { - value <<= 1; - } - return value; - } - - - static void bind_script_constants(script& script) - { - script::slot g = script.globals(); - - g.set_field("CLAMP", GL_CLAMP); - g.set_field("REPEAT", GL_REPEAT); - g.set_field("LINEAR", GL_LINEAR); - g.set_field("NEAREST", GL_NEAREST); - g.set_field("LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR); - g.set_field("LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST); - g.set_field("NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR); - g.set_field("NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST); - } - -public: - - /* - * Construction is initialization. - */ - impl() : - mMinFilter(GL_NEAREST), - mMagFilter(GL_NEAREST), - mWrapS(GL_CLAMP), - mWrapT(GL_CLAMP), - mTilesS(1), - mTilesT(1), - mObject(0) - { - // make sure we have a video context - video* video = video::current(); - ASSERT(video && "should have a video context set"); - - // we want to know when the GL context is recreated - dispatcher& dispatcher = dispatcher::global(); - mNewContextDispatch = dispatcher.add_target("video.newcontext", - boost::bind(&impl::context_recreated, this)); - } - - ~impl() - { - unload_from_gl(); - } - - - void init(const std::string& name) - { - std::string path(name); - - resource::find(path); - - mImage = image::alloc(path); - if (!mImage->is_valid()) - { - throw std::runtime_error("texture not found: " + name); - } - - mImage->flip(); - - script script; - - bind_script_constants(script); - log::import(script); - - if (script.do_string(mImage->comment()) != script::success) - { - std::string str; - script[-1].get(str); - log_warning(str); - } - else - { - log_info("loading tiles from texture", path); - - script::slot globals = script.globals(); - globals.get(mTilesS, "tiles_s"); - globals.get(mTilesT, "tiles_t"); - globals.get(mMinFilter, "min_filter"); - globals.get(mMagFilter, "mag_filter"); - globals.get(mWrapS, "wrap_s"); - globals.get(mWrapT, "wrap_t"); - } - } - - - /* - * Upload the image to GL so that it will be accessible by a much more - * manageable handle and hopefully reside in video memory. - */ - void upload_to_gl() - { - if (mObject) - { - // already loaded - return; - } - - glGenTextures(1, &mObject); - glBindTexture(GL_TEXTURE_2D, mObject); - - glTexImage2D - //gluBuild2DMipmaps - ( - GL_TEXTURE_2D, - 0, - mImage->mode(), - //3, - mImage->width(), - mImage->height(), - 0, - mImage->mode(), - GL_UNSIGNED_BYTE, - mImage->pixels() - ); - - set_properties(); - } - - - /* - * Sets some texture properties such as the filters and external - * coordinate behavior. - */ - void set_properties() - { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT); - } - - void min_filter(GLuint filter) - { - bind(); - mMinFilter = filter; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mMinFilter); - } - - void mag_filter(GLuint filter) - { - bind(); - mMagFilter = filter; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mMagFilter); - } - - void wrap_s(GLuint wrap) - { - bind(); - mWrapS = wrap; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mWrapS); - } - - void wrap_t(GLuint wrap) - { - bind(); - mWrapT = wrap; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mWrapT); - } - - - void bind() - { - if (mObject == 0) - { - upload_to_gl(); - } - if (mObject != gObject) - { - glBindTexture(GL_TEXTURE_2D, mObject); - gObject = mObject; - } - } - - - bool tile_coordinates(int index, scalar coords[8]) const - { - // make sure the index represents a real tile - if (index < 0 && index >= mTilesS * mTilesT) return false; - - scalar w = 1.0 / scalar(mTilesS); - scalar h = 1.0 / scalar(mTilesT); - - coords[0] = scalar(index % mTilesS) * w; - coords[1] = (scalar(mTilesT - 1) - scalar(index / mTilesS)) * h; - coords[2] = coords[0] + w; - coords[3] = coords[1]; - coords[4] = coords[2]; - coords[5] = coords[1] + h; - coords[6] = coords[0]; - coords[7] = coords[5]; - - return true; - } - - image_ptr mImage; - - GLuint mMinFilter; ///< Minification filter. - GLuint mMagFilter; ///< Magnification filter. - GLuint mWrapS; ///< Wrapping behavior horizontally. - GLuint mWrapT; ///< Wrapping behavior vertically. - int mTilesS; - int mTilesT; - - GLuint mObject; ///< GL texture handle. - static GLuint gObject; ///< Global GL texture handle. - - dispatcher::handle mNewContextDispatch; -}; - -GLuint texture::impl::gObject = 0; - - -texture::texture(const std::string& name) : // FIXME: this is really weird - image(name), - // pass through - impl_(texture::impl::instance(name)) {} - - -/** - * Bind the GL texture for mapping, etc. - */ - -void texture::bind() const -{ - // pass through - impl_->bind(); -} - - -/** - * Get the texture object, for the curious. - */ - -GLuint texture::object() const -{ - // pass through - return impl_->mObject; -} - - -void texture::reset_binding() -{ - glBindTexture(GL_TEXTURE_2D, 0); - impl::gObject = 0; -} - - -void texture::min_filter(GLuint filter) -{ - // pass through - impl_->min_filter(filter); -} - -void texture::mag_filter(GLuint filter) -{ - // pass through - impl_->mag_filter(filter); -} - -void texture::wrap_s(GLuint wrap) -{ - // pass through - impl_->wrap_s(wrap); -} - -void texture::wrap_t(GLuint wrap) -{ - // pass through - impl_->wrap_t(wrap); -} - - -bool texture::tile_coordinates(int index, scalar coords[8]) const -{ - // pass through - return impl_->tile_coordinates(index, coords); -} - -bool texture::tile_coordinates(int index, scalar coords[8], - orientation orientation) const -{ - if (tile_coordinates(index, coords)) - { - if (orientation & flip) - { - // this looks kinda weird, but it's just swapping in a way that - // doesn't require an intermediate variable - coords[1] = coords[5]; - coords[5] = coords[3]; - coords[3] = coords[7]; - coords[7] = coords[5]; - } - if (orientation & reverse) - { - coords[0] = coords[2]; - coords[2] = coords[6]; - coords[4] = coords[6]; - coords[6] = coords[0]; - } - - return true; - } - - return false; -} - - -} // namespace moof - diff --git a/src/moof/texture.hh b/src/moof/texture.hh deleted file mode 100644 index a53dcd1..0000000 --- a/src/moof/texture.hh +++ /dev/null @@ -1,107 +0,0 @@ - -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** -**] All rights reserved. -* -* vi:ts=4 sw=4 tw=75 -* -* Distributable under the terms and conditions of the 2-clause BSD license; -* see the file COPYING for a complete text of the license. -* -**************************************************************************/ - -#ifndef _MOOF_TEXTURE_HH_ -#define _MOOF_TEXTURE_HH_ - -/** - * \file texture.hh - * Image-loading and OpenGL texture loading. - */ - -#include - -#include - -#include -#include - - -namespace moof { - - -class texture; -typedef boost::shared_ptr texture_ptr; - - -class texture : public image -{ -public: - - static const int no_tile = -1; - - /** - * Possible orientations for texture coordinates. - */ - typedef enum - { - normal = 0, ///< Normal orientation. - flip = 1, ///< Flip over a horizontal axis. - reverse = 2, ///< Flip over a vertical axis. - flip_and_reverse = 3 ///< Flip over both. - } orientation; - - - static texture_ptr alloc(const std::string& name) - { - return texture_ptr(new texture(name)); - } - - explicit texture(const std::string& name); - - void bind() const; - GLuint object() const; - - static void reset_binding(); - - void min_filter(GLuint filter); - void mag_filter(GLuint filter); - void wrap_s(GLuint wrap); - void wrap_t(GLuint wrap); - - - /** - * Calculate texture coordinates for a tile at a certain index. Tiles - * are indexed start with zero as the to-left tile and moving across, - * then down. - * \param index The tile index. - * \param coords An array of scalars where the texture coordinates will - * be stored after this call. The first coordinate (u,v) will be in - * the first two places and so on until all four coordinates are - * stored, therefore requiring enough room for an array of eight - * scalars. The winding of the coordinates is always counter-clockwise - * (the GL default). - * \return True if index is valid, false otherwise. - */ - bool tile_coordinates(int index, scalar coords[8]) const; - - /** - * This version let's you specify an orientation that will be reflected - * in the texture coordinates. This allows you to easily map a texture - * backwards or upside-down. - * \param what The orientation; can be flip, reverse, or - * flip_and_reverse. - * \return True if index is valid, false otherwise. - */ - bool tile_coordinates(int index, scalar coords[8], orientation what) const; - - -private: - - class impl; - boost::shared_ptr impl_; -}; - - -} // namespace moof - -#endif // _MOOF_TEXTURE_HH_ - diff --git a/src/yoink.rc b/src/yoink.rc index 7c22403..25ca5d5 100644 --- a/src/yoink.rc +++ b/src/yoink.rc @@ -11,7 +11,7 @@ FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0 PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_REVISION,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -#ifdef NDEBUG +#if NDEBUG FILEFLAGS 0 #else FILEFLAGS VS_FF_DEBUG