Compare commits
16 Commits
Prerelease
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
|
f5f590164a | ||
c45485cabd | |||
143703dea3 | |||
|
48493cb2fc | ||
5b7829b1f8 | |||
868f52464e | |||
d1d2493435 | |||
da30a7eedd | |||
5d906d6f99 | |||
6107e9a762 | |||
a38a83692f | |||
c4d6426587 | |||
817b0166c0 | |||
2a98857bab | |||
29a64160e9 | |||
f676ef5332 |
140
CMakeLists.txt
140
CMakeLists.txt
@@ -1,63 +1,77 @@
|
||||
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-20.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
|
||||
)
|
||||
|
||||
|
||||
CPMAddPackage(
|
||||
NAME LearnOpenGL
|
||||
URL https://git.redacted.cc/josh/LearnOpenGL/archive/Prerelease-2.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_include_directories(JGL PUBLIC ${LearnOpenGL_SOURCE_DIR}/include)
|
||||
target_link_libraries(JGL PUBLIC LearnOpenGL)
|
||||
|
||||
target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
||||
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&);
|
||||
|
@@ -1,58 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// LearnOpenGL::Shader
|
||||
// OpenGL Shader Class Wrapper
|
||||
// Updated by dawsh
|
||||
// https://learnopengl.com/code_viewer_gh.php?code=includes/learnopengl/shader.h
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <glad/glad.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <J3ML/LinearAlgebra/Vector4.h>
|
||||
#include <J3ML/LinearAlgebra/Matrix2x2.h>
|
||||
#include <J3ML/LinearAlgebra/Matrix3x3.h>
|
||||
#include <J3ML/LinearAlgebra/Matrix4x4.h>
|
||||
|
||||
namespace LearnOpenGL {
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
using J3ML::LinearAlgebra::Vector4;
|
||||
using J3ML::LinearAlgebra::Matrix2x2;
|
||||
using J3ML::LinearAlgebra::Matrix3x3;
|
||||
using J3ML::LinearAlgebra::Matrix4x4;
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
unsigned int ID{};
|
||||
|
||||
Shader();
|
||||
Shader(std::filesystem::path vertexProgramPath, std::filesystem::path fragmentProgramPath);
|
||||
Shader(std::string vertexProgramSrc, std::string fragmentProgramSrc);
|
||||
|
||||
void use();
|
||||
// Utility uniform functions
|
||||
void setBool(const std::string& name, bool value) const;
|
||||
void setInt(const std::string& name, int value) const;
|
||||
void setFloat(const std::string& name, float value) const;
|
||||
void setVec2(const std::string& name, const Vector2& value) const;
|
||||
void setVec2(const std::string& name, float x, float y) const;
|
||||
void setVec3(const std::string& name, const Vector3& value) const;
|
||||
void setVec3(const std::string& name, float x, float y, float z) const;
|
||||
void setVec4(const std::string& name, const Vector4& value) const;
|
||||
void setVec4(const std::string& name, float x, float y, float z, float w) const;
|
||||
void setMat2(const std::string& name, const Matrix2x2 &mat) const;
|
||||
void setMat3(const std::string& name, const Matrix3x3 &mat) const;
|
||||
void setMat4(const std::string& name, const Matrix4x4 &mat) const;
|
||||
|
||||
GLint getAttribute(const std::string& name) const;
|
||||
GLint getUniform(const std::string& name) const;
|
||||
|
||||
private:
|
||||
void checkCompileErrors(GLuint shader, std::string type);
|
||||
};
|
||||
}
|
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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,209 +0,0 @@
|
||||
#include <LearnOpenGL/Shader.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace LearnOpenGL
|
||||
{
|
||||
|
||||
Shader::Shader(std::filesystem::path vertexProgramPath, std::filesystem::path fragmentProgramPath) {
|
||||
std::string vertexCode;
|
||||
std::string fragmentCode;
|
||||
std::string geometryCode;
|
||||
std::ifstream vShaderFile;
|
||||
std::ifstream fShaderFile;
|
||||
std::ifstream gShaderFile;
|
||||
|
||||
vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
|
||||
try { // Open Files
|
||||
vShaderFile.open(vertexProgramPath);
|
||||
fShaderFile.open(fragmentProgramPath);
|
||||
std::stringstream vShaderStream, fShaderStream;
|
||||
// read file's buffer contents into streams
|
||||
vShaderStream << vShaderFile.rdbuf();
|
||||
fShaderStream << fShaderFile.rdbuf();
|
||||
// close file handlers
|
||||
vShaderFile.close();
|
||||
fShaderFile.close();
|
||||
// convert stream into string
|
||||
vertexCode = vShaderStream.str();
|
||||
fragmentCode = fShaderStream.str();
|
||||
if (false)
|
||||
{
|
||||
gShaderFile.open("");
|
||||
std::stringstream gShaderStream;
|
||||
gShaderStream << gShaderFile.rdbuf();
|
||||
gShaderFile.close();
|
||||
geometryCode = gShaderStream.str();
|
||||
}
|
||||
} catch (std::ifstream::failure& e) {
|
||||
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESSFULLY_READ: " << e.what() << std::endl;
|
||||
}
|
||||
const char* vShaderCode = vertexCode.c_str();
|
||||
const char* fShaderCode = fragmentCode.c_str();
|
||||
// 2. Compile shaders
|
||||
unsigned int vertex, fragment;
|
||||
// vertex shader
|
||||
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex, 1, &vShaderCode, NULL);
|
||||
glCompileShader(vertex);
|
||||
checkCompileErrors(vertex, "VERTEX");
|
||||
// fragment shader
|
||||
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||
glCompileShader(fragment);
|
||||
checkCompileErrors(fragment, "FRAGMENT");
|
||||
// if geometry shader is given, compile geometry shader
|
||||
unsigned int geometry;
|
||||
if (false)
|
||||
{
|
||||
//const char * gShaderCode = geometryCode.c_str();
|
||||
//geometry = glCreateShader(GL_GEOMETRY_SHADER);
|
||||
//glShaderSource(geometry, 1, &gShaderCode, NULL);
|
||||
//glCompileShader(geometry);
|
||||
//checkCompileErrors(geometry, "GEOMETRY");
|
||||
}
|
||||
// shader Program
|
||||
ID = glCreateProgram();
|
||||
glAttachShader(ID, vertex);
|
||||
glAttachShader(ID, fragment);
|
||||
if (false) // geometryPath != nullptr)
|
||||
glAttachShader(ID, geometry);
|
||||
glLinkProgram(ID);
|
||||
checkCompileErrors(ID, "PROGRAM");
|
||||
// delete the shaders as they're linked into our program now and are no longer necessary
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
if (false) //geometryPath != nullptr)
|
||||
glDeleteShader(geometry);
|
||||
}
|
||||
|
||||
Shader::Shader(std::string vertexProgramSrc, std::string fragmentProgramSrc) {
|
||||
|
||||
std::string geometryCode;
|
||||
|
||||
const char* vShaderCode = vertexProgramSrc.c_str();
|
||||
const char* fShaderCode = fragmentProgramSrc.c_str();
|
||||
// 2. Compile shaders
|
||||
unsigned int vertex, fragment;
|
||||
// vertex shader
|
||||
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex, 1, &vShaderCode, NULL);
|
||||
glCompileShader(vertex);
|
||||
checkCompileErrors(vertex, "VERTEX");
|
||||
// fragment shader
|
||||
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||
glCompileShader(fragment);
|
||||
checkCompileErrors(fragment, "FRAGMENT");
|
||||
// if geometry shader is given, compile geometry shader
|
||||
unsigned int geometry;
|
||||
if (false)
|
||||
{
|
||||
//const char * gShaderCode = geometryCode.c_str();
|
||||
//geometry = glCreateShader(GL_GEOMETRY_SHADER);
|
||||
//glShaderSource(geometry, 1, &gShaderCode, NULL);
|
||||
//glCompileShader(geometry);
|
||||
//checkCompileErrors(geometry, "GEOMETRY");
|
||||
}
|
||||
// shader Program
|
||||
ID = glCreateProgram();
|
||||
glAttachShader(ID, vertex);
|
||||
glAttachShader(ID, fragment);
|
||||
if (false) // geometryPath != nullptr)
|
||||
glAttachShader(ID, geometry);
|
||||
glLinkProgram(ID);
|
||||
checkCompileErrors(ID, "PROGRAM");
|
||||
// delete the shaders as they're linked into our program now and are no longer necessary
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
if (false) //geometryPath != nullptr)
|
||||
glDeleteShader(geometry);
|
||||
}
|
||||
|
||||
void Shader::use() {
|
||||
glUseProgram(ID);
|
||||
}
|
||||
|
||||
GLint Shader::getAttribute(const std::string& name) const
|
||||
{
|
||||
return glGetAttribLocation(ID, name.c_str());
|
||||
}
|
||||
|
||||
GLint Shader::getUniform(const std::string &name) const {
|
||||
return glGetUniformLocation(ID, name.c_str());
|
||||
}
|
||||
|
||||
void Shader::setBool(const std::string &name, bool value) const {
|
||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value);
|
||||
}
|
||||
|
||||
void Shader::setInt(const std::string &name, int value) const {
|
||||
glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
|
||||
void Shader::setFloat(const std::string &name, float value) const {
|
||||
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
|
||||
void Shader::setVec2(const std::string &name, const Vector2 &value) const {
|
||||
glUniform2f(glGetUniformLocation(ID, name.c_str()), value.x, value.y);
|
||||
}
|
||||
|
||||
void Shader::setVec2(const std::string &name, float x, float y) const {
|
||||
glUniform2f(glGetUniformLocation(ID, name.c_str()), x, y);
|
||||
}
|
||||
|
||||
void Shader::setVec3(const std::string &name, const Vector3 &value) const {
|
||||
glUniform3f(glGetUniformLocation(ID, name.c_str()), value.x, value.y, value.z);
|
||||
}
|
||||
|
||||
void Shader::setVec3(const std::string &name, float x, float y, float z) const {
|
||||
glUniform3f(glGetUniformLocation(ID, name.c_str()), x, y, z);
|
||||
}
|
||||
|
||||
void Shader::setVec4(const std::string &name, const Vector4 &value) const {
|
||||
glUniform4f(glGetUniformLocation(ID, name.c_str()), value.x, value.y, value.z, value.w);
|
||||
}
|
||||
|
||||
void Shader::setVec4(const std::string &name, float x, float y, float z, float w) const {
|
||||
glUniform4f(glGetUniformLocation(ID, name.c_str()), x, y, z, w);
|
||||
}
|
||||
|
||||
void Shader::setMat2(const std::string &name, const Matrix2x2 &mat) const {
|
||||
//glUniformMatrix2fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat.At(0, 0));
|
||||
}
|
||||
|
||||
void Shader::setMat3(const std::string &name, const Matrix3x3 &mat) const {
|
||||
//glUniformMatrix3fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat.At(0, 0));
|
||||
}
|
||||
|
||||
void Shader::setMat4(const std::string &name, const Matrix4x4 &mat) const {
|
||||
//glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat.At(0, 0));
|
||||
}
|
||||
|
||||
void Shader::checkCompileErrors(GLuint shader, std::string type) {
|
||||
GLint success;
|
||||
GLchar infoLog[1024];
|
||||
if (type != "PROGRAM") {
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << std::endl;
|
||||
}
|
||||
} else {
|
||||
glGetProgramiv(shader, GL_LINK_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
|
||||
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Shader::Shader() {}
|
||||
}
|
Reference in New Issue
Block a user