renderer: screenshot by saving render texture to file
parent
00a4b8e1e2
commit
3f61a6a753
|
@ -9,3 +9,4 @@ gmon.out*
|
||||||
cscope*
|
cscope*
|
||||||
test.cpp
|
test.cpp
|
||||||
a.out
|
a.out
|
||||||
|
*screenshot*
|
|
@ -17,6 +17,8 @@ namespace renderer{
|
||||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
|
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
|
void saveScreenshot(bool forceFullHD=false);
|
||||||
|
|
||||||
Shader* getRenderShader();
|
Shader* getRenderShader();
|
||||||
RenderSet& getChunksToRender();
|
RenderSet& getChunksToRender();
|
||||||
oneapi::tbb::concurrent_queue<chunkmesher::MeshData*>& getMeshDataQueue();
|
oneapi::tbb::concurrent_queue<chunkmesher::MeshData*>& getMeshDataQueue();
|
||||||
|
|
|
@ -155,4 +155,7 @@ void processInput(GLFWwindow *window)
|
||||||
// Reset blockpicking if enough time has passed
|
// Reset blockpicking if enough time has passed
|
||||||
if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_RELEASE && glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_2) == GLFW_RELEASE) blockpick = false;
|
if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_RELEASE && glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_2) == GLFW_RELEASE) blockpick = false;
|
||||||
|
|
||||||
|
if(glfwGetKey(window, GLFW_KEY_F2) == GLFW_PRESS) renderer::saveScreenshot();
|
||||||
|
if(glfwGetKey(window, GLFW_KEY_F3) == GLFW_PRESS) renderer::saveScreenshot(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "chunkmesher.hpp"
|
#include "chunkmesher.hpp"
|
||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include "stb_image.h"
|
#include "stb_image.h"
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
#include "stb_image_write.h"
|
||||||
|
|
||||||
namespace renderer{
|
namespace renderer{
|
||||||
RenderSet chunks_torender;
|
RenderSet chunks_torender;
|
||||||
|
@ -240,6 +242,30 @@ namespace renderer{
|
||||||
renderTexDepthBuffer);
|
renderTexDepthBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void saveScreenshot(bool forceFullHD){
|
||||||
|
int old_screenWidth = screenWidth;
|
||||||
|
int old_screenHeight = screenHeight;
|
||||||
|
|
||||||
|
if(forceFullHD){
|
||||||
|
resize_framebuffer(1920, 1080);
|
||||||
|
// Do a render pass
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind the render frame buffer
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, renderTexFrameBuffer);
|
||||||
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
|
// Save the framebuffer in a byte array
|
||||||
|
GLubyte data[screenWidth*screenHeight*3];
|
||||||
|
glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||||
|
// Save the byte array onto a texture
|
||||||
|
stbi_flip_vertically_on_write(1);
|
||||||
|
stbi_write_png(forceFullHD ? "screenshot_fullhd.png" : "screenshot.png", screenWidth,
|
||||||
|
screenHeight, 3, data, screenWidth*3);
|
||||||
|
|
||||||
|
if(forceFullHD) resize_framebuffer(old_screenWidth, old_screenHeight);
|
||||||
|
}
|
||||||
|
|
||||||
void destroy(){
|
void destroy(){
|
||||||
delete theShader;
|
delete theShader;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue