Integrate CMake Package Manager

This commit is contained in:
2024-01-19 14:23:02 -05:00
parent c4d926dd3e
commit 4626f5a37f
4 changed files with 54 additions and 16 deletions

View File

@@ -17,7 +17,12 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Enable Package Managers # Enable Package Managers
#include(cmake/CPM.cmake) include(cmake/CPM.cmake)
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-7.zip
)
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp") file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" ) file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" )
@@ -34,6 +39,7 @@ find_package(GLUT REQUIRED)
add_executable(JGL_Demo main.cpp) add_executable(JGL_Demo main.cpp)
set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib") set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
include_directories(${PROJECT_SOURCE_DIR}/include include_directories(${PROJECT_SOURCE_DIR}/include
${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS}) ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS}
${J3ML_SOURCE_DIR}/include)
target_link_libraries(JGL_Demo PUBLIC JGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES}) target_link_libraries(JGL_Demo PUBLIC JGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} J3ML)

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})

View File

@@ -3,8 +3,16 @@
// //
#pragma once #pragma once
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Vector2.h>
// OpenGL Wrapper for rendering 2D graphics primitives in both a 2D and 3D context // OpenGL Wrapper for rendering 2D graphics primitives in both a 2D and 3D context
namespace JGL { namespace JGL {
// All functions accept coordinates in pixel-screen space [0, 600]
// and are internally transformed to OpenGL clip space [-1, +1]
using namespace LinearAlgebra;
namespace J2D { namespace J2D {
} }
@@ -29,14 +37,12 @@ namespace JGL {
Vector2 ScreenToViewport(const Vector2& v); Vector2 ScreenToViewport(const Vector2& v);
Vector2 ViewportToScreen(const Vector2& v); Vector2 ViewportToScreen(const Vector2& v);
Color3 GetColor();
void SetColor(const Color3 &color);
void DrawPixel2D(const Color3 &, int x, int y); void DrawPixel2D(const Color3 &, int x, int y);
void DrawPixel2D(const Vector2 &coordinates); void DrawPixel2D(const Color3& color, const Vector2 &coordinates);
void DrawLine2D(const Vector2 &A, const Vector2 &B); void DrawLine2D(const Color3& color, const Vector2 &A, const Vector2 &B);
void DrawLine3D(const Vector3 &A, const Vector3 &B); void DrawLine3D(const Color3& color, const Vector3 &A, const Vector3 &B);
void DrawCubicBezierCurve2D(); void DrawCubicBezierCurve2D();
void OutlineCircle2D(const Vector2 center, float radius, int subdivisions, Color3 color); void OutlineCircle2D(const Color3& color, const Vector2& center, float radius, int subdivisions);
void FillSphere3D(); void FillSphere3D();
void WireframeSphere3D(); void WireframeSphere3D();
void FillCircle2D(); void FillCircle2D();
@@ -49,14 +55,14 @@ namespace JGL {
void DrawString(); void DrawString();
void FillRect2D(const Vector2 &pos, const Vector2 &size, const Color3 &color) void FillRect2D(const Vector2 &pos, const Vector2 &size, const Color3 &color)
{ {
pos = ScreenToViewport(pos); auto vp_pos = ScreenToViewport(pos);
size = ScreenToViewport(size); auto vp_size = ScreenToViewport(size);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3f(color.r, color.g, color.b); glColor3f(color.r, color.g, color.b);
glVertex2f(pos.x, pos.y); glVertex2f(vp_pos.x, vp_pos.y);
glVertex2f(pos.x, pos.y + size.y); glVertex2f(vp_pos.x, vp_pos.y + vp_size.y);
glVertex2f(pos.x + size.x, pos.y + size.y); glVertex2f(vp_pos.x + vp_size.x, vp_pos.y + vp_size.y);
glVertex2f(pos.x + size.x, pos.y); glVertex2f(vp_pos.x + vp_size.x, vp_pos.y);
glEnd(); glEnd();
} }
void OutlineRect2D (const Vector2& pos, const Vector2& size, const Color3& color, float thickness = 1); void OutlineRect2D (const Vector2& pos, const Vector2& size, const Color3& color, float thickness = 1);

View File

@@ -1,4 +1,6 @@
#include <GL/glut.h> #include <GL/glut.h>
#include "JGL/JGL.h"
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
#include <windows.h> #include <windows.h>
#endif #endif
@@ -40,7 +42,7 @@ void display() {
glVertex2f(-0.9f, -0.3f); glVertex2f(-0.9f, -0.3f);
glEnd(); glEnd();
FillRect2D() JGL::FillRect2D();
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
glColor3f(0.0f, 0.0f, 1.f); // Blue glColor3f(0.0f, 0.0f, 1.f); // Blue