Commit 208132d9 authored by Janis Born's avatar Janis Born
Browse files

fix TextureDataPPMWriter skipping the last row of image data

parent b67e001b
......@@ -14,6 +14,12 @@ using namespace ACGL::Utils;
bool ACGL::OpenGL::saveTextureDataToPPM(const ConstSharedTextureData& _textureData, const std::string& _filename)
{
if(_textureData->getFormat() != GL_RGB)
{
error() << "saveTextureDataToPPM: Unsupported texture format, must be GL_RGB" << std::endl;
return false;
}
std::ofstream outFileStream(_filename.c_str(), std::ios_base::out | std::ios_base::binary);
if(!outFileStream.good())
......@@ -36,7 +42,7 @@ bool ACGL::OpenGL::saveTextureDataToPPM(const ConstSharedTextureData& _textureDa
}
else
{
error() << "saveTextureDataToPPM: Unsupported data format" << std::endl;
error() << "saveTextureDataToPPM: Unsupported texture type, must be GL_UNSIGNED_BYTE" << std::endl;
return false;
}
outFileStream << maxValue;
......@@ -45,15 +51,15 @@ bool ACGL::OpenGL::saveTextureDataToPPM(const ConstSharedTextureData& _textureDa
outFileStream << "\n";
// Now, write the image data in binary format
for(uint_t y = _textureData->getHeight()-1; y > 0; --y)
for(uint_t y = 0; y < _textureData->getHeight(); ++y)
{
for(uint_t x = 0; x < _textureData->getWidth(); ++x)
{
uint_t i = (y * _textureData->getWidth()) + x;
uint_t i = ((_textureData->getHeight() - y - 1) * _textureData->getWidth()) + x;
outFileStream.put(_textureData->getData()[(4*i + 0) * getGLTypeSize(_textureData->getType())]);
outFileStream.put(_textureData->getData()[(4*i + 1) * getGLTypeSize(_textureData->getType())]);
outFileStream.put(_textureData->getData()[(4*i + 2) * getGLTypeSize(_textureData->getType())]);
outFileStream.put(_textureData->getData()[(3*i + 0) * getGLTypeSize(_textureData->getType())]);
outFileStream.put(_textureData->getData()[(3*i + 1) * getGLTypeSize(_textureData->getType())]);
outFileStream.put(_textureData->getData()[(3*i + 2) * getGLTypeSize(_textureData->getType())]);
}
}
......
Supports Markdown
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