mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 09:34:19 +00:00
make screenshot work
This commit is contained in:
parent
c0d6ce6d25
commit
f5f05f3dcb
|
@ -963,28 +963,28 @@ void CCommandProcessorFragment_OpenGL::Cmd_Screenshot(const CCommandBuffer::SCom
|
|||
int h = aViewport[3];
|
||||
|
||||
// we allocate one more row to use when we are flipping the texture
|
||||
unsigned char *pPixelData = (unsigned char *)malloc((size_t)w * (h + 1) * 3);
|
||||
unsigned char *pTempRow = pPixelData + w * h * 3;
|
||||
unsigned char *pPixelData = (unsigned char *)malloc((size_t)w * (h + 1) * 4);
|
||||
unsigned char *pTempRow = pPixelData + w * h * 4;
|
||||
|
||||
// fetch the pixels
|
||||
GLint Alignment;
|
||||
glGetIntegerv(GL_PACK_ALIGNMENT, &Alignment);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pPixelData);
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pPixelData);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, Alignment);
|
||||
|
||||
// flip the pixel because opengl works from bottom left corner
|
||||
for(int y = 0; y < h / 2; y++)
|
||||
{
|
||||
mem_copy(pTempRow, pPixelData + y * w * 3, w * 3);
|
||||
mem_copy(pPixelData + y * w * 3, pPixelData + (h - y - 1) * w * 3, w * 3);
|
||||
mem_copy(pPixelData + (h - y - 1) * w * 3, pTempRow, w * 3);
|
||||
mem_copy(pTempRow, pPixelData + y * w * 4, w * 4);
|
||||
mem_copy(pPixelData + y * w * 4, pPixelData + (h - y - 1) * w * 4, w * 4);
|
||||
mem_copy(pPixelData + (h - y - 1) * w * 4, pTempRow, w * 4);
|
||||
}
|
||||
|
||||
// fill in the information
|
||||
pCommand->m_pImage->m_Width = w;
|
||||
pCommand->m_pImage->m_Height = h;
|
||||
pCommand->m_pImage->m_Format = CImageInfo::FORMAT_RGB;
|
||||
pCommand->m_pImage->m_Format = CImageInfo::FORMAT_RGBA;
|
||||
pCommand->m_pImage->m_pData = pPixelData;
|
||||
}
|
||||
|
||||
|
|
|
@ -893,41 +893,6 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_RenderTex3D(const CCommandBuffer::
|
|||
};
|
||||
}
|
||||
|
||||
void CCommandProcessorFragment_OpenGL3_3::Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand)
|
||||
{
|
||||
// fetch image data
|
||||
GLint aViewport[4] = {0, 0, 0, 0};
|
||||
glGetIntegerv(GL_VIEWPORT, aViewport);
|
||||
|
||||
int w = aViewport[2];
|
||||
int h = aViewport[3];
|
||||
|
||||
// we allocate one more row to use when we are flipping the texture
|
||||
unsigned char *pPixelData = (unsigned char *)malloc((size_t)w * (h + 1) * 3);
|
||||
unsigned char *pTempRow = pPixelData + w * h * 3;
|
||||
|
||||
// fetch the pixels
|
||||
GLint Alignment;
|
||||
glGetIntegerv(GL_PACK_ALIGNMENT, &Alignment);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pPixelData);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, Alignment);
|
||||
|
||||
// flip the pixel because opengl works from bottom left corner
|
||||
for(int y = 0; y < h / 2; y++)
|
||||
{
|
||||
mem_copy(pTempRow, pPixelData + y * w * 3, w * 3);
|
||||
mem_copy(pPixelData + y * w * 3, pPixelData + (h - y - 1) * w * 3, w * 3);
|
||||
mem_copy(pPixelData + (h - y - 1) * w * 3, pTempRow, w * 3);
|
||||
}
|
||||
|
||||
// fill in the information
|
||||
pCommand->m_pImage->m_Width = w;
|
||||
pCommand->m_pImage->m_Height = h;
|
||||
pCommand->m_pImage->m_Format = CImageInfo::FORMAT_RGB;
|
||||
pCommand->m_pImage->m_pData = pPixelData;
|
||||
}
|
||||
|
||||
void CCommandProcessorFragment_OpenGL3_3::DestroyBufferContainer(int Index, bool DeleteBOs)
|
||||
{
|
||||
SBufferContainer &BufferContainer = m_BufferContainers[Index];
|
||||
|
|
|
@ -417,7 +417,6 @@ protected:
|
|||
void Cmd_Clear(const CCommandBuffer::SCommand_Clear *pCommand) override;
|
||||
void Cmd_Render(const CCommandBuffer::SCommand_Render *pCommand) override;
|
||||
void Cmd_RenderTex3D(const CCommandBuffer::SCommand_RenderTex3D *pCommand) override;
|
||||
void Cmd_Screenshot(const CCommandBuffer::SCommand_Screenshot *pCommand) override;
|
||||
|
||||
void Cmd_CreateBufferObject(const CCommandBuffer::SCommand_CreateBufferObject *pCommand) override;
|
||||
void Cmd_RecreateBufferObject(const CCommandBuffer::SCommand_RecreateBufferObject *pCommand) override;
|
||||
|
|
|
@ -680,7 +680,7 @@ void CGraphics_Threaded::ScreenshotDirect()
|
|||
str_format(aBuf, sizeof(aBuf), "saved screenshot to '%s'", aWholePath);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf, ColorRGBA{1.0f, 0.6f, 0.3f, 1.0f});
|
||||
png_open_file_write(&Png, aWholePath); // ignore_convention
|
||||
png_set_data(&Png, Image.m_Width, Image.m_Height, 8, PNG_TRUECOLOR, (unsigned char *)Image.m_pData); // ignore_convention
|
||||
png_set_data(&Png, Image.m_Width, Image.m_Height, 8, PNG_TRUECOLOR_ALPHA, (unsigned char *)Image.m_pData); // ignore_convention
|
||||
png_close_file(&Png); // ignore_convention
|
||||
|
||||
free(Image.m_pData);
|
||||
|
|
Loading…
Reference in a new issue