initial commit

This commit is contained in:
2025-04-19 16:58:48 -04:00
commit 80be946267
4 changed files with 125 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
/.idea
/.cache
/.ccls-cache
/compile_commands.json
/cmake-build-debug
/build

34
CMakeLists.txt Normal file
View File

@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.18..3.29)
project(jgl_example_project)
set(CMAKE_CXX_STANDARD 20)
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include (cmake/CPM.cmake)
CPMAddPackage(
NAME JGL
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-54.zip
)
CPMAddPackage(
NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-32.zip
)
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp")
add_executable(jgl_example_project main.cpp)
target_include_directories(jgl_example_project PUBLIC
${JGL_SOURCE_DIR}/include
${ReWindow_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/include
)
target_link_libraries(jgl_example_project PUBLIC JGL ReWindow)

24
cmake/CPM.cmake Normal file
View File

@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
set(CPM_DOWNLOAD_VERSION 0.38.7)
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5")
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)
include(${CPM_DOWNLOAD_LOCATION})

61
main.cpp Normal file
View File

@@ -0,0 +1,61 @@
#include <JGL/JGL.h>
#include <ReWindow/types/Window.h>
#include <ReWindow/Logger.h>
class Window : public ReWindow::OpenGLWindow {
private:
Vector2 box_pos = Vector2::Zero;
public:
Window(const std::string& title, unsigned int width, unsigned int height) : ReWindow::OpenGLWindow(title, width, height, 2, 1) {}
~Window() override = default;
void InitGL() {
if (!JGL::Init({ GetSize().x, GetSize().y}, 75, 100))
throw std::runtime_error("We encountered an error while initializing JGL.");
glClearColor(0.f, 0.f, 0.f, 0.f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
}
void Display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
JGL::Update({ GetSize().x, GetSize().y });
// Rendering goes here.
J2D::Begin(nullptr, true);
J2D::FillRect(Colors::Red, box_pos, {32, 32});
J2D::End();
}
void OnRefresh(float elapsed) override {
// Code that runs every frame (that is not rendering) goes here.
if (IsKeyDown(Keys::W))
box_pos.y -= 240 * GetDeltaTime();
if (IsKeyDown(Keys::S))
box_pos.y += 240 * GetDeltaTime();
if (IsKeyDown(Keys::A))
box_pos.x -= 240 * GetDeltaTime();
if (IsKeyDown(Keys::D))
box_pos.x += 240 * GetDeltaTime();
Display();
ReWindow::OpenGLWindow::SwapBuffers();
}
};
int main() {
auto* window = new Window("title", 1152, 864);
if (!window->Open())
throw std::runtime_error("We encountered an error while opening the window.");
ReWindow::Logger::Debug.EnableConsole(false);
window->SetVsyncEnabled(true);
window->SetResizable(false);
window->InitGL();
while (!window->IsClosing())
window->ManagedRefresh();
}