Skip to content

Commit

Permalink
Added support for blending, and loading both RGB and RGBA textures
Browse files Browse the repository at this point in the history
  • Loading branch information
Yousazoe committed Feb 21, 2022
1 parent f19ebd7 commit f1d52d4
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Infinite/src/Infinite/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace Infinite {
m_Window = std::unique_ptr<Window>(Window::Create());
m_Window->SetEventCallback(BIND_EVENT_FN(OnEvent));

Renderer::Init();

m_ImGuiLayer = new ImGuiLayer();
PushOverlay(m_ImGuiLayer);
}
Expand Down
5 changes: 5 additions & 0 deletions Infinite/src/Infinite/Renderer/RenderCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace Infinite {
class RenderCommand
{
public:
inline static void Init()
{
s_RendererAPI->Init();
}

inline static void SetClearColor(const glm::vec4& color)
{
s_RendererAPI->SetClearColor(color);
Expand Down
5 changes: 5 additions & 0 deletions Infinite/src/Infinite/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace Infinite {

Renderer::SceneData* Renderer::s_SceneData = new Renderer::SceneData;

void Renderer::Init()
{
RenderCommand::Init();
}

void Renderer::BeginScene(OrthographicCamera& camera)
{
s_SceneData->ViewProjectionMatrix = camera.GetViewProjectionMatrix();
Expand Down
2 changes: 2 additions & 0 deletions Infinite/src/Infinite/Renderer/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Infinite {
class Renderer
{
public:
static void Init();

static void BeginScene(OrthographicCamera& camera);
static void EndScene();

Expand Down
1 change: 1 addition & 0 deletions Infinite/src/Infinite/Renderer/RendererAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Infinite {


public:
virtual void Init() = 0;
virtual void SetClearColor(const glm::vec4& color) = 0;
virtual void Clear() = 0;

Expand Down
6 changes: 6 additions & 0 deletions Infinite/src/Platform/OpenGL/OpenGLRendererAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#include <glad/glad.h>

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


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

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

Expand Down
18 changes: 16 additions & 2 deletions Infinite/src/Platform/OpenGL/OpenGLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@ namespace Infinite {
m_Width = width;
m_Height = height;

GLenum internalFormat = 0, dataFormat = 0;
if (channels == 4)
{
internalFormat = GL_RGBA8;
dataFormat = GL_RGBA;
}
else if (channels == 3)
{
internalFormat = GL_RGB8;
dataFormat = GL_RGB;
}

IFN_CORE_ASSERT(internalFormat & dataFormat, "Format not supported!");

glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
glTextureStorage2D(m_RendererID, 1, GL_RGB8, m_Width, m_Height);
glTextureStorage2D(m_RendererID, 1, internalFormat, m_Width, m_Height);

glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, GL_RGB, GL_UNSIGNED_BYTE, data);
glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, dataFormat, GL_UNSIGNED_BYTE, data);

stbi_image_free(data);
}
Expand Down
Binary file added Sandbox/assets/textures/InfiniteLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion Sandbox/src/SandboxApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class ExampleLayer : public Infinite::Layer
m_TextureShader.reset(Infinite::Shader::Create(textureShaderVertexSrc, textureShaderFragmentSrc));

m_Texture = Infinite::Texture2D::Create("assets/textures/Checkerboard.png");
m_InfiniteLogoTexture = Infinite::Texture2D::Create("assets/textures/InfiniteLogo.png");

std::dynamic_pointer_cast<Infinite::OpenGLShader>(m_TextureShader)->Bind();
std::dynamic_pointer_cast<Infinite::OpenGLShader>(m_TextureShader)->UploadUniformInt("u_Texture", 0);
Expand Down Expand Up @@ -214,6 +215,9 @@ class ExampleLayer : public Infinite::Layer
m_Texture->Bind();
Infinite::Renderer::Submit(m_TextureShader, m_SquareVertexArray, glm::scale(glm::mat4(1.0f), glm::vec3(1.5f)));

m_InfiniteLogoTexture->Bind();
Infinite::Renderer::Submit(m_TextureShader, m_SquareVertexArray, glm::scale(glm::mat4(1.0f), glm::vec3(1.5f)));

// Triangle
// Infinite::Renderer::Submit(m_Shader, m_VertexArray);

Expand Down Expand Up @@ -243,7 +247,7 @@ class ExampleLayer : public Infinite::Layer

Infinite::Ref<Infinite::Shader> m_FlatColorShader, m_TextureShader;
Infinite::Ref<Infinite::VertexArray> m_SquareVertexArray;
Infinite::Ref<Infinite::Texture2D> m_Texture;
Infinite::Ref<Infinite::Texture2D> m_Texture, m_InfiniteLogoTexture;

Infinite::OrthographicCamera m_Camera;
glm::vec3 m_CameraPosition;
Expand Down
Binary file modified logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f1d52d4

Please sign in to comment.