|
|
|
@ -15,6 +15,8 @@
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <utils/stb/stb_image.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace lunarium
|
|
|
|
namespace lunarium
|
|
|
|
{
|
|
|
|
{
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
@ -109,7 +111,8 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
|
|
glViewport(0, 0, mFBWidth, mFBHeight);
|
|
|
|
glViewport(0, 0, mFBWidth, mFBHeight);
|
|
|
|
mProjection = glm::ortho(0.0f, (GLfloat)mFBWidth, (GLfloat)mFBHeight, 0.0f, -1.0f, 1.0f);
|
|
|
|
mProjection = glm::ortho(0.0f, (GLfloat)mFBWidth, (GLfloat)mFBHeight, 0.0f, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
// mProjection = glm::ortho(0.0f, (GLfloat)mFBWidth, 0.0f, (GLfloat)mFBHeight, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
|
|
Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO_VERBOSE,
|
|
|
|
Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO_VERBOSE,
|
|
|
|
"glViewport set to %d, %d", mFBWidth, mFBHeight);
|
|
|
|
"glViewport set to %d, %d", mFBWidth, mFBHeight);
|
|
|
|
|
|
|
|
|
|
|
|
@ -138,19 +141,21 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
|
|
// Buffer width and height (in pixels) is the same as the screen size
|
|
|
|
// Buffer width and height (in pixels) is the same as the screen size
|
|
|
|
// Need to multiply these by the number bytes per pixel
|
|
|
|
// Need to multiply these by the number bytes per pixel
|
|
|
|
int bufferSize = mFBWidth * mFBHeight * 4; // NOTE: Assuming 4 channels for now
|
|
|
|
//int bufferSize = mFBWidth * mFBHeight * 4; // NOTE: Assuming 4 channels for now
|
|
|
|
unsigned char* buffer = new unsigned char[bufferSize];
|
|
|
|
//unsigned char* buffer = new unsigned char[bufferSize];
|
|
|
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, (void*)buffer);
|
|
|
|
//glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, (void*)buffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//FlipImageVertically(buffer, mFBWidth, mFBHeight, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//glSetTexImage()
|
|
|
|
|
|
|
|
|
|
|
|
mpFBTexture->FreeRawData();
|
|
|
|
mpFBTexture->FreeRawData();
|
|
|
|
mpFBTexture->mWidth = mFBWidth;
|
|
|
|
mpFBTexture->mWidth = mFBWidth;
|
|
|
|
mpFBTexture->mHeight = mFBHeight;
|
|
|
|
mpFBTexture->mHeight = mFBHeight;
|
|
|
|
mpFBTexture->mRawData = buffer;
|
|
|
|
|
|
|
|
mpFBTexture->mRawDataSize = bufferSize;
|
|
|
|
|
|
|
|
mpFBTexture->mFormat = ImageFormat::RGBA;
|
|
|
|
mpFBTexture->mFormat = ImageFormat::RGBA;
|
|
|
|
|
|
|
|
|
|
|
|
// return a copy of the image
|
|
|
|
// return a copy of the image
|
|
|
|
return new Image(*mpFBTexture);
|
|
|
|
return mpFBTexture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -161,6 +166,7 @@ namespace lunarium
|
|
|
|
}
|
|
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// USER METHODS
|
|
|
|
// USER METHODS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
@ -329,9 +335,10 @@ namespace lunarium
|
|
|
|
float yScale = source.Height / image.GetHeight();
|
|
|
|
float yScale = source.Height / image.GetHeight();
|
|
|
|
float yOffset = source.Top / image.GetHeight();
|
|
|
|
float yOffset = source.Top / image.GetHeight();
|
|
|
|
|
|
|
|
|
|
|
|
Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO_VERBOSE, "uvManip Values: %f, %f, %f, %f", xScale, xOffset, yScale, yOffset);
|
|
|
|
// Logger::Log(LogCategory::GRAPHICS, LogLevel::INFO_VERBOSE, "uvManip Values: %f, %f, %f, %f", xScale, xOffset, yScale, yOffset);
|
|
|
|
|
|
|
|
|
|
|
|
mImageShader.SetUniformf("uvManip", { xScale, xOffset, yScale, yOffset });
|
|
|
|
// * -1.0f on yScale will flip the image vertically
|
|
|
|
|
|
|
|
mImageShader.SetUniformf("uvManip", { xScale, xOffset, yScale /** -1.0f*/, yOffset});
|
|
|
|
mImageShader.SetUniformMatrix("model", 1, glm::value_ptr(trans));
|
|
|
|
mImageShader.SetUniformMatrix("model", 1, glm::value_ptr(trans));
|
|
|
|
mImageShader.SetUniformMatrix("projection", 1, glm::value_ptr(mProjection));
|
|
|
|
mImageShader.SetUniformMatrix("projection", 1, glm::value_ptr(mProjection));
|
|
|
|
mImageShader.SetUniformf("spriteColor", { color.Red, color.Green, color.Blue, color.Alpha });
|
|
|
|
mImageShader.SetUniformf("spriteColor", { color.Red, color.Green, color.Blue, color.Alpha });
|
|
|
|
@ -440,15 +447,26 @@ namespace lunarium
|
|
|
|
GLuint VBO;
|
|
|
|
GLuint VBO;
|
|
|
|
GLfloat vertices[] = {
|
|
|
|
GLfloat vertices[] = {
|
|
|
|
// Pos // Tex
|
|
|
|
// Pos // Tex
|
|
|
|
0.0f, 1.0f, 0.0f, 1.0f,
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
1.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
1.0f, 0.0f, 1.0f, 1.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
0.0f, 0.0f, 0.0f, 1.0f,
|
|
|
|
|
|
|
|
|
|
|
|
0.0f, 1.0f, 0.0f, 1.0f,
|
|
|
|
0.0f, 1.0f, 0.0f, 0.0f,
|
|
|
|
1.0f, 1.0f, 1.0f, 1.0f,
|
|
|
|
1.0f, 1.0f, 1.0f, 0.0f,
|
|
|
|
1.0f, 0.0f, 1.0f, 0.0f
|
|
|
|
1.0f, 0.0f, 1.0f, 1.0f
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GLfloat vertices[] = {
|
|
|
|
|
|
|
|
// // Pos // Tex
|
|
|
|
|
|
|
|
// 0.0f, 1.0f, 0.0f, 1.0f,
|
|
|
|
|
|
|
|
// 1.0f, 0.0f, 1.0f, 0.0f,
|
|
|
|
|
|
|
|
// 0.0f, 0.0f, 0.0f, 0.0f,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0.0f, 1.0f, 0.0f, 1.0f,
|
|
|
|
|
|
|
|
// 1.0f, 1.0f, 1.0f, 1.0f,
|
|
|
|
|
|
|
|
// 1.0f, 0.0f, 1.0f, 0.0f
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &mImageVAO);
|
|
|
|
glGenVertexArrays(1, &mImageVAO);
|
|
|
|
glGenBuffers(1, &VBO);
|
|
|
|
glGenBuffers(1, &VBO);
|
|
|
|
|
|
|
|
|
|
|
|
|