add opengl code
This commit is contained in:
@ -2,7 +2,11 @@ project(Sandbox)
|
||||
|
||||
file(GLOB_RECURSE SRC_SOURCE ./**.cpp)
|
||||
|
||||
file(GLOB ASSETS assets)
|
||||
file(COPY ${ASSETS} DESTINATION ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SRC_SOURCE})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Prism)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Prism)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE ENABLE_DOCKSPACE)
|
||||
@ -5,6 +5,7 @@
|
||||
#include "DemoLayer.h"
|
||||
|
||||
#include "Prism/Renderer/Renderer.h"
|
||||
#include "Prism/Renderer/Shader.h"
|
||||
|
||||
static void ImGuiShowHelpMarker(const char* desc)
|
||||
{
|
||||
@ -29,6 +30,24 @@ DemoLayer::~DemoLayer()
|
||||
|
||||
void DemoLayer::OnAttach()
|
||||
{
|
||||
static float vertices[] = {
|
||||
-0.5f, -0.5f, 0.0f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f
|
||||
};
|
||||
|
||||
static unsigned int indices[] = {
|
||||
0, 1, 2
|
||||
};
|
||||
|
||||
m_VertexBuffer = std::unique_ptr<Prism::VertexBuffer>(Prism::VertexBuffer::Create());
|
||||
m_VertexBuffer->SetData(vertices, sizeof(vertices));
|
||||
|
||||
m_IndexBuffer = std::unique_ptr<Prism::IndexBuffer>(Prism::IndexBuffer::Create());
|
||||
m_IndexBuffer->SetData(indices, sizeof(indices));
|
||||
|
||||
|
||||
m_Shader.reset(Prism::Shader::Create("assets/shaders/shader.glsl"));
|
||||
}
|
||||
|
||||
void DemoLayer::OnDetach()
|
||||
@ -38,6 +57,10 @@ void DemoLayer::OnDetach()
|
||||
void DemoLayer::OnUpdate()
|
||||
{
|
||||
Prism::Renderer::Clear(m_ClearColor[0], m_ClearColor[1], m_ClearColor[2], m_ClearColor[3]);
|
||||
m_Shader->Bind();
|
||||
m_VertexBuffer->Bind();
|
||||
m_IndexBuffer->Bind();
|
||||
Prism::Renderer::DrawIndexed(3);
|
||||
}
|
||||
|
||||
void DemoLayer::OnImGuiRender()
|
||||
@ -49,6 +72,7 @@ void DemoLayer::OnImGuiRender()
|
||||
ImGui::Begin("GameLayer");
|
||||
ImGui::ColorEdit4("Clear Color", m_ClearColor);
|
||||
ImGui::End();
|
||||
|
||||
#if ENABLE_DOCKSPACE
|
||||
|
||||
static bool p_open = true;
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
|
||||
#ifndef DEMOLAYER_H
|
||||
#define DEMOLAYER_H
|
||||
#include "Prism/Core/Layer.h"
|
||||
|
||||
#include "Prism.h"
|
||||
|
||||
class DemoLayer : public Prism::Layer
|
||||
{
|
||||
@ -21,6 +21,10 @@ public:
|
||||
|
||||
private:
|
||||
float m_ClearColor[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
|
||||
|
||||
std::unique_ptr<Prism::VertexBuffer> m_VertexBuffer;
|
||||
std::unique_ptr<Prism::IndexBuffer> m_IndexBuffer;
|
||||
std::unique_ptr<Prism::Shader> m_Shader;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
//
|
||||
|
||||
|
||||
#include "Layer/DemoLayer.h"
|
||||
#include "Prism/Core/Application.h"
|
||||
#include "Prism.h"
|
||||
#include "Prism/Core/EntryPoint.h"
|
||||
#include "Prism/Core/ImGui/ImGuiLayer.h"
|
||||
|
||||
#include "Layer/DemoLayer.h"
|
||||
|
||||
class Sandbox : public Prism::Application
|
||||
{
|
||||
|
||||
19
Sandbox/assets/shaders/shader.glsl
Normal file
19
Sandbox/assets/shaders/shader.glsl
Normal file
@ -0,0 +1,19 @@
|
||||
#type vertex
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 a_Position;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(a_Position, 1.0);
|
||||
}
|
||||
|
||||
#type fragment
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) out vec4 o_Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
o_Color = vec4(1.0, 0.0, 1.0, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user