Commit 489831af authored by Robert Menzel's avatar Robert Menzel
Browse files

added rudimentary ppm loader

parent a0671aea
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPPM_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPPM_HH
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <ACGL/OpenGL/InitStaticFileTypes.hh>
namespace ACGL{
namespace OpenGL{
class TextureDataControlFilePPM : public TextureDataControlFile
{
friend void initStaticFileTypes(void);
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureDataControlFilePPM(const std::string& _filename)
: TextureDataControlFile(_filename)
{}
virtual ~TextureDataControlFilePPM(void) {}
static SharedTextureDataControlFile creator(const std::string& _filename) { return SharedTextureDataControlFile(new TextureDataControlFilePPM(_filename)); }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
private:
virtual bool load(SharedTextureData& texture) const;
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
static int_t getTypeID(void) { return sTypeID; }
private:
static int_t registerType(void);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
private:
static int_t sTypeID;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureDataControlFilePPM)
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPPM_HH
......@@ -6,6 +6,11 @@
#ifndef ACGL_OPENGL_DATA_TEXTUREDATA_HH
#define ACGL_OPENGL_DATA_TEXTUREDATA_HH
/**
* TextureData holds the data of a 1,2 or 3 dimensional image to be used as a texture.
* This structure is used for texture loading.
*/
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureDataControlFilePPM.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <fstream>
using namespace ACGL;
using namespace ACGL::OpenGL;
using namespace ACGL::Utils;
bool TextureDataControlFilePPM::load(SharedTextureData& texture) const
{
std::ifstream fileStream( getFullFilePath().c_str(), std::ifstream::in );
if (!fileStream.good()) {
error() << "could not open file " << getFullFilePath() << std::endl;
return false;
}
int width, height, maxValue;
std::string line;
fileStream >> line; // ignore the header
// note: we assume no comments in this file!
// a general ppm loader has to be more clever!
fileStream >> width;
fileStream >> height;
fileStream >> maxValue; // we will ignore this and assume the value range is 0..255
unsigned char *data = new unsigned char[width*height*3]; // we assume RGB
int pos = 0;
while (fileStream.good() && pos < (width*height*3)) {
int i;
fileStream >> i;
data[pos] = (unsigned char) i;
pos++;
}
fileStream.close();
texture->setData(data); // data will get deleted by the TextureData destructor!
texture->setDepth(1); // 2D so, depth is 1
texture->setHeight(height);
texture->setWidth(width);
texture->setFormat(GL_RGB);
texture->setType(GL_UNSIGNED_BYTE); // == unsigned char
return true;
}
int_t TextureDataControlFilePPM::registerType(void)
{
sTypeID = TextureDataControlFileFactory::the()->registerType("ppm", &TextureDataControlFilePPM::creator);
return sTypeID;
}
int_t TextureDataControlFilePPM::sTypeID = -1;
......@@ -7,6 +7,7 @@
#include <ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFilePNG.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFilePPM.hh>
using namespace ACGL::OpenGL;
......@@ -16,5 +17,6 @@ void ACGL::OpenGL::initStaticFileTypes(void)
TextureDataControlFileJPG::registerType();
TextureDataControlFilePNG::registerType();
#endif
TextureDataControlFilePPM::registerType();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment