Implement J3D::DrawString3D
This commit is contained in:
@@ -26,7 +26,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.13.zip
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.14.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
@@ -42,9 +42,11 @@ add_library(JGL SHARED ${SOURCES}
|
||||
include/JGL/JGL.h
|
||||
src/JGL/JGL.cpp
|
||||
include/LearnOpenGL/Shader.h
|
||||
src/LearnOpenGL/Shader.cpp
|
||||
include/LearnOpenGL/Texture2D.h
|
||||
src/LearnOpenGL/Texture2D.cpp)
|
||||
include/JGL/Color3.h
|
||||
include/JGL/Colors.h
|
||||
include/JGL/Color4.h
|
||||
)
|
||||
set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
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,209 +8,12 @@
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <JGL/Color3.h>
|
||||
#include <J3ML/Geometry/Sphere.h>
|
||||
|
||||
// OpenGL Wrapper for rendering 2D graphics primitives in both a 2D and 3D context
|
||||
namespace JGL {
|
||||
|
||||
|
||||
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;
|
||||
@@ -218,6 +21,8 @@ namespace JGL {
|
||||
using J3ML::LinearAlgebra::AxisAngle;
|
||||
using J3ML::LinearAlgebra::Quaternion;
|
||||
|
||||
using J3ML::Geometry::Sphere;
|
||||
|
||||
struct HSV {
|
||||
float hue;
|
||||
float saturation;
|
||||
@@ -238,14 +43,6 @@ 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
|
||||
@@ -278,8 +75,11 @@ 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 WireframeSphere3D(const Sphere& sphere)
|
||||
{
|
||||
|
||||
}
|
||||
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&);
|
||||
|
10
main.cpp
10
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>
|
||||
@@ -91,11 +94,12 @@ public:
|
||||
JGL::J2D::FillTriangle2D(JGL::Colors::Yellow, tri);
|
||||
|
||||
|
||||
JGL::RenderText("JGL Sample Text", 0.f, -100.f, 1.f, 32);
|
||||
JGL::J3D::DrawString3D(JGL::Colors::White, "JGL Sample Text", {1, -120, 0.5f}, 2.f);
|
||||
JGL::RenderText("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::Reds::Firebrick, {10, 10, -1.f}, {200, 200, 10.f});
|
||||
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();
|
||||
}
|
||||
@@ -113,7 +117,7 @@ public:
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
JGLDemoWindow* window = new JGLDemoWindow();
|
||||
auto* window = new JGLDemoWindow();
|
||||
|
||||
window->init(RenderingAPI::OPENGL, "Window", 1280, 720, false);
|
||||
window->initGL();
|
||||
|
101
src/JGL/JGL.cpp
101
src/JGL/JGL.cpp
@@ -5,10 +5,11 @@
|
||||
#include <glad/glad.h>
|
||||
#include <JGL/JGL.h>
|
||||
#include <GL/glut.h>
|
||||
#include "J3ML/LinearAlgebra/Transform2D.h"
|
||||
#include <J3ML/LinearAlgebra/Transform2D.h>
|
||||
#include <rewindow/types/window.h>
|
||||
#include <freetype2/ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include "JGL/Color3.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -17,26 +18,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;
|
||||
@@ -122,8 +103,8 @@ namespace JGL
|
||||
namespace J2D
|
||||
{
|
||||
void FillRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size) {
|
||||
auto vp_pos = pos;//ScreenToViewport(pos);
|
||||
auto vp_size = 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);
|
||||
@@ -134,8 +115,8 @@ namespace JGL
|
||||
}
|
||||
|
||||
void OutlineRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size, float thickness) {
|
||||
auto vp_pos = pos;//ScreenToViewport(pos);
|
||||
auto vp_size = size;//ScreenToViewport(size);
|
||||
auto vp_pos = pos;
|
||||
auto vp_size = size;
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glLineWidth(thickness);
|
||||
glColor3f(color.r, color.g, color.b);
|
||||
@@ -147,8 +128,8 @@ namespace JGL
|
||||
}
|
||||
|
||||
void DrawLine2D(const Color3 &color, const Vector2 &A, const Vector2 &B, float thickness) {
|
||||
auto vp_a = A;//ScreenToViewport(A);
|
||||
auto vp_b = B;//ScreenToViewport(B);
|
||||
auto vp_a = A;
|
||||
auto vp_b = B;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glLineWidth(thickness);
|
||||
@@ -168,7 +149,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);
|
||||
@@ -233,5 +214,69 @@ namespace JGL
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user