Starting on Entity System, and fixed aspect stuff
This commit is contained in:
parent
04d6c0ed82
commit
73e39559cb
0
Engine/Components/Componet.h
Normal file
0
Engine/Components/Componet.h
Normal file
@ -58,8 +58,27 @@ GLFWwindow* Engine::GetWindow() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Engine::ResizeFramebuffer(int width, int height) {
|
void Engine::ResizeFramebuffer(int width, int height) {
|
||||||
fbWidth = width;
|
// Avoid division by zero.
|
||||||
fbHeight = height;
|
if (height <= 0)
|
||||||
|
height = 1;
|
||||||
|
|
||||||
|
// Define the desired target aspect ratio (e.g., 16:9).
|
||||||
|
const float targetAspect = 16.0f / 9.0f;
|
||||||
|
float currentAspect = static_cast<float>(width) / static_cast<float>(height);
|
||||||
|
|
||||||
|
// Adjust dimensions to maintain the target aspect ratio.
|
||||||
|
int newWidth = width;
|
||||||
|
int newHeight = height;
|
||||||
|
if (currentAspect > targetAspect) {
|
||||||
|
// The viewport is too wide: adjust width.
|
||||||
|
newWidth = static_cast<int>(height * targetAspect);
|
||||||
|
} else if (currentAspect < targetAspect) {
|
||||||
|
// The viewport is too tall: adjust height.
|
||||||
|
newHeight = static_cast<int>(width / targetAspect);
|
||||||
|
}
|
||||||
|
|
||||||
|
fbWidth = newWidth;
|
||||||
|
fbHeight = newHeight;
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||||
|
|
||||||
@ -92,6 +111,7 @@ void Engine::ResizeFramebuffer(int width, int height) {
|
|||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GLuint Engine::CompileShader(const char* vertexSrc, const char* fragmentSrc) {
|
GLuint Engine::CompileShader(const char* vertexSrc, const char* fragmentSrc) {
|
||||||
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
glShaderSource(vertexShader, 1, &vertexSrc, nullptr);
|
glShaderSource(vertexShader, 1, &vertexSrc, nullptr);
|
||||||
@ -229,8 +249,8 @@ bool Engine::SetupScene() {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Ambient.
|
// Ambient.
|
||||||
float ambientStrength = 0.2;
|
float ambientStrength = 0.3;
|
||||||
vec3 ambient = ambientStrength * vec3(1.0, 0.0, 0.0);
|
vec3 ambient = ambientStrength * vec3(1.0, 0.0, 1.0);
|
||||||
|
|
||||||
// Diffuse.
|
// Diffuse.
|
||||||
vec3 norm = normalize(Normal);
|
vec3 norm = normalize(Normal);
|
||||||
@ -270,7 +290,7 @@ ImTextureID Engine::RenderScene(const glm::mat4 &view, const glm::mat4 &projecti
|
|||||||
glUniform3f(glGetUniformLocation(shaderProgram, "viewPos"), viewPos.x, viewPos.y, viewPos.z);
|
glUniform3f(glGetUniformLocation(shaderProgram, "viewPos"), viewPos.x, viewPos.y, viewPos.z);
|
||||||
|
|
||||||
rotationAngle += 0.01f;
|
rotationAngle += 0.01f;
|
||||||
glm::mat4 model = glm::rotate(glm::mat4(1.0f), rotationAngle, glm::vec3(1,1,1));
|
glm::mat4 model = glm::rotate(glm::mat4(1.0f), rotationAngle, glm::vec3(1,1,0));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, glm::value_ptr(model));
|
glUniformMatrix4fv(glGetUniformLocation(shaderProgram, "model"), 1, GL_FALSE, glm::value_ptr(model));
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(shaderProgram, "lightPos"), 0.0f, 20.0f, 0.0f);
|
glUniform3f(glGetUniformLocation(shaderProgram, "lightPos"), 0.0f, 20.0f, 0.0f);
|
||||||
|
BIN
Three-Labs.exe
BIN
Three-Labs.exe
Binary file not shown.
Binary file not shown.
@ -15,9 +15,10 @@ Collapsed=0
|
|||||||
DockId=0x00000001,0
|
DockId=0x00000001,0
|
||||||
|
|
||||||
[Window][Rendered Output]
|
[Window][Rendered Output]
|
||||||
Pos=337,0
|
Pos=336,0
|
||||||
Size=943,800
|
Size=944,800
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
DockId=0x00000002,0
|
||||||
|
|
||||||
[Window][Editor]
|
[Window][Editor]
|
||||||
Pos=176,231
|
Pos=176,231
|
||||||
@ -27,5 +28,5 @@ Collapsed=0
|
|||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,0 Size=1280,800 Split=X Selected=0x5098C5B2
|
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=0,0 Size=1280,800 Split=X Selected=0x5098C5B2
|
||||||
DockNode ID=0x00000001 Parent=0x08BD597D SizeRef=334,800 Selected=0x5098C5B2
|
DockNode ID=0x00000001 Parent=0x08BD597D SizeRef=334,800 Selected=0x5098C5B2
|
||||||
DockNode ID=0x00000002 Parent=0x08BD597D SizeRef=944,800 CentralNode=1
|
DockNode ID=0x00000002 Parent=0x08BD597D SizeRef=944,800 CentralNode=1 Selected=0xB6999AB4
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user