Compare commits
13 Commits
Prerelease
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
|
48493cb2fc | ||
5b7829b1f8 | |||
868f52464e | |||
d1d2493435 | |||
da30a7eedd | |||
5d906d6f99 | |||
6107e9a762 | |||
a38a83692f | |||
c4d6426587 | |||
817b0166c0 | |||
2a98857bab | |||
29a64160e9 | |||
f676ef5332 |
130
CMakeLists.txt
130
CMakeLists.txt
@@ -1,63 +1,67 @@
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
project(JGL
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||
message(FATAL_ERROR "In-source builds are not allowed")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "-municode")
|
||||
endif(WIN32)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
|
||||
# Enable Package Managers
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME J3ML
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-18.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.13.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME GLAD
|
||||
URL https://git.redacted.cc/Redacted/glad/archive/v2.1.zip
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" )
|
||||
file(GLOB_RECURSE ASSETS "content/*")
|
||||
|
||||
add_library(JGL SHARED ${SOURCES}
|
||||
include/JGL/JGL.h
|
||||
src/JGL/JGL.cpp
|
||||
include/LearnOpenGL/Shader.h
|
||||
src/LearnOpenGL/Shader.cpp)
|
||||
set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLUT REQUIRED)
|
||||
find_package(Freetype REQUIRED)
|
||||
|
||||
add_executable(JGL_Demo main.cpp)
|
||||
set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
include_directories(${OPENGL_INCLUDE_DIRS})
|
||||
include_directories(${GLUT_INCLUDE_DIRS})
|
||||
include_directories(${J3ML_SOURCE_DIR}/include)
|
||||
include_directories(${ReWindow_SOURCE_DIR}/include)
|
||||
include_directories(${glad_SOURCE_DIR}/include)
|
||||
|
||||
target_link_libraries(JGL PRIVATE ${FREETYPE_LIBRARIES})
|
||||
target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
||||
target_link_libraries(JGL_Demo PUBLIC JGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} J3ML ReWindowLibrary GLEW glad)
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
project(JGL
|
||||
VERSION 1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||
message(FATAL_ERROR "In-source builds are not allowed")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "-municode")
|
||||
endif(WIN32)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
|
||||
|
||||
# Enable Package Managers
|
||||
include(cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME J3ML
|
||||
URL https://git.redacted.cc/josh/j3ml/archive/Prerelease-18.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.19.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME GLAD
|
||||
URL https://git.redacted.cc/Redacted/glad/archive/v2.1.zip
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" )
|
||||
file(GLOB_RECURSE ASSETS "content/*")
|
||||
|
||||
add_library(JGL SHARED ${SOURCES}
|
||||
include/JGL/JGL.h
|
||||
src/JGL/JGL.cpp
|
||||
include/LearnOpenGL/Shader.h
|
||||
include/LearnOpenGL/Texture2D.h
|
||||
include/JGL/Color3.h
|
||||
include/JGL/Colors.h
|
||||
include/JGL/Color4.h
|
||||
)
|
||||
set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLUT REQUIRED)
|
||||
find_package(Freetype REQUIRED)
|
||||
|
||||
add_executable(JGL_Demo main.cpp)
|
||||
set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
include_directories(${OPENGL_INCLUDE_DIRS})
|
||||
include_directories(${GLUT_INCLUDE_DIRS})
|
||||
include_directories(${J3ML_SOURCE_DIR}/include)
|
||||
include_directories(${ReWindow_SOURCE_DIR}/include)
|
||||
include_directories(${glad_SOURCE_DIR}/include)
|
||||
|
||||
target_link_libraries(JGL PRIVATE ${FREETYPE_LIBRARIES})
|
||||
target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
||||
target_link_libraries(JGL_Demo PUBLIC JGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} J3ML ReWindowLibrary GLEW glad)
|
||||
|
@@ -3,6 +3,7 @@
|
||||
# Goals
|
||||
* Provide single-function-calls to render various graphics primitives in 2D and 3D.
|
||||
* Integrated directly with our other toolkits (ReWindow, J3ML)
|
||||
* Quick Rendering of Debug Text, Geometric Widgets, Textures, and so forth.
|
||||
|
||||
# Non-Goals
|
||||
* Full Rendering Engine
|
||||
|
32
include/JGL/Color3.h
Normal file
32
include/JGL/Color3.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <JGL/Color4.h>
|
||||
#include <J3ML/J3ML.h>
|
||||
|
||||
namespace JGL
|
||||
{
|
||||
using namespace J3ML;
|
||||
struct Color3 {
|
||||
u8 r;
|
||||
u8 g;
|
||||
u8 b;
|
||||
|
||||
Color3 Lerp(const Color3& rhs, float alpha) const;
|
||||
Color4 WithAlphaChannel(float alpha = 1) const;
|
||||
Color3(u8 R, u8 G, u8 B) : r(R), g(G), b(B) {}
|
||||
Color3(const Color4& c)
|
||||
{
|
||||
this->r = c.r;
|
||||
this->g = c.g;
|
||||
this->b = c.b;
|
||||
}
|
||||
u8 RedChannel () const { return r; }
|
||||
u8 GreenChannel() const { return g; }
|
||||
u8 BlueChannel () const { return b; }
|
||||
float RedChannelNormalized () const { return static_cast<float>(r) / 255.f;}
|
||||
float BlueChannelNormalized() const { return static_cast<float>(b) / 255.f;}
|
||||
float GreenChannelNormalized() const { return static_cast<float>(g) / 255.f;}
|
||||
};
|
||||
|
||||
|
||||
}
|
11
include/JGL/Color4.h
Normal file
11
include/JGL/Color4.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
namespace JGL
|
||||
{
|
||||
struct Color4{
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
int a;
|
||||
};
|
||||
}
|
178
include/JGL/Colors.h
Normal file
178
include/JGL/Colors.h
Normal file
@@ -0,0 +1,178 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <JGL/Color3.h>
|
||||
|
||||
namespace JGL
|
||||
{
|
||||
namespace Colors {
|
||||
namespace Primary {
|
||||
static const Color3 Red{255, 0, 0};
|
||||
static const Color3 Green{0, 255, 0};
|
||||
static const Color3 Blue{0, 0, 255};
|
||||
static const Color3 White{255, 255, 255};
|
||||
static const Color3 Black{0, 0, 0};
|
||||
static const Color3 Gray{128, 128, 128};
|
||||
static const Color3 DarkGray{192, 192, 192};
|
||||
static const Color3 LightGray{64, 64, 64};
|
||||
static const Color3 Yellow{255, 255, 0};
|
||||
}
|
||||
using namespace Primary;
|
||||
namespace Reds {
|
||||
static const Color3 Fuchsia {255, 0, 255};
|
||||
static const Color3 LightSalmon{255, 160, 122};
|
||||
static const Color3 Salmon{250, 128, 114};
|
||||
static const Color3 DarkSalmon{233, 150, 122};
|
||||
static const Color3 LightCoral{240, 128, 128};
|
||||
static const Color3 IndianRed{205, 92, 92};
|
||||
static const Color3 Crimson{220, 20, 60};
|
||||
static const Color3 Firebrick{178, 34, 34};
|
||||
static const Color3 DarkRed{139, 0, 0};
|
||||
}
|
||||
namespace Oranges {
|
||||
static const Color3 Coral{255, 127, 80};
|
||||
static const Color3 Tomato{255, 99, 71};
|
||||
static const Color3 OrangeRed{255, 69, 0};
|
||||
static const Color3 Gold{255, 215, 0};
|
||||
static const Color3 Orange{255, 165, 0};
|
||||
static const Color3 DarkOrange{255, 140, 0};
|
||||
}
|
||||
namespace Yellows {
|
||||
static const Color3 LightYellow{255, 255, 224};
|
||||
static const Color3 LemonChiffon{255, 250, 205};
|
||||
static const Color3 LightGoldenrodYellow{250, 250, 210};
|
||||
static const Color3 PapayaWhip{255, 239, 213};
|
||||
static const Color3 Moccasin{255, 228, 181};
|
||||
static const Color3 PeachPuff{255, 218, 185};
|
||||
static const Color3 PaleGoldenrod{238, 232, 170};
|
||||
static const Color3 Khaki{240, 230, 140};
|
||||
static const Color3 DarkKhaki{189, 183, 107};
|
||||
}
|
||||
namespace Greens {
|
||||
static const Color3 LawnGreen{124, 252, 0};
|
||||
static const Color3 Chartreuse{127, 255, 0};
|
||||
static const Color3 LimeGreen{50, 205, 50};
|
||||
static const Color3 ForestGreen{34, 139, 34};
|
||||
static const Color3 DarkGreen{0, 100, 0};
|
||||
static const Color3 GreenYellow{173, 255, 47};
|
||||
static const Color3 YellowGreen{154, 205, 50};
|
||||
static const Color3 SpringGreen{0, 255, 127};
|
||||
static const Color3 MediumSpringGreen{0, 250, 154};
|
||||
static const Color3 LightGreen{144, 238, 144};
|
||||
static const Color3 PaleGreen{152, 251, 152};
|
||||
static const Color3 DarkSeaGreen{143, 188, 143};
|
||||
static const Color3 MediumSeaGreen{60, 179, 113};
|
||||
static const Color3 SeaGreen{46, 139, 87};
|
||||
static const Color3 DarkOliveGreen{85, 107, 47};
|
||||
static const Color3 OliveDrab{107, 142, 35};
|
||||
static const Color3 Lime{0, 255, 0};
|
||||
static const Color3 Olive{128, 128, 0};
|
||||
}
|
||||
namespace Cyans {
|
||||
static const Color3 LightCyan{224, 255, 255};
|
||||
static const Color3 Cyan{0, 255, 255};
|
||||
static const Color3 Aqua{0, 255, 255};
|
||||
static const Color3 Aquamarine{127, 255, 212};
|
||||
static const Color3 MediumAquamarine{102, 205, 170};
|
||||
static const Color3 PaleTurquoise{175, 238, 238};
|
||||
static const Color3 Turquoise{64, 224, 208};
|
||||
static const Color3 MediumTurquoise{72, 209, 204};
|
||||
static const Color3 DarkTurquoise{0, 206, 209};
|
||||
static const Color3 LightSeaGreen{32, 178, 170};
|
||||
static const Color3 CadetBlue{95, 158, 160};
|
||||
static const Color3 DarkCyan{0, 139, 139};
|
||||
static const Color3 Teal{0, 128, 128};
|
||||
}
|
||||
namespace Blues {
|
||||
static const Color3 PowderBlue{176, 224, 230};
|
||||
static const Color3 LightBlue{173, 216, 230};
|
||||
static const Color3 LightSkyBlue{135, 206, 250};
|
||||
static const Color3 SkyBlue{135, 206, 235};
|
||||
static const Color3 DeepSkyBlue{0, 191, 255};
|
||||
static const Color3 LightSteelBlue{176, 196, 222};
|
||||
static const Color3 DodgerBlue{30, 144, 255};
|
||||
static const Color3 CornflowerBlue{100, 149, 237};
|
||||
static const Color3 SteelBlue{70, 130, 180};
|
||||
static const Color3 RoyalBlue{65, 105, 225};
|
||||
static const Color3 MediumBlue{0, 0, 205};
|
||||
static const Color3 DarkBlue{0, 0, 139};
|
||||
static const Color3 Navy{0, 0, 128};
|
||||
static const Color3 MidnightBlue{25, 25, 112};
|
||||
static const Color3 MediumSlateBlue{123, 104, 238};
|
||||
static const Color3 SlateBlue{106, 90, 205};
|
||||
static const Color3 DarkSlateBlue{72, 61, 139};
|
||||
}
|
||||
|
||||
|
||||
namespace Purples {
|
||||
static const Color3 Lavender{230, 230, 250};
|
||||
static const Color3 Thistle{216, 191, 216};
|
||||
static const Color3 Plum{221, 160, 221};
|
||||
static const Color3 Violet{238, 160, 221};
|
||||
static const Color3 Orchid{218, 112, 214};
|
||||
static const Color3 Fuchsia{255, 0, 255};
|
||||
static const Color3 Magenta{255, 0, 255};
|
||||
static const Color3 MediumOrchid{186, 85, 211};
|
||||
static const Color3 MediumPurple{147, 112, 219};
|
||||
static const Color3 BlueViolet{138, 43, 226};
|
||||
static const Color3 DarkViolet{148, 0, 211};
|
||||
static const Color3 DarkOrchid{153, 50, 204};
|
||||
static const Color3 DarkMagenta{139, 0, 128};
|
||||
static const Color3 Purple{128, 0, 128};
|
||||
static const Color3 Indigo{75, 0, 130};
|
||||
}
|
||||
namespace Pinks {
|
||||
static const Color3 Pink{255, 129, 203};
|
||||
static const Color3 LightPink{255, 182, 193};
|
||||
static const Color3 HotPink{255, 105, 180};
|
||||
static const Color3 DeepPink{255, 20, 147};
|
||||
static const Color3 PaleVioletRed{219, 112, 147};
|
||||
static const Color3 MediumVioletRed{199, 21, 133};
|
||||
}
|
||||
namespace Whites {
|
||||
static const Color3 Snow{255, 250, 250};
|
||||
static const Color3 Honeydew{240, 255, 240};
|
||||
static const Color3 MintCream{245, 255, 250};
|
||||
static const Color3 Azure{240, 255, 255};
|
||||
static const Color3 AliceBlue{240, 248, 255};
|
||||
static const Color3 GhostWhite{248, 248, 255};
|
||||
static const Color3 WhiteSmoke{245, 245, 245};
|
||||
static const Color3 SeaShell{255, 245, 238};
|
||||
static const Color3 Beige{245, 245, 220};
|
||||
static const Color3 OldLace{253, 245, 230};
|
||||
static const Color3 FloralWhite{255, 250, 240};
|
||||
static const Color3 Ivory{255, 255, 240};
|
||||
static const Color3 AntiqueWhite{250, 240, 215};
|
||||
static const Color3 Linen{250, 240, 230};
|
||||
static const Color3 LavenderBlush{255, 240, 245};
|
||||
static const Color3 MistyRose{255, 228, 255};
|
||||
}
|
||||
namespace Grays {
|
||||
static const Color3 Gainsboro{220, 220, 220};
|
||||
static const Color3 LightGray{211, 211, 211};
|
||||
static const Color3 Silver{192, 192, 192};
|
||||
static const Color3 DimGray{105, 105, 105};
|
||||
static const Color3 LightSlateGray{119, 136, 153};
|
||||
static const Color3 SlateGray{112, 128, 144};
|
||||
static const Color3 DarkSlateGray{47, 79, 79};
|
||||
}
|
||||
namespace Browns {
|
||||
static const Color3 CornSilk{255, 248, 220};
|
||||
static const Color3 BlanchedAlmond{255, 235, 205};
|
||||
static const Color3 Bisque{255, 228, 196};
|
||||
static const Color3 NavajoWhite{255, 222, 173};
|
||||
static const Color3 Wheat{254, 222, 179};
|
||||
static const Color3 BurlyWood{222, 184, 135};
|
||||
static const Color3 Tan{210, 180, 140};
|
||||
static const Color3 RosyBrown{188, 143, 143};
|
||||
static const Color3 SandyBrown{244, 164, 96};
|
||||
static const Color3 GoldenRod{218, 165, 32};
|
||||
static const Color3 Peru{205, 133, 63};
|
||||
static const Color3 Chocolate{210, 105, 30};
|
||||
static const Color3 SaddleBrown{139, 69, 19};
|
||||
static const Color3 Sienna{160, 82, 45};
|
||||
static const Color3 Brown{164, 42, 42};
|
||||
static const Color3 Maroon{128, 0, 0};
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,210 +8,16 @@
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <JGL/Color3.h>
|
||||
#include <J3ML/Geometry/Sphere.h>
|
||||
#include <J3ML/Geometry/OBB.h>
|
||||
#include <J3ML/Geometry/Capsule.h>
|
||||
#include <J3ML/Geometry/Plane.h>
|
||||
#include <J3ML/Geometry/TriangleMesh.h>
|
||||
|
||||
// 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]
|
||||
struct RGBTuple {
|
||||
int r; int g; int b;
|
||||
};
|
||||
struct RGBATuple {
|
||||
int r; int g; int b; int a;
|
||||
};
|
||||
struct HSVTuple {
|
||||
int h; int s; int v;
|
||||
};
|
||||
struct HSLTuple {
|
||||
int h; int s; int l;
|
||||
};
|
||||
|
||||
struct Color3 {
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
|
||||
Color3 Lerp(const Color3& rhs, float alpha) const;
|
||||
|
||||
};
|
||||
struct Color4{
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
int a;
|
||||
};
|
||||
namespace Colors {
|
||||
namespace Primary {
|
||||
static const Color3 Red {255, 0, 0};
|
||||
static const Color3 Green { 0, 255, 0};
|
||||
static const Color3 Blue { 0, 0, 255};
|
||||
static const Color3 White {255, 255, 255};
|
||||
static const Color3 Black { 0, 0, 0};
|
||||
static const Color3 Gray {128, 128, 128};
|
||||
static const Color3 DarkGray {192, 192, 192};
|
||||
static const Color3 LightGray { 64, 64, 64};
|
||||
static const Color3 Yellow {255, 255, 0};
|
||||
}
|
||||
using namespace Primary;
|
||||
namespace Reds {
|
||||
static const Color3 Fuchsia {};
|
||||
static const Color3 LightSalmon {255, 160, 122};
|
||||
static const Color3 Salmon {250, 128, 114};
|
||||
static const Color3 DarkSalmon {233, 150, 122};
|
||||
static const Color3 LightCoral {240, 128, 128};
|
||||
static const Color3 IndianRed {205, 92, 92};
|
||||
static const Color3 Crimson {220, 20, 60};
|
||||
static const Color3 Firebrick {178, 34, 34};
|
||||
static const Color3 DarkRed {139, 0, 0};
|
||||
}
|
||||
namespace Oranges {
|
||||
static const Color3 Coral {255, 127, 80};
|
||||
static const Color3 Tomato {255, 99, 71};
|
||||
static const Color3 OrangeRed {255, 69, 0};
|
||||
static const Color3 Gold {255, 215, 0};
|
||||
static const Color3 Orange {255, 165, 0};
|
||||
static const Color3 DarkOrange {255, 140, 0};
|
||||
}
|
||||
namespace Yellows {
|
||||
static const Color3 LightYellow {255, 255, 224};
|
||||
static const Color3 LemonChiffon {255, 250 ,205};
|
||||
static const Color3 LightGoldenrodYellow {250, 250, 210};
|
||||
static const Color3 PapayaWhip {255, 239, 213};
|
||||
static const Color3 Moccasin {255, 228, 181};
|
||||
static const Color3 PeachPuff {255, 218, 185};
|
||||
static const Color3 PaleGoldenrod {238, 232, 170};
|
||||
static const Color3 Khaki {240, 230, 140};
|
||||
static const Color3 DarkKhaki {189, 183, 107};
|
||||
}
|
||||
namespace Greens {
|
||||
static const Color3 LawnGreen {124, 252, 0};
|
||||
static const Color3 Chartreuse {127, 255, 0};
|
||||
static const Color3 LimeGreen {50, 205, 50};
|
||||
static const Color3 ForestGreen {34, 139, 34};
|
||||
static const Color3 DarkGreen {0, 100, 0};
|
||||
static const Color3 GreenYellow{173, 255, 47};
|
||||
static const Color3 YellowGreen{154, 205, 50};
|
||||
static const Color3 SpringGreen{0, 255, 127};
|
||||
static const Color3 MediumSpringGreen{0, 250, 154};
|
||||
static const Color3 LightGreen{144, 238, 144};
|
||||
static const Color3 PaleGreen{152, 251, 152};
|
||||
static const Color3 DarkSeaGreen{143, 188, 143};
|
||||
static const Color3 MediumSeaGreen{60, 179, 113};
|
||||
static const Color3 SeaGreen{46, 139, 87};
|
||||
static const Color3 DarkOliveGreen{85, 107, 47};
|
||||
static const Color3 OliveDrab{107, 142, 35};
|
||||
static const Color3 Lime{0, 255, 0};
|
||||
static const Color3 Olive{128, 128, 0};
|
||||
}
|
||||
namespace Cyans {
|
||||
static const Color3 LightCyan{224, 255, 255};
|
||||
static const Color3 Cyan{0, 255, 255};
|
||||
static const Color3 Aqua{0, 255, 255};
|
||||
static const Color3 Aquamarine{127, 255, 212};
|
||||
static const Color3 MediumAquamarine{102, 205, 170};
|
||||
static const Color3 PaleTurquoise{175, 238, 238};
|
||||
static const Color3 Turquoise{64, 224, 208};
|
||||
static const Color3 MediumTurquoise{72, 209, 204};
|
||||
static const Color3 DarkTurquoise{0, 206, 209};
|
||||
static const Color3 LightSeaGreen{32, 178, 170};
|
||||
static const Color3 CadetBlue{95, 158, 160};
|
||||
static const Color3 DarkCyan{0, 139, 139};
|
||||
static const Color3 Teal{0, 128, 128};
|
||||
}
|
||||
namespace Blues {
|
||||
static const Color3 PowderBlue {176, 224, 230};
|
||||
static const Color3 LightBlue {173, 216, 230};
|
||||
static const Color3 LightSkyBlue {135, 206, 250};
|
||||
static const Color3 SkyBlue {135, 206, 235};
|
||||
static const Color3 DeepSkyBlue {0, 191, 255};
|
||||
static const Color3 LightSteelBlue {176, 196, 222};
|
||||
static const Color3 DodgerBlue {30, 144, 255};
|
||||
static const Color3 CornflowerBlue {100, 149, 237};
|
||||
static const Color3 SteelBlue {70, 130, 180};
|
||||
static const Color3 RoyalBlue {65, 105, 225};
|
||||
static const Color3 MediumBlue {0, 0, 205};
|
||||
static const Color3 DarkBlue {0, 0, 139};
|
||||
static const Color3 Navy {0, 0, 128};
|
||||
static const Color3 MidnightBlue {25, 25, 112};
|
||||
static const Color3 MediumSlateBlue {123, 104, 238};
|
||||
static const Color3 SlateBlue {106, 90, 205};
|
||||
static const Color3 DarkSlateBlue {72, 61, 139};
|
||||
}
|
||||
|
||||
|
||||
namespace Purples {
|
||||
static const Color3 Lavender {230, 230, 250};
|
||||
static const Color3 Thistle {216, 191, 216};
|
||||
static const Color3 Plum {221, 160, 221};
|
||||
static const Color3 Violet {238, 160, 221};
|
||||
static const Color3 Orchid {218, 112, 214};
|
||||
static const Color3 Fuchsia {255, 0, 255};
|
||||
static const Color3 Magenta {255, 0, 255};
|
||||
static const Color3 MediumOrchid {186, 85, 211};
|
||||
static const Color3 MediumPurple {147, 112, 219};
|
||||
static const Color3 BlueViolet {138, 43, 226};
|
||||
static const Color3 DarkViolet {148, 0, 211};
|
||||
static const Color3 DarkOrchid {153, 50, 204};
|
||||
static const Color3 DarkMagenta {139, 0, 128};
|
||||
static const Color3 Purple {128, 0, 128};
|
||||
static const Color3 Indigo {75, 0, 130};
|
||||
}
|
||||
namespace Pinks {
|
||||
static const Color3 Pink {255, 129, 203};
|
||||
static const Color3 LightPink {255, 182, 193};
|
||||
static const Color3 HotPink {255, 105, 180};
|
||||
static const Color3 DeepPink {255, 20, 147};
|
||||
static const Color3 PaleVioletRed {219, 112, 147};
|
||||
static const Color3 MediumVioletRed {199, 21, 133};
|
||||
}
|
||||
namespace Whites {
|
||||
static const Color3 Snow {255, 250, 250};
|
||||
static const Color3 Honeydew {240, 255, 240};
|
||||
static const Color3 MintCream {245, 255, 250};
|
||||
static const Color3 Azure {240, 255, 255};
|
||||
static const Color3 AliceBlue {240, 248, 255};
|
||||
static const Color3 GhostWhite {248, 248, 255};
|
||||
static const Color3 WhiteSmoke {245, 245, 245};
|
||||
static const Color3 SeaShell {255, 245, 238};
|
||||
static const Color3 Beige {245, 245, 220};
|
||||
static const Color3 OldLace {253, 245, 230};
|
||||
static const Color3 FloralWhite {255, 250, 240};
|
||||
static const Color3 Ivory {255, 255, 240};
|
||||
static const Color3 AntiqueWhite {250, 240, 215};
|
||||
static const Color3 Linen {250, 240, 230};
|
||||
static const Color3 LavenderBlush {255, 240, 245};
|
||||
static const Color3 MistyRose {255, 228, 255};
|
||||
}
|
||||
namespace Grays {
|
||||
static const Color3 Gainsboro {220, 220, 220};
|
||||
static const Color3 LightGray {211, 211, 211};
|
||||
static const Color3 Silver {192, 192, 192};
|
||||
static const Color3 DimGray {105, 105, 105};
|
||||
static const Color3 LightSlateGray {119, 136, 153};
|
||||
static const Color3 SlateGray {112, 128, 144};
|
||||
static const Color3 DarkSlateGray {47, 79, 79};
|
||||
}
|
||||
namespace Browns {
|
||||
static const Color3 CornSilk {255, 248, 220};
|
||||
static const Color3 BlanchedAlmond {255, 235, 205};
|
||||
static const Color3 Bisque {255, 228, 196};
|
||||
static const Color3 NavajoWhite {255, 222, 173};
|
||||
static const Color3 Wheat {254, 222, 179};
|
||||
static const Color3 BurlyWood {222, 184, 135};
|
||||
static const Color3 Tan {210, 180, 140};
|
||||
static const Color3 RosyBrown {188, 143, 143};
|
||||
static const Color3 SandyBrown {244, 164, 96};
|
||||
static const Color3 GoldenRod {218, 165, 32};
|
||||
static const Color3 Peru {205, 133, 63};
|
||||
static const Color3 Chocolate {210, 105, 30};
|
||||
static const Color3 SaddleBrown {139, 69, 19};
|
||||
static const Color3 Sienna {160, 82, 45};
|
||||
static const Color3 Brown {164, 42, 42};
|
||||
static const Color3 Maroon {128, 0, 0};
|
||||
}
|
||||
}
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
using J3ML::LinearAlgebra::Matrix3x3;
|
||||
@@ -219,6 +25,12 @@ namespace JGL {
|
||||
using J3ML::LinearAlgebra::AxisAngle;
|
||||
using J3ML::LinearAlgebra::Quaternion;
|
||||
|
||||
using J3ML::Geometry::Sphere;
|
||||
using J3ML::Geometry::OBB;
|
||||
using J3ML::Geometry::Capsule;
|
||||
using J3ML::Geometry::TriangleMesh;
|
||||
using J3ML::Geometry::Plane;
|
||||
|
||||
struct HSV {
|
||||
float hue;
|
||||
float saturation;
|
||||
@@ -229,7 +41,7 @@ namespace JGL {
|
||||
{
|
||||
Vector2 A;
|
||||
Vector2 B;
|
||||
Vector3 C;
|
||||
Vector2 C;
|
||||
};
|
||||
|
||||
struct Triangle3D
|
||||
@@ -239,34 +51,27 @@ namespace JGL {
|
||||
Vector3 C;
|
||||
};
|
||||
|
||||
Vector2 ScreenToViewport(const Vector2& v);
|
||||
Vector2 ViewportToScreen(const Vector2& v)
|
||||
{
|
||||
// TODO: Implement (CORRECT!!!) matrix transformation
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool InitTextEngine();
|
||||
|
||||
// TODO: implement correct coloring
|
||||
void RenderText(std::string text, float x, float y, float scale);
|
||||
using J3ML::u32;
|
||||
|
||||
namespace J2D {
|
||||
void DrawPixel2D(const Color3& color, const Vector2 &coordinates);
|
||||
void DrawPixel2D(const Color3& color, float x, float y);
|
||||
void DrawLine2D(const Color3& color, const Vector2 &A, const Vector2 &B, float thickness = 1);
|
||||
void DrawLine2D(const Color3& color, float x, float y, float w, float h, float thickness = 1);
|
||||
void DrawPixel2D(const Color3 &color, const Vector2 &coordinates);
|
||||
void DrawPixel2D(const Color3 &color, float x, float y);
|
||||
void DrawLine2D(const Color3 &color, const Vector2 &A, const Vector2 &B, float thickness = 1);
|
||||
void DrawLine2D(const Color3 &color, float x, float y, float w, float h, float thickness = 1);
|
||||
void DrawCubicBezierCurve2D();
|
||||
void OutlineCircle2D(const Color3& color, const Vector2& center, float radius, int subdivisions, float thickness = 1);
|
||||
void FillCircle2D(const Color3& color, const Vector2& center, float radius, int subdivisions);
|
||||
void OutlineTriangle2D();
|
||||
void FillTriangle2D();
|
||||
void OutlineCircle2D(const Color3 &color, const Vector2 ¢er, float radius, int subdivisions,
|
||||
float thickness = 1);
|
||||
void FillCircle2D(const Color3 &color, const Vector2 ¢er, float radius, int subdivisions);
|
||||
void OutlineTriangle2D(const Color3 &color, const Triangle2D &tri);
|
||||
void FillTriangle2D(const Color3 &color, const Triangle2D &tri);
|
||||
void FillTexturedTriangle2D();
|
||||
void FillTexturedPolygon2D();
|
||||
void DrawSprite2D();
|
||||
void DrawPartialSprite2D();
|
||||
void DrawString2D();
|
||||
void DrawString2D(const Color3& color, std::string text, float x, float y, float scale, u32 size = 16);
|
||||
void FillRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size);
|
||||
void OutlineRect2D ( const Color3& color, const Vector2& pos, const Vector2& size, float thickness = 1);
|
||||
void FillRoundedRect2D (const Color3& color, const Vector2& pos, const Vector2& size, float radius);
|
||||
@@ -277,9 +82,15 @@ namespace JGL {
|
||||
}
|
||||
namespace J3D {
|
||||
void DrawLine3D(const Color3& color, const Vector3 &A, const Vector3 &B, float thickness = 1);
|
||||
void FillSphere3D();
|
||||
void WireframeSphere3D();
|
||||
void DrawString3D();
|
||||
void FillSphere3D(const Color3& color, const Sphere& sphere);
|
||||
void WireframeSphere3D(const Color3& color, const Sphere& sphere, float thickness = 1);
|
||||
void FillOBB3D(const Color3& color, const OBB& obb);
|
||||
void WireframeOBB3D(const Color3& color, const OBB& obb, float thickness = 1);
|
||||
void FillCapsule3D(const Color3& color, const Capsule& capsule);
|
||||
void WireframeCapsule3D(const Color3& color, const Capsule& cap, float thickness = 1);
|
||||
void FillTriangleMesh3D(const Color3& color, const TriangleMesh& mesh);
|
||||
void WireframeTriangleMesh3D(const Color3& color, const TriangleMesh& mesh, float thickness = 1);
|
||||
void DrawString3D(const Color3& color, const std::string& text, const Vector3& pos, float scale, u32 size = 12);
|
||||
|
||||
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
|
||||
void DrawMatrixGizmo (const Matrix4x4&);
|
||||
|
149
include/LearnOpenGL/Mesh.h
Normal file
149
include/LearnOpenGL/Mesh.h
Normal file
@@ -0,0 +1,149 @@
|
||||
/// @file Mesh.h
|
||||
/// @description
|
||||
/// @author LearnOpenGL - Updated Josh O'Leary
|
||||
/// @lastedit 2024-02-22
|
||||
|
||||
// Original Source:
|
||||
// https://learnopengl.com/code_viewer_gh.php?code=includes/learnopengl/mesh.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GL/glew.h>
|
||||
#include <GL/glext.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <string>
|
||||
#include "Shader.h"
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
using J3ML::u32;
|
||||
|
||||
constexpr int MAX_BONE_INFLUENCE = 4;
|
||||
|
||||
namespace LearnOpenGL
|
||||
{
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
Vector3 Position;
|
||||
Vector3 Normal;
|
||||
Vector2 TexCoords;
|
||||
Vector3 Tangent;
|
||||
Vector3 BiTangent;
|
||||
int BoneIDs[MAX_BONE_INFLUENCE];
|
||||
float BoneWeights[MAX_BONE_INFLUENCE];
|
||||
};
|
||||
|
||||
// Different from Texture2D in purpose
|
||||
struct Texture {
|
||||
unsigned int id;
|
||||
std::string type;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
class Mesh {
|
||||
public:
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<uint> indices;
|
||||
std::vector<Texture> textures;
|
||||
uint VAO;
|
||||
|
||||
Mesh(std::vector<Vertex> verts, std::vector<uint> indices, std::vector<Texture> textures)
|
||||
{
|
||||
this->vertices = verts;
|
||||
this->indices = indices;
|
||||
this->textures = textures;
|
||||
|
||||
setupMesh();
|
||||
}
|
||||
|
||||
void Draw(Shader &shader)
|
||||
{
|
||||
uint diffuse = 1;
|
||||
uint specular = 1;
|
||||
uint normal = 1;
|
||||
uint height = 1;
|
||||
for (uint i = 0; i < textures.size(); i++)
|
||||
{
|
||||
// activate proper texture unit before binding
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
// retrieve texture number (the N in diffuse_textureN)
|
||||
std::string number;
|
||||
std::string name = textures[i].type;
|
||||
if (name == "texture_diffuse")
|
||||
number = std::to_string(diffuse++);
|
||||
else if (name == "texture_specular")
|
||||
number = std::to_string(specular++);
|
||||
else if (name == "texture_normal")
|
||||
number = std::to_string(normal++);
|
||||
else if (name == "texture_height")
|
||||
number = std::to_string(height++);
|
||||
|
||||
// now set the sampler to the correct texture unit
|
||||
glUniform1i(glGetUniformLocation(shader.ID, (name + number).c_str()), i);
|
||||
// and finally bind the texture
|
||||
glBindTexture(GL_TEXTURE_2D, textures[i].id);
|
||||
}
|
||||
|
||||
// draw mesh
|
||||
glBindVertexArray(VAO);
|
||||
glDrawElements(GL_TRIANGLES, static_cast<uint>(indices.size()), GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
// always good practice to set everything back to defaults once configured.
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
private:
|
||||
// render data
|
||||
unsigned int VBO, EBO;
|
||||
|
||||
// initializes all the buffer objects/arrays
|
||||
void setupMesh()
|
||||
{
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenBuffers(1, &EBO);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
// load data into vertex buffers
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
|
||||
// A great thing about structs is that their memory layout is sequential for all member items
|
||||
// The effect is that we can simply pass a pointer to the struct and it translates perfectly to a glm::vec3/vec2 array
|
||||
// which again translates to 3/2 floats which translates to a byte array
|
||||
// Except we use J3ML instead of glm, but the concept applies nonetheless
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), &vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(uint), &indices[0], GL_STATIC_DRAW);
|
||||
|
||||
// set the vertex attribute pointers
|
||||
// vertex positions
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
|
||||
// vertex normals
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, Normal));
|
||||
// vertex texture coords
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, TexCoords));
|
||||
// vertex tangent
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, Tangent));
|
||||
// vertex bitangent
|
||||
glEnableVertexAttribArray(4);
|
||||
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, BiTangent));
|
||||
// ids
|
||||
glEnableVertexAttribArray(5);
|
||||
glVertexAttribIPointer(5, 4, GL_INT, sizeof(Vertex), (void*)offsetof(Vertex, BoneIDs));
|
||||
|
||||
// weights
|
||||
glEnableVertexAttribArray(6);
|
||||
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, BoneWeights));
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
};
|
||||
}
|
23
include/LearnOpenGL/Texture2D.h
Normal file
23
include/LearnOpenGL/Texture2D.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
namespace {
|
||||
// Texture2D is able to store and configure a texture in OpenGL
|
||||
// It also hosts utility functions for easy management.
|
||||
class Texture2D {
|
||||
public:
|
||||
unsigned int ID; // ID of the texture object
|
||||
unsigned int Width, Height;
|
||||
unsigned int InternalFormat;
|
||||
unsigned int ImageFormat;
|
||||
unsigned int WrapS;
|
||||
unsigned int WrapT;
|
||||
unsigned int Filter_Min;
|
||||
unsigned int Filter_Max;
|
||||
|
||||
Texture2D();
|
||||
|
||||
void Generate(unsigned int width, unsigned int height, unsigned char *data);
|
||||
|
||||
void Bind() const;
|
||||
};
|
||||
}
|
48
main.cpp
48
main.cpp
@@ -4,7 +4,10 @@
|
||||
#include <rewindow/types/window.h>
|
||||
#include <iostream>
|
||||
#include <LearnOpenGL/Shader.h>
|
||||
#include <JGL/Colors.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
@@ -38,8 +41,6 @@ const std::string fragmentShader = "varying vec2 texpos;\n"
|
||||
|
||||
using J3ML::LinearAlgebra::Matrix4x4;
|
||||
|
||||
|
||||
|
||||
struct point {
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
@@ -52,7 +53,9 @@ class JGLDemoWindow : public ReWindow::RWindow
|
||||
public:
|
||||
LearnOpenGL::Shader shader;
|
||||
|
||||
JGLDemoWindow() : ReWindow::RWindow()
|
||||
JGLDemoWindow() : ReWindow::RWindow() {}
|
||||
JGLDemoWindow(const std::string& title, int width, int height) :
|
||||
ReWindow::RWindow(title, width, height)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -63,7 +66,7 @@ public:
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, 1024, 768, 0, -1, 1);
|
||||
glOrtho(0, getSize().x, getSize().y, 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
@@ -79,9 +82,33 @@ public:
|
||||
|
||||
void display()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
JGL::RenderText("WHATS BOPPIN muth ~~~ niger ~~~ aphuqqa____?", 0.f, -100.f, 3.f);
|
||||
JGL::RenderText("CHINESE CHARCTERS DONT WORK", 0.f, -100.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, getSize().x, getSize().y, 0, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
JGL::J2D::FillRect2D(JGL::Colors::Blue, {32, 32}, {100.5, 100.5});
|
||||
JGL::J2D::FillRect2D(JGL::Colors::Blue, {32, 32}, {100.5, 100.5});
|
||||
|
||||
JGL::Triangle2D tri
|
||||
{
|
||||
{140, 200},
|
||||
{135, 100},
|
||||
{105, 100}
|
||||
};
|
||||
JGL::J2D::FillTriangle2D(JGL::Colors::Yellow, tri);
|
||||
|
||||
|
||||
JGL::J3D::DrawString3D(JGL::Colors::White, "JGL Sample Text", {1, -120, 0.5f}, 2.f);
|
||||
JGL::J2D::DrawString2D(JGL::Colors::Green, "William J. Tomasine II ", 0.f, -120.f, 1.f);
|
||||
|
||||
JGL::J2D::DrawLine2D(JGL::Colors::Greens::DarkGreen, {10, 10}, {200, 300});
|
||||
JGL::J3D::DrawLine3D(JGL::Colors::Red, {0,0,0}, {1,0,0});
|
||||
JGL::J3D::DrawLine3D(JGL::Colors::Red, {0,0,0}, {1,0,0});
|
||||
|
||||
//glFlush();
|
||||
}
|
||||
|
||||
void OnRefresh(float elapsed) override
|
||||
@@ -91,16 +118,15 @@ public:
|
||||
}
|
||||
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
JGLDemoWindow* window = new JGLDemoWindow();
|
||||
|
||||
window->init(RenderingAPI::OPENGL, "Window", 1280, 720, false);
|
||||
auto* window = new JGLDemoWindow("JGL Demo Window", 1280, 720);
|
||||
window->setRenderer(RenderingAPI::OPENGL);
|
||||
window->Open();
|
||||
window->initGL();
|
||||
window->setResizable(true);
|
||||
while (window->isAlive())
|
||||
|
248
src/JGL/JGL.cpp
248
src/JGL/JGL.cpp
@@ -4,11 +4,10 @@
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <JGL/JGL.h>
|
||||
#include <GL/glut.h>
|
||||
#include "J3ML/LinearAlgebra/Transform2D.h"
|
||||
#include <rewindow/types/window.h>
|
||||
#include <J3ML/LinearAlgebra/Transform2D.h>
|
||||
#include <freetype2/ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include <JGL/Color3.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -17,27 +16,6 @@ GLuint texture;
|
||||
|
||||
namespace JGL
|
||||
{
|
||||
Vector2 ScreenToViewport(const Vector2 &v) {
|
||||
// TODO: Implement (CORRECT!!!) matrix transformation
|
||||
|
||||
Vector2 windowSize = ReWindow::RWindow::CurrentWindow()->getSize();
|
||||
|
||||
//Transform2D transform;
|
||||
|
||||
//transform = transform.Translate(1.f, 1.f); // Center
|
||||
//transform = transform.Scale(0.5f, 0.5f); // Scale by half
|
||||
//transform = transform.Scale(viewportWidth, viewportHeight); // Scale by screen size
|
||||
|
||||
//return transform.Transform(v);
|
||||
|
||||
float x = (v.x) / windowSize.x;
|
||||
float y = (v.y) / windowSize.y;
|
||||
|
||||
return {
|
||||
x, y
|
||||
};
|
||||
}
|
||||
|
||||
FT_Face face;
|
||||
FT_Library ft;
|
||||
|
||||
@@ -56,70 +34,15 @@ namespace JGL
|
||||
std::cout << "Error::FREETYPE: Failed to load font!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
FT_Set_Pixel_Sizes(face, 0, default_font_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderText(std::string text, float x, float y, float scale) {
|
||||
glUseProgram(0); // Fixed-function pipeline.
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
|
||||
const char* c;
|
||||
for (c = text.c_str(); *c; c++)
|
||||
{
|
||||
if (FT_Load_Char(face, *c, FT_LOAD_RENDER))
|
||||
continue;
|
||||
|
||||
FT_GlyphSlot g = face->glyph;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, g->bitmap.width, g->bitmap.rows, 0, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap.buffer);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
float x2 = x + g->bitmap_left * scale;
|
||||
float y2 = -y - g->bitmap_top * scale; // Adjust y-coordinate
|
||||
float w = g->bitmap.width * scale;
|
||||
float h = g->bitmap.rows * scale;
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2f(x2, y2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2f(x2, y2 + h);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2f(x2 + w, y2 + h);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2f(x2, y2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2f(x2 + w, y2 + h);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2f(x2 + w, y2);
|
||||
|
||||
glEnd();
|
||||
|
||||
x += (g->advance.x >> 6) * scale;
|
||||
y += (g->advance.y >> 6) * scale;
|
||||
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
||||
}
|
||||
|
||||
namespace J2D
|
||||
{
|
||||
void FillRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size) {
|
||||
auto vp_pos = ScreenToViewport(pos);
|
||||
auto vp_size = ScreenToViewport(size);
|
||||
auto vp_pos = pos;
|
||||
auto vp_size = size;
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
||||
glVertex2f(vp_pos.x, vp_pos.y);
|
||||
@@ -130,8 +53,8 @@ namespace JGL
|
||||
}
|
||||
|
||||
void OutlineRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size, float thickness) {
|
||||
auto vp_pos = ScreenToViewport(pos);
|
||||
auto vp_size = ScreenToViewport(size);
|
||||
auto vp_pos = pos;
|
||||
auto vp_size = size;
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glLineWidth(thickness);
|
||||
glColor3f(color.r, color.g, color.b);
|
||||
@@ -143,10 +66,10 @@ namespace JGL
|
||||
}
|
||||
|
||||
void DrawLine2D(const Color3 &color, const Vector2 &A, const Vector2 &B, float thickness) {
|
||||
auto vp_a = ScreenToViewport(A);
|
||||
auto vp_b = ScreenToViewport(B);
|
||||
auto vp_a = A;
|
||||
auto vp_b = B;
|
||||
|
||||
glBegin(GL_LINE);
|
||||
glBegin(GL_LINES);
|
||||
glLineWidth(thickness);
|
||||
glColor3f(color.r, color.g, color.b);
|
||||
glVertex2f(vp_a.x, vp_a.y);
|
||||
@@ -164,7 +87,7 @@ namespace JGL
|
||||
}
|
||||
|
||||
void DrawPixel2D(const Color3 &color, const Vector2 &coordinates) {
|
||||
auto vp_pos = ScreenToViewport(coordinates);
|
||||
auto vp_pos = coordinates;
|
||||
glBegin(GL_POINT);
|
||||
glColor3f(color.r, color.g, color.b);
|
||||
glVertex2f(vp_pos.x, vp_pos.y);
|
||||
@@ -203,6 +126,85 @@ namespace JGL
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void OutlineTriangle2D(const Color3& color, const Triangle2D& tri)
|
||||
{
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
||||
glVertex2f(tri.A.x, tri.A.y);
|
||||
glVertex2f(tri.B.x, tri.B.y);
|
||||
glVertex2f(tri.C.x, tri.C.y);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void FillTriangle2D(const Color3& color, const Triangle2D& tri)
|
||||
{
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
||||
glVertex2f(tri.A.x, tri.A.y);
|
||||
glVertex2f(tri.B.x, tri.B.y);
|
||||
glVertex2f(tri.C.x, tri.C.y);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void DrawString2D(const Color3& color, std::string text, float x, float y, float scale, u32 size) {
|
||||
glUseProgram(0); // Fixed-function pipeline.
|
||||
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
||||
|
||||
FT_Set_Pixel_Sizes(face, 0, size);
|
||||
|
||||
const char* c;
|
||||
for (c = text.c_str(); *c; c++)
|
||||
{
|
||||
if (FT_Load_Char(face, *c, FT_LOAD_RENDER))
|
||||
continue;
|
||||
|
||||
FT_GlyphSlot g = face->glyph;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, g->bitmap.width, g->bitmap.rows, 0, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap.buffer);
|
||||
|
||||
float x2 = x + g->bitmap_left * scale;
|
||||
float y2 = -y - g->bitmap_top * scale; // Adjust y-coordinate
|
||||
float w = g->bitmap.width * scale;
|
||||
float h = g->bitmap.rows * scale;
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2f(x2, y2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2f(x2, y2 + h);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2f(x2 + w, y2 + h);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2f(x2, y2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2f(x2 + w, y2 + h);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2f(x2 + w, y2);
|
||||
|
||||
glEnd();
|
||||
|
||||
x += (g->advance.x >> 6) * scale;
|
||||
y += (g->advance.y >> 6) * scale;
|
||||
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -210,12 +212,78 @@ namespace JGL
|
||||
{
|
||||
void DrawLine3D(const Color3& color, const Vector3& A, const Vector3& B, float thickness)
|
||||
{
|
||||
glBegin(GL_LINE);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glLineWidth(thickness);
|
||||
glColor3f(color.r, color.g, color.b);
|
||||
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
||||
glVertex3f(A.x, A.y, A.z);
|
||||
glVertex3f(B.x, B.y, B.z);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void DrawString3D(const Color3& color, const std::string& text, const Vector3& pos, float scale, u32 size)
|
||||
{
|
||||
float x = pos.x;
|
||||
float y = pos.y;
|
||||
float z = pos.z;
|
||||
glUseProgram(0); // Fixed-function pipeline.
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
|
||||
FT_Set_Pixel_Sizes(face, 0, size);
|
||||
|
||||
const char* c;
|
||||
for (c = text.c_str(); *c; c++)
|
||||
{
|
||||
if (FT_Load_Char(face, *c, FT_LOAD_RENDER))
|
||||
continue;
|
||||
|
||||
FT_GlyphSlot g = face->glyph;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, g->bitmap.width, g->bitmap.rows, 0, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap.buffer);
|
||||
|
||||
float x2 = x + g->bitmap_left * scale;
|
||||
float y2 = -y - g->bitmap_top * scale; // Adjust y-coordinate
|
||||
float z2 = z;
|
||||
float w = g->bitmap.width * scale;
|
||||
float h = g->bitmap.rows * scale;
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x2, y2, z2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(x2, y2 + h, z2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x2 + w, y2 + h, z2);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x2, y2, z2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x2 + w, y2 + h, z2);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(x2 + w, y2, z2);
|
||||
|
||||
glEnd();
|
||||
|
||||
x += (g->advance.x >> 6) * scale;
|
||||
y += (g->advance.y >> 6) * scale;
|
||||
|
||||
}
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
||||
}
|
||||
|
||||
}
|
||||
}
|
29
src/LearnOpenGL/Texture2D.cpp
Normal file
29
src/LearnOpenGL/Texture2D.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <LearnOpenGL/Texture2D.h>
|
||||
#include <glad/glad.h>
|
||||
#include <GL/glut.h>
|
||||
|
||||
Texture2D::Texture2D()
|
||||
: Width(0), Height(0), InternalFormat(GL_RGB), ImageFormat(GL_RGB), WrapS(GL_REPEAT), WrapT(GL_REPEAT),
|
||||
Filter_Min(GL_LINEAR), Filter_Max(GL_LINEAR) {
|
||||
glGenTextures(1, &this->ID);
|
||||
}
|
||||
|
||||
void Texture2D::Generate(unsigned int width, unsigned int height, unsigned char *data) {
|
||||
this->Width = width;
|
||||
this->Height = height;
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, this->InternalFormat, width, height, 0, this->ImageFormat, GL_UNSIGNED_BYTE,
|
||||
data);
|
||||
// set Texture wrap and filter modes
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, this->WrapS);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, this->WrapT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, this->Filter_Min);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, this->Filter_Max);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void Texture2D::Bind() const
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
}
|
Reference in New Issue
Block a user