mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 10:35:43 -05:00
Fixed GL screen shot.
This commit is contained in:
parent
8f3eb01cda
commit
22d8509fe8
3 changed files with 39 additions and 13 deletions
38
src/bgfx.cpp
38
src/bgfx.cpp
|
@ -102,35 +102,51 @@ namespace bgfx
|
|||
_result[15] = 1.0f;
|
||||
}
|
||||
|
||||
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data)
|
||||
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, bool _grayscale, bool _yflip)
|
||||
{
|
||||
FILE* file = fopen(_filePath, "wb");
|
||||
if ( NULL != file )
|
||||
{
|
||||
uint8_t type = _grayscale ? 3 : 2;
|
||||
uint8_t bpp = _grayscale ? 8 : 32;
|
||||
|
||||
putc(0, file);
|
||||
putc(0, file);
|
||||
putc(2, file); // uncompressed RGBA
|
||||
putc(type, file);
|
||||
putc(0, file);
|
||||
putc(0, file);
|
||||
putc(0, file);
|
||||
putc(0, file);
|
||||
putc(0, file);
|
||||
putc(0, file);
|
||||
putc(0, file); // x origin
|
||||
putc(0, file);
|
||||
putc(0, file);
|
||||
putc(0, file); // y origin
|
||||
putc( _width&0xff, file);
|
||||
putc(0, file);
|
||||
putc(_width&0xff, file);
|
||||
putc( (_width>>8)&0xff, file);
|
||||
putc( _height&0xff, file);
|
||||
putc(_height&0xff, file);
|
||||
putc( (_height>>8)&0xff, file);
|
||||
putc(32, file);
|
||||
putc(bpp, file);
|
||||
putc(32, file);
|
||||
|
||||
uint8_t* data = (uint8_t*)_data;
|
||||
for (uint32_t yy = 0; yy < _height; ++yy)
|
||||
uint32_t dstPitch = _width*bpp/8;
|
||||
if (_yflip)
|
||||
{
|
||||
fwrite(data, _width*4, 1, file);
|
||||
data += _pitch;
|
||||
uint8_t* data = (uint8_t*)_src + dstPitch*_height - _srcPitch;
|
||||
for (uint32_t yy = 0; yy < _height; ++yy)
|
||||
{
|
||||
fwrite(data, dstPitch, 1, file);
|
||||
data -= _srcPitch;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t* data = (uint8_t*)_src;
|
||||
for (uint32_t yy = 0; yy < _height; ++yy)
|
||||
{
|
||||
fwrite(data, dstPitch, 1, file);
|
||||
data += _srcPitch;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace bgfx
|
|||
|
||||
void fatal(bgfx::Fatal::Enum _code, const char* _format, ...);
|
||||
void release(Memory* _mem);
|
||||
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data);
|
||||
void saveTga(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, bool _grayscale = false, bool _yflip = false);
|
||||
const char* getAttribName(Attrib::Enum _attr);
|
||||
bool renderFrame();
|
||||
|
||||
|
|
|
@ -388,7 +388,17 @@ namespace bgfx
|
|||
#if BGFX_CONFIG_RENDERER_OPENGL
|
||||
void* data = g_realloc(NULL, m_resolution.m_width*m_resolution.m_height*4);
|
||||
glReadPixels(0, 0, m_resolution.m_width, m_resolution.m_height, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
saveTga( (const char*)_mem->data, m_resolution.m_width, m_resolution.m_height, m_resolution.m_width*4, data);
|
||||
|
||||
uint8_t* rgba = (uint8_t*)data;
|
||||
for (uint32_t ii = 0, num = m_resolution.m_width*m_resolution.m_height; ii < num; ++ii)
|
||||
{
|
||||
uint8_t temp = rgba[0];
|
||||
rgba[0] = rgba[2];
|
||||
rgba[2] = temp;
|
||||
rgba += 4;
|
||||
}
|
||||
|
||||
saveTga( (const char*)_mem->data, m_resolution.m_width, m_resolution.m_height, m_resolution.m_width*4, data, false, true);
|
||||
g_free(data);
|
||||
#endif // BGFX_CONFIG_RENDERER_OPENGL
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue