create SkeletalAnimationDemo
This commit is contained in:
@@ -82,7 +82,9 @@ file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp")
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
add_library(LearnOpenGL SHARED ${SOURCES}
|
||||
src/LearnOpenGL/IndexBuffer.cpp)
|
||||
src/LearnOpenGL/IndexBuffer.cpp
|
||||
include/LearnOpenGL/ComputeShader.h
|
||||
src/demos/SkeletalAnim/main.cpp)
|
||||
|
||||
target_include_directories(LearnOpenGL PUBLIC ${J3ML_SOURCE_DIR}/include)
|
||||
target_include_directories(LearnOpenGL PUBLIC ${glad_SOURCE_DIR}/include)
|
||||
@@ -104,4 +106,6 @@ target_include_directories(LearnOpenGLDemo PRIVATE ${ReWindow_SOURCE_DIR}/includ
|
||||
target_link_libraries(LearnOpenGLDemo PRIVATE ReWindowLibrary)
|
||||
|
||||
|
||||
target_link_libraries(LearnOpenGLDemo PUBLIC LearnOpenGL)
|
||||
target_link_libraries(LearnOpenGLDemo PUBLIC LearnOpenGL)
|
||||
|
||||
add_subdirectory(src/demos/SkeletalAnim)
|
@@ -1,8 +1,30 @@
|
||||
//
|
||||
// Created by dawsh on 2/22/24.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifndef LEARNOPENGL_LEARNOPENGL_H
|
||||
#define LEARNOPENGL_LEARNOPENGL_H
|
||||
#define INCLUDE_SKELETAL
|
||||
|
||||
#endif //LEARNOPENGL_LEARNOPENGL_H
|
||||
#ifdef INCLUDE_SKELETAL
|
||||
// TODO: consider moving to 'Skeletal' directory
|
||||
#include <LearnOpenGL/Animator.h>
|
||||
#include <LearnOpenGL/Animation.h>
|
||||
#include <LearnOpenGL/Bone.h>
|
||||
#include <LearnOpenGL/BoneInfo.h>
|
||||
#include <LearnOpenGL/Model.h>
|
||||
#endif
|
||||
|
||||
#include <LearnOpenGL/Camera2D.h>
|
||||
#include <LearnOpenGL/Camera3D.h>
|
||||
#include <LearnOpenGL/ComputeShader.h>
|
||||
#include <LearnOpenGL/CubeMap.h>
|
||||
#include <LearnOpenGL/FrameBuffer.h>
|
||||
#include <LearnOpenGL/IndexBuffer.h>
|
||||
#include <LearnOpenGL/Mesh.h>
|
||||
#include <LearnOpenGL/Shader.h>
|
||||
#include <LearnOpenGL/RenderBuffer.h>
|
||||
#include <LearnOpenGL/Skybox.h>
|
||||
#include <LearnOpenGL/Texture.h>
|
||||
#include <LearnOpenGL/Texture2D.h>
|
||||
#include <LearnOpenGL/Vertex.h>
|
||||
#include <LearnOpenGL/VertexArray.h>
|
||||
#include <LearnOpenGL/VertexBuffer.h>
|
||||
|
||||
using namespace LearnOpenGL;
|
17
main.cpp
17
main.cpp
@@ -2,30 +2,37 @@
|
||||
|
||||
#include <LearnOpenGL/Texture2D.h>
|
||||
#include <LearnOpenGL/Shader.h>
|
||||
//#include <LearnOpenGL/Mesh.h>
|
||||
//#include <LearnOpenGL/Model.h>
|
||||
#include <rewindow/types/window.h>
|
||||
|
||||
class LearnOpenGLDemoWindow : public ReWindow::RWindow
|
||||
{
|
||||
public:
|
||||
|
||||
LearnOpenGLDemoWindow() : ReWindow::RWindow("LearnOpenGL Window", 1000, 600, RenderingAPI::OPENGL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OnRefresh(float dt) override
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::cout << "OpenGL Utility Classes" << std::endl;
|
||||
|
||||
auto window = new LearnOpenGLDemoWindow();
|
||||
window->setRenderer(RenderingAPI::OPENGL);
|
||||
window->Open();
|
||||
gladLoadGL();
|
||||
|
||||
LearnOpenGL::Texture2D testTexture;
|
||||
|
||||
std::cout << glGetString(GL_VERSION) << std::endl;
|
||||
while (window->isAlive())
|
||||
{
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -52,13 +52,14 @@ namespace LearnOpenGL
|
||||
}
|
||||
|
||||
void FrameBuffer::AddAttachment(int idx, int internalFormat, int format, int width, int height) {
|
||||
// TODO: Kick Rocks Until We Update OpenGL
|
||||
unsigned int rt;
|
||||
glGenTextures(1, &rt);
|
||||
glBindTexture(GL_TEXTURE_2D, rt);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, GL_FLOAT, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + idx, GL_TEXTURE_2D, rt, 0);
|
||||
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + idx, GL_TEXTURE_2D, rt, 0);
|
||||
|
||||
Attachments.push_back(rt);
|
||||
}
|
||||
|
18
src/demos/SkeletalAnim/CMakeLists.txt
Normal file
18
src/demos/SkeletalAnim/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.18..3.27)
|
||||
|
||||
project(SkeletalAnim
|
||||
VERSION 1.5
|
||||
LANGUAGES CXX)
|
||||
|
||||
# Redacted Software's ReWindow Library
|
||||
# One Class Header, Implemented for multiple platforms
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.18.zip
|
||||
)
|
||||
|
||||
add_executable(SkeletalAnim main.cpp)
|
||||
|
||||
target_include_directories(SkeletalAnim PRIVATE ${ReWindow_SOURCE_DIR}/include)
|
||||
target_link_libraries(SkeletalAnim PRIVATE ReWindowLibrary)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE LearnOpenGL)
|
61
src/demos/SkeletalAnim/main.cpp
Normal file
61
src/demos/SkeletalAnim/main.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
#include <LearnOpenGL/LearnOpenGL.h>
|
||||
|
||||
#include <rewindow/types/window.h>
|
||||
|
||||
|
||||
class SkeletalAnimationDemo : public ReWindow::RWindow
|
||||
{
|
||||
public:
|
||||
Model ourModel;
|
||||
Animation animation;
|
||||
Animator animator;
|
||||
Shader shader;
|
||||
Camera3D camera;
|
||||
SkeletalAnimationDemo() : ReWindow::RWindow("Skeletal Animation Demo", 1024, 768, RenderingAPI::OPENGL)
|
||||
{
|
||||
|
||||
}
|
||||
void OnRefresh(float dt) override
|
||||
{
|
||||
// draw in wireframe
|
||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
// pretend there's code
|
||||
|
||||
animator.UpdateAnimations(dt);
|
||||
glClearColor(0.05f, 0.05f, 0.05f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
shader.use();
|
||||
Matrix4x4 Projection = Matrix4x4::OpenGLPerspProjLH(0, 1, 1, 1);
|
||||
Matrix4x4 View = camera.GetViewMatrix();
|
||||
shader.setMat4("projection", Projection);
|
||||
shader.setMat4("view", View);
|
||||
auto transforms = animator.GetFinalBoneMatrices();
|
||||
for (int i = 0; i < transforms.size(); ++i)
|
||||
shader.setMat4("finalBoneMatrices[" + std::to_string(i) + "]", transforms[i]);
|
||||
Matrix4x4 model = Matrix4x4(1.f);
|
||||
model = model.Translate(Vector3(0.f, -0.4f, 0.f));
|
||||
model = model.Scale({.5f, .5f, .5f});
|
||||
shader.setMat4("model", model);
|
||||
ourModel.Draw(shader);
|
||||
}
|
||||
protected:
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
auto* window = new SkeletalAnimationDemo();
|
||||
window->setRenderer(RenderingAPI::OPENGL);
|
||||
window->Open();
|
||||
gladLoadGL();
|
||||
|
||||
while (window->isAlive())
|
||||
{
|
||||
window->pollEvents();
|
||||
window->refresh();
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user