diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d8a62a..542c2b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,12 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") # 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 SOURCES "src/*.c" "src/*.cpp" ) @@ -34,6 +39,7 @@ find_package(GLUT REQUIRED) add_executable(JGL_Demo main.cpp) set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib") 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) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..cc25ec2 --- /dev/null +++ b/cmake/CPM.cmake @@ -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}) diff --git a/include/JGL/JGL.h b/include/JGL/JGL.h index b599f3c..712c5d0 100644 --- a/include/JGL/JGL.h +++ b/include/JGL/JGL.h @@ -3,8 +3,16 @@ // #pragma once +#include +#include + // OpenGL Wrapper for rendering 2D graphics primitives in both a 2D and 3D context 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 { } @@ -29,14 +37,12 @@ namespace JGL { Vector2 ScreenToViewport(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 Vector2 &coordinates); - void DrawLine2D(const Vector2 &A, const Vector2 &B); - void DrawLine3D(const Vector3 &A, const Vector3 &B); + void DrawPixel2D(const Color3& color, const Vector2 &coordinates); + void DrawLine2D(const Color3& color, const Vector2 &A, const Vector2 &B); + void DrawLine3D(const Color3& color, const Vector3 &A, const Vector3 &B); 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 WireframeSphere3D(); void FillCircle2D(); @@ -49,14 +55,14 @@ namespace JGL { void DrawString(); void FillRect2D(const Vector2 &pos, const Vector2 &size, const Color3 &color) { - pos = ScreenToViewport(pos); - size = ScreenToViewport(size); + auto vp_pos = ScreenToViewport(pos); + auto vp_size = ScreenToViewport(size); glBegin(GL_QUADS); glColor3f(color.r, color.g, color.b); - glVertex2f(pos.x, pos.y); - glVertex2f(pos.x, pos.y + size.y); - glVertex2f(pos.x + size.x, pos.y + size.y); - glVertex2f(pos.x + size.x, pos.y); + glVertex2f(vp_pos.x, vp_pos.y); + glVertex2f(vp_pos.x, vp_pos.y + vp_size.y); + glVertex2f(vp_pos.x + vp_size.x, vp_pos.y + vp_size.y); + glVertex2f(vp_pos.x + vp_size.x, vp_pos.y); glEnd(); } void OutlineRect2D (const Vector2& pos, const Vector2& size, const Color3& color, float thickness = 1); diff --git a/main.cpp b/main.cpp index 4183944..7f8a7fc 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,6 @@ #include +#include "JGL/JGL.h" + #if defined(_WIN32) || defined(_WIN64) #include #endif @@ -40,7 +42,7 @@ void display() { glVertex2f(-0.9f, -0.3f); glEnd(); - FillRect2D() + JGL::FillRect2D(); glBegin(GL_TRIANGLES); glColor3f(0.0f, 0.0f, 1.f); // Blue