initial working copy of Image
This commit is contained in:
parent
e0d488d2fd
commit
fb70988fd0
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: ResourceManaged.hpp,v 1.4 2005/06/14 00:28:36 cozman Exp $
|
||||
// $Id: ResourceManaged.hpp,v 1.5 2005/06/27 04:24:09 cozman Exp $
|
||||
|
||||
#ifndef PHOTON_RESOURCEMANAGED_HPP
|
||||
#define PHOTON_RESOURCEMANAGED_HPP
|
||||
@ -65,12 +65,23 @@ public:
|
||||
// Generally called by destructor, so should rarely be called.
|
||||
virtual void release();
|
||||
|
||||
// Group: Accessors
|
||||
public:
|
||||
// Function: getName
|
||||
// Get the name associated with the resource.
|
||||
//
|
||||
// Returns:
|
||||
// Name of resource, or empty string if no resource is loaded.
|
||||
std::string getName() const;
|
||||
|
||||
// Group: Resource Manager Access
|
||||
|
||||
public:
|
||||
static ResMgrT resMgr_;
|
||||
|
||||
// Function: cleanUp
|
||||
// Cleans up any unused resources of the type.
|
||||
// (Ex. Image::cleanUp() will unload all images.)
|
||||
virtual void cleanUp();
|
||||
static void cleanUp();
|
||||
|
||||
// Function: addResource
|
||||
// Define a new named resource.
|
||||
@ -92,9 +103,8 @@ public:
|
||||
// path - Path of resource data file.
|
||||
static void addResource(const std::string& path);
|
||||
|
||||
protected:
|
||||
private:
|
||||
std::string resName_;
|
||||
static ResMgrT resMgr_;
|
||||
};
|
||||
|
||||
//and he said "the implementation shall follow, as it is written"
|
||||
@ -143,6 +153,12 @@ void ResourceManaged<ResMgrT>::release()
|
||||
}
|
||||
}
|
||||
|
||||
template<class ResMgrT>
|
||||
std::string ResourceManaged<ResMgrT>::getName() const
|
||||
{
|
||||
return resName_;
|
||||
}
|
||||
|
||||
template<class ResMgrT>
|
||||
void ResourceManaged<ResMgrT>::cleanUp()
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: ResourceManager.hpp,v 1.6 2005/06/14 00:28:36 cozman Exp $
|
||||
// $Id: ResourceManager.hpp,v 1.7 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
#ifndef PHOTON_RESOURCEMANAGER_HPP
|
||||
#define PHOTON_RESOURCEMANAGER_HPP
|
||||
@ -54,6 +54,9 @@ private:
|
||||
virtual void freeResource(resT &res)=0;
|
||||
|
||||
void deleteResource(const std::string& name);
|
||||
|
||||
public:
|
||||
void printReport(std::ostream& os);
|
||||
|
||||
private:
|
||||
typedef std::map<std::string,resT> MapT;
|
||||
@ -113,7 +116,7 @@ void ResourceManager<resT>::newResource(const std::string& name,
|
||||
{
|
||||
// rethrow any exceptions with specific information
|
||||
throw ResourceException("Could not load " + path + " as " + name +
|
||||
": " + e.what());
|
||||
": " + e.getDesc());
|
||||
}
|
||||
|
||||
resourceMap_[name] = resource; // add the resource to resourceMap
|
||||
@ -126,11 +129,13 @@ resT& ResourceManager<resT>::getResource(const std::string& name)
|
||||
|
||||
if(resource != resourceMap_.end())
|
||||
{
|
||||
// increment the refCount and return the resource for use
|
||||
++resource->second.refCount;
|
||||
return resource->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ResourceException();
|
||||
throw ResourceException("No resource named \"" + name + "\" exists.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,6 +152,19 @@ void ResourceManager<resT>::deleteResource(const std::string& name)
|
||||
}
|
||||
}
|
||||
|
||||
template<class resT>
|
||||
void ResourceManager<resT>::printReport(std::ostream& os)
|
||||
{
|
||||
MapIterator resource( resourceMap_.begin() );
|
||||
|
||||
for(MapIterator i = resourceMap_.begin(); i != resourceMap_.end(); ++i)
|
||||
{
|
||||
os << i->second.name << "\t" << i->second.path << "\t"
|
||||
<< i->second.refCount << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif //PHOTON_RESOURCEMANAGER_HPP
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: exceptions.hpp,v 1.4 2005/03/01 07:51:04 cozman Exp $
|
||||
// $Id: exceptions.hpp,v 1.5 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
#ifndef PHOTON_EXCEPTIONS_HPP
|
||||
#define PHOTON_EXCEPTIONS_HPP
|
||||
@ -56,8 +56,16 @@ public:
|
||||
// Throwable family) define what() that returns a description of the
|
||||
// exception.
|
||||
//
|
||||
// Returns: std::string describing the error
|
||||
// Returns: Formatted std::string describing the error
|
||||
std::string virtual what() const throw();
|
||||
|
||||
// Function: getDesc
|
||||
// Get just the description portion of an exception, used for chaining
|
||||
// exceptions.
|
||||
//
|
||||
// Returns: Unformatted std::string describing the cause of the error
|
||||
std::string virtual getDesc() const throw();
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Throwable& rhs);
|
||||
|
||||
private:
|
||||
|
10
photon.mm
10
photon.mm
@ -4,7 +4,6 @@
|
||||
<cloud/>
|
||||
<font BOLD="true" NAME="SansSerif" SIZE="12"/>
|
||||
<node ID="_" POSITION="right" TEXT="0.1 Release">
|
||||
<arrowlink DESTINATION="Freemind_Link_511487087" ENDARROW="Default" ENDINCLINATION="67;0;" ID="Freemind_Arrow_Link_1969744902" STARTARROW="None" STARTINCLINATION="-28;-391;"/>
|
||||
<font NAME="SansSerif" SIZE="12"/>
|
||||
<node ID="Freemind_Link_1613164220" TEXT="better SConstruct file">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
@ -32,11 +31,12 @@
|
||||
<node ID="Freemind_Link_1104675603" TEXT="Tests">
|
||||
<node ID="Freemind_Link_1283736172" TEXT="Math Test(s)"/>
|
||||
<node ID="Freemind_Link_1348104879" TEXT="Kernel/AppCore"/>
|
||||
<node ID="Freemind_Link_288973656" TEXT="Texture">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node ID="Freemind_Link_1937076235" TEXT="Examples">
|
||||
<node ID="Freemind_Link_279976301" TEXT="Pen"/>
|
||||
<node ID="Freemind_Link_609153459" TEXT="Image"/>
|
||||
<node ID="Freemind_Link_25725154" TEXT="Sound/Music"/>
|
||||
<node ID="Freemind_Link_288973656" TEXT="Texture"/>
|
||||
</node>
|
||||
</node>
|
||||
<node FOLDED="true" ID="Freemind_Link_22783417" TEXT="Example Game">
|
||||
@ -63,9 +63,6 @@
|
||||
<node ID="Freemind_Link_1083205841" TEXT="Jupiter - Initial rewrite of Photon"/>
|
||||
</node>
|
||||
</node>
|
||||
<node ID="Freemind_Link_511487087" POSITION="left" TEXT="Website">
|
||||
<node ID="Freemind_Link_502036778" TEXT="cozTheme with a Wiki"/>
|
||||
</node>
|
||||
<node FOLDED="true" ID="Freemind_Link_351891371" POSITION="left" TEXT="General Mateinance">
|
||||
<font BOLD="true" NAME="SansSerif" SIZE="12"/>
|
||||
<node ID="Freemind_Link_1978849189" TEXT="Clean up CVS">
|
||||
@ -75,7 +72,6 @@
|
||||
</node>
|
||||
<node ID="Freemind_Link_682620075" POSITION="left" TEXT="Current Problems">
|
||||
<font BOLD="true" NAME="SansSerif" SIZE="12"/>
|
||||
<node ID="Freemind_Link_1424720553" TEXT="Image is not tested at all"/>
|
||||
</node>
|
||||
</node>
|
||||
</map>
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: exceptions.cpp,v 1.6 2005/02/27 05:52:00 cozman Exp $
|
||||
// $Id: exceptions.cpp,v 1.7 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
|
||||
#include "exceptions.hpp"
|
||||
@ -34,6 +34,11 @@ std::string Throwable::what() const throw()
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string Throwable::getDesc() const throw()
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Throwable& rhs)
|
||||
{
|
||||
return os << rhs.what();
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: FileBuffer.cpp,v 1.6 2005/06/11 05:28:41 cozman Exp $
|
||||
// $Id: FileBuffer.cpp,v 1.7 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
#include "util/FileBuffer.hpp"
|
||||
|
||||
@ -34,7 +34,7 @@ void FileBuffer::open(const std::string& filename)
|
||||
file_ = PHYSFS_openRead(filename.c_str());
|
||||
if(file_ == 0)
|
||||
{
|
||||
throw ResourceException();
|
||||
throw ResourceException("Could not open file \"" + filename + "\".");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Image.cpp,v 1.2 2005/06/14 00:28:36 cozman Exp $
|
||||
// $Id: Image.cpp,v 1.3 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
#include "video/Image.hpp"
|
||||
|
||||
@ -18,14 +18,16 @@ namespace video
|
||||
|
||||
Image::Image() :
|
||||
alpha_(255),
|
||||
texMinX_(0), texMinY_(0), texMaxX_(1), texMaxY_(1)
|
||||
texMinX_(0), texMinY_(0), texMaxX_(1), texMaxY_(1),
|
||||
width_(0), height_(0)
|
||||
{ }
|
||||
|
||||
Image::Image(const Image &rhs) :
|
||||
Texture(rhs),
|
||||
alpha_(rhs.alpha_),
|
||||
texMinX_(rhs.texMinX_), texMinY_(rhs.texMinY_),
|
||||
texMaxX_(rhs.texMaxX_), texMaxY_(rhs.texMaxY_)
|
||||
texMaxX_(rhs.texMaxX_), texMaxY_(rhs.texMaxY_),
|
||||
width_(rhs.width_), height_(rhs.height_)
|
||||
{ }
|
||||
|
||||
Image::Image(const std::string& name) :
|
||||
@ -45,6 +47,8 @@ Image& Image::operator=(const Image &rhs)
|
||||
texMinY_ = rhs.texMinY_;
|
||||
texMaxX_ = rhs.texMaxX_;
|
||||
texMaxY_ = rhs.texMaxY_;
|
||||
width_ = rhs.width_;
|
||||
height_ = rhs.height_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@ -52,6 +56,8 @@ Image& Image::operator=(const Image &rhs)
|
||||
void Image::open(const std::string& name)
|
||||
{
|
||||
Texture::open(name);
|
||||
width_ = getWidth();
|
||||
height_ = getHeight();
|
||||
}
|
||||
|
||||
void Image::setAlpha(ubyte alpha)
|
||||
@ -75,8 +81,8 @@ void Image::flip(bool horizontal, bool vertical)
|
||||
//stretching and resizing is very inexpensive, done via variables
|
||||
void Image::stretch(scalar xFactor, scalar yFactor)
|
||||
{
|
||||
width_ = xFactor*width_;
|
||||
height_ = yFactor*height_;
|
||||
width_ = xFactor*getWidth();
|
||||
height_ = yFactor*getHeight();
|
||||
}
|
||||
|
||||
void Image::resize(scalar width, scalar height)
|
||||
@ -184,7 +190,7 @@ ubyte Image::getAlpha() const
|
||||
|
||||
std::ostream& operator<<(std::ostream &o, const Image &rhs)
|
||||
{
|
||||
return o << "Image: { Name: " << rhs.resName_ <<
|
||||
return o << "Image: { Name: " << rhs.getName() <<
|
||||
" Dimensions: " << rhs.width_ << "x" << rhs.height_
|
||||
<< " Alpha: " << rhs.alpha_ << " }";
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Texture.cpp,v 1.2 2005/06/14 00:28:36 cozman Exp $
|
||||
// $Id: Texture.cpp,v 1.3 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
#include "video/Texture.hpp"
|
||||
|
||||
@ -22,7 +22,7 @@ Texture::Texture()
|
||||
Texture::Texture(const Texture &rhs) :
|
||||
ResourceManaged<TextureResourceManager>(rhs)
|
||||
{
|
||||
resMgr_.getTextureData(resName_, width_, height_, texID_);
|
||||
resMgr_.getTextureData(getName(), width_, height_, texID_);
|
||||
}
|
||||
|
||||
Texture::Texture(const std::string& name)
|
||||
@ -33,7 +33,7 @@ Texture::Texture(const std::string& name)
|
||||
void Texture::open(const std::string& name)
|
||||
{
|
||||
ResourceManaged<TextureResourceManager>::open(name);
|
||||
resMgr_.getTextureData(resName_, width_, height_, texID_);
|
||||
resMgr_.getTextureData(getName(), width_, height_, texID_);
|
||||
}
|
||||
|
||||
void Texture::bind() const
|
||||
@ -50,7 +50,7 @@ Texture& Texture::operator=(const Texture &rhs)
|
||||
if(&rhs != this)
|
||||
{
|
||||
ResourceManaged<TextureResourceManager>::operator=(rhs);
|
||||
resMgr_.getTextureData(resName_, width_, height_, texID_);
|
||||
resMgr_.getTextureData(getName(), width_, height_, texID_);
|
||||
|
||||
//w&h after getTextureData
|
||||
width_ = rhs.width_;
|
||||
@ -76,7 +76,7 @@ scalar Texture::getHeight() const
|
||||
|
||||
std::ostream& operator<<(std::ostream &o, const Texture &rhs)
|
||||
{
|
||||
return o << "Texture: { Name: " << rhs.resName_ << " TexID: " << rhs.texID_
|
||||
return o << "Texture: { Name: " << rhs.getName() << " TexID: " << rhs.texID_
|
||||
<< " Dimensions: " << rhs.width_ << "x" << rhs.height_ << " }";
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: TextureResourceManager.cpp,v 1.2 2005/06/14 00:28:36 cozman Exp $
|
||||
// $Id: TextureResourceManager.cpp,v 1.3 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
#include "video/TextureResourceManager.hpp"
|
||||
|
||||
@ -57,7 +57,7 @@ void TextureResourceManager::loadResource(TextureResource &res,
|
||||
|
||||
if(!file)
|
||||
{
|
||||
throw ResourceException("corona::CreateMemoryFile failed");
|
||||
throw APIError("corona::CreateMemoryFile failed");
|
||||
}
|
||||
|
||||
image = corona::OpenImage(file,corona::PF_R8G8B8A8);
|
||||
@ -66,7 +66,7 @@ void TextureResourceManager::loadResource(TextureResource &res,
|
||||
|
||||
if(!image)
|
||||
{
|
||||
throw ResourceException("corona::OpenImage failed");
|
||||
throw ResourceException("Invalid image format.");
|
||||
}
|
||||
|
||||
res.width = image->getWidth();
|
||||
@ -118,7 +118,5 @@ void TextureResourceManager::freeResource(TextureResource &res)
|
||||
glDeleteTextures(1, &res.texID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: VideoCore.cpp,v 1.4 2005/06/11 05:28:41 cozman Exp $
|
||||
// $Id: VideoCore.cpp,v 1.5 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
#include "video/VideoCore.hpp"
|
||||
|
||||
@ -115,11 +115,13 @@ void VideoCore::initOpenGL()
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
// Setup depth checking.
|
||||
//glDepthFunc(GL_LEQUAL);
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
//setup hints
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
|
||||
|
||||
glEnable(GL_POLYGON_SMOOTH);
|
||||
|
||||
//enable texturing
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
@ -5,7 +5,7 @@
|
||||
// James Turk (jpt2433@rit.edu)
|
||||
//
|
||||
// Version:
|
||||
// $Id: Texture_test.cpp,v 1.1 2005/06/13 05:38:06 cozman Exp $
|
||||
// $Id: Texture_test.cpp,v 1.2 2005/06/27 04:24:16 cozman Exp $
|
||||
|
||||
#include "photon.hpp"
|
||||
using namespace photon;
|
||||
@ -31,7 +31,16 @@ public:
|
||||
video.setOrthoView(800,600);
|
||||
|
||||
video::Texture::addResource("data/test.png");
|
||||
img.open("data/test.png");
|
||||
video::Texture::addResource("test2","data/test2.png");
|
||||
|
||||
// Testing of errors
|
||||
//video::Texture::addResource("nonfile");
|
||||
//video::Texture::addResource("Texture_test.cpp");
|
||||
//tex[0].open("test0");
|
||||
|
||||
tex[0].open("data/test.png");
|
||||
tex[1].open("test2");
|
||||
tex[2] = tex[1];
|
||||
|
||||
}
|
||||
|
||||
@ -48,31 +57,45 @@ public:
|
||||
|
||||
video.clear();
|
||||
|
||||
img.bind();
|
||||
tex[0].bind();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0,0); glVertex2f(0,0);
|
||||
glTexCoord2f(1,0); glVertex2f(100,0);
|
||||
glTexCoord2f(1,1); glVertex2f(100,100);
|
||||
glTexCoord2f(0,1); glVertex2f(0,100);
|
||||
glEnd();
|
||||
|
||||
tex[1].bind();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0,0); glVertex2f(250,200);
|
||||
glTexCoord2f(1,0); glVertex2f(300,250);
|
||||
glTexCoord2f(1,1); glVertex2f(250,300);
|
||||
glTexCoord2f(0,1); glVertex2f(200,250);
|
||||
glEnd();
|
||||
|
||||
if(tex[2])
|
||||
{
|
||||
tex[2].bind();
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0,0); glVertex2f(400,400);
|
||||
glTexCoord2f(1,0); glVertex2f(500,400);
|
||||
glTexCoord2f(1,1); glVertex2f(500,500);
|
||||
glTexCoord2f(0,1); glVertex2f(400,500);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
video::Texture img;
|
||||
video::Texture tex[3];
|
||||
|
||||
Log log;
|
||||
AppCore& app;
|
||||
video::VideoCore& video;
|
||||
};
|
||||
|
||||
class Test00 : public Application
|
||||
class TextureTest : public Application
|
||||
{
|
||||
public:
|
||||
Test00()
|
||||
{
|
||||
//Log::getInstance().addSink(LogSinkPtr(new ConsoleSink("out")));
|
||||
//Log::getInstance().addSink(LogSinkPtr(new HTMLSink("debug")));
|
||||
}
|
||||
|
||||
int main(const StrVec& args)
|
||||
{
|
||||
@ -86,4 +109,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
ENTRYPOINT(Test00)
|
||||
ENTRYPOINT(TextureTest)
|
||||
|
Loading…
Reference in New Issue
Block a user