Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion GenerateProject.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
@echo off
call vendor\bin\premake\premake5.exe vs2022
PAUSE
IF %ERRORLEVEL% NEQ 0 (
PAUSE
)
32 changes: 32 additions & 0 deletions Sandbox/assets/shaders/Texture.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//Basic texture shader

#type vertex
#version 330 core

layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec2 a_TexCoord;

uniform mat4 u_ViewProjection;
uniform mat4 u_Transform;

out vec2 v_TexCoord;

void main()
{
v_TexCoord = a_TexCoord;
gl_Position = u_ViewProjection * u_Transform * vec4(a_Position, 1.0);
}

#type fragment
#version 330 core

layout(location = 0) out vec4 color;

in vec2 v_TexCoord;

uniform sampler2D u_Texture;

void main()
{
color = texture(u_Texture, v_TexCoord);
}
Binary file added Sandbox/assets/textures/Checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sandbox/assets/textures/starLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 36 additions & 16 deletions Sandbox/src/SandboxApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ class ExampleLayer : public StarStudio::Layer

m_SquareVA.reset(StarStudio::VertexArray::Create());

float squareVertices[3 * 4] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.5f, 0.5f, 0.0f,
-0.5f, 0.5f, 0.0f
float squareVertices[5 * 4] = {
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.0f ,0.0f, 1.0f
};

StarStudio::Ref<StarStudio::VertexBuffer> squareVB;
squareVB.reset(StarStudio::VertexBuffer::Create(squareVertices, sizeof(squareVertices)));
squareVB->SetLayout({
{ StarStudio::ShaderDataType::Float3, "a_Position" }
{ StarStudio::ShaderDataType::Float3, "a_Position" },
{ StarStudio::ShaderDataType::Float2, "a_TexCoord" }
});
m_SquareVA->AddVertexBuffer(squareVB);

Expand All @@ -74,7 +75,7 @@ class ExampleLayer : public StarStudio::Layer
v_Color = a_Color;
gl_Position = u_ViewProjection * u_Transform * vec4(a_Position, 1.0);
}
)";
)";

std::string fragmentSrc = R"(
#version 330 core
Expand All @@ -89,9 +90,9 @@ class ExampleLayer : public StarStudio::Layer
color = vec4(v_Position * 0.5 + 0.5, 1.0);
color = v_Color;
}
)";
)";

m_Shader.reset(StarStudio::Shader::Create(vertexSrc, fragmentSrc));
m_Shader = StarStudio::Shader::Create("VertexPosColor", vertexSrc, fragmentSrc);

std::string flatColorShaderVertexSrc = R"(
#version 330 core
Expand Down Expand Up @@ -124,8 +125,15 @@ class ExampleLayer : public StarStudio::Layer
color = vec4(u_Color, 1.0);
}
)";
m_FlatColorShader = StarStudio::Shader::Create("FlatColor", flatColorShaderVertexSrc, flatColorShaderFragmentSrc);

auto textureShader = m_ShaderLibrary.Load("assets/shaders/Texture.glsl");

m_FlatColorShader.reset(StarStudio::Shader::Create(flatColorShaderVertexSrc, flatColorShaderFragmentSrc));
m_Texture = StarStudio::Texture2D::Create("assets/textures/Checkerboard.png");
m_starLogTexture = StarStudio::Texture2D::Create("assets/textures/starLogo.png");

std::dynamic_pointer_cast<StarStudio::OpenGLShader>(textureShader)->Bind();
std::dynamic_pointer_cast<StarStudio::OpenGLShader>(textureShader)->UploadUniformInt("u_Texture", 0);

}

Expand Down Expand Up @@ -159,7 +167,7 @@ class ExampleLayer : public StarStudio::Layer
std::dynamic_pointer_cast<StarStudio::OpenGLShader>(m_FlatColorShader)->Bind();
std::dynamic_pointer_cast<StarStudio::OpenGLShader>(m_FlatColorShader)->UploadUniformFloat3("u_Color", m_SquareColor);

for (int y = 0; y < 20; y++)
/*for (int y = 0; y < 20; y++)
{
for (int x = 0; x < 20; x++)
{
Expand All @@ -168,9 +176,18 @@ class ExampleLayer : public StarStudio::Layer

StarStudio::Renderer::Submit(m_FlatColorShader, m_SquareVA, transform);
}
}
}*/

auto textureShader = m_ShaderLibrary.Get("Texture");

StarStudio::Renderer::Submit(m_Shader, m_VertexArray);
m_Texture->Bind();
StarStudio::Renderer::Submit(textureShader, m_SquareVA, glm::scale(glm::mat4(1.0f), glm::vec3(1.5f)));

m_starLogTexture->Bind();
StarStudio::Renderer::Submit(textureShader, m_SquareVA, glm::scale(glm::mat4(1.0f), glm::vec3(1.5f)));

//triangle
//StarStudio::Renderer::Submit(m_Shader, m_VertexArray);

StarStudio::Renderer::EndScene();
}
Expand All @@ -194,7 +211,7 @@ class ExampleLayer : public StarStudio::Layer
}

ImGui::End();

/*
//Color Picker
ImGui::Begin("Color Picker");

Expand All @@ -205,20 +222,23 @@ class ExampleLayer : public StarStudio::Layer
}

ImGui::End();
}

*/
}
void OnEvent(StarStudio::Event& event) override
{

}

private:
StarStudio::ShaderLibrary m_ShaderLibrary;
StarStudio::Ref<StarStudio::Shader> m_Shader;
StarStudio::Ref<StarStudio::VertexArray> m_VertexArray;

StarStudio::Ref<StarStudio::Shader> m_FlatColorShader;
StarStudio::Ref<StarStudio::VertexArray> m_SquareVA;

StarStudio::Ref<StarStudio::Texture2D> m_Texture, m_starLogTexture;

StarStudio::OrthographicCamera m_Camera;
glm::vec3 m_CameraPosition;
float m_CameraMoveSpeed = 5.0f;
Expand Down
4 changes: 2 additions & 2 deletions StarStudio/src/Platform/OpenGL/OpenGLBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace StarStudio {
: m_Count(count)
{
glCreateBuffers(1, &m_RendererID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(uint32_t), indices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, m_RendererID);
glBufferData(GL_ARRAY_BUFFER, count * sizeof(uint32_t), indices, GL_STATIC_DRAW);
}

OpenGLIndexBuffer::~OpenGLIndexBuffer()
Expand Down
6 changes: 6 additions & 0 deletions StarStudio/src/Platform/OpenGL/OpenGLRendererAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

namespace StarStudio
{
void OpenGLRendererAPI::Init()
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

void OpenGLRendererAPI::SetClearColor(const glm::vec4& color)
{
glClearColor(color.r, color.g, color.b, color.a);
Expand Down
2 changes: 2 additions & 0 deletions StarStudio/src/Platform/OpenGL/OpenGLRendererAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace StarStudio
class OpenGLRendererAPI : public RendererAPI
{
public:
virtual void Init() override;

virtual void SetClearColor(const glm::vec4& color) override;
virtual void Clear() override;

Expand Down
Loading
Loading