Compare commits
16 Commits
Prerelease
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
608e9e29f5 | |||
c53fa52f6f | |||
7fa75cac54 | |||
|
d5f9eaa5a8 | ||
dead018993 | |||
|
e9a339182b | ||
|
076398b290 | ||
cf72d92c28 | |||
5d99f8ec1f | |||
a388ee8021 | |||
41916a4089 | |||
222dd346fb | |||
e6e567725b | |||
93612bb816 | |||
9ac22a8a87 | |||
1eaa9c6574 |
173
CMakeLists.txt
173
CMakeLists.txt
@@ -1,77 +1,96 @@
|
||||
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)
|
||||
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)
|
||||
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/Release-2.2.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-3.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME GLAD
|
||||
URL https://git.redacted.cc/Redacted/glad/archive/v2.1ext_mt.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME jlog
|
||||
URL https://git.redacted.cc/josh/jlog/Prerelease-9.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME Event
|
||||
URL https://git.redacted.cc/josh/Event/archive/Release-6.zip
|
||||
)
|
||||
if (WIN32)
|
||||
#CPMAddPackage(
|
||||
#NAME harfbuzz
|
||||
#URL https://github.com/harfbuzz/harfbuzz/archive/refs/tags/9.0.0.zip
|
||||
#)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME freetype
|
||||
URL https://github.com/freetype/freetype/archive/refs/tags/VER-2-13-2.zip
|
||||
)
|
||||
endif()
|
||||
|
||||
file(COPY "assets" DESTINATION "${PROJECT_BINARY_DIR}")
|
||||
file(GLOB_RECURSE ASSETS "assets/*")
|
||||
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" )
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
find_package(Freetype REQUIRED)
|
||||
add_library(JGL SHARED ${SOURCES})
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
add_library(JGL STATIC ${SOURCES})
|
||||
endif()
|
||||
|
||||
set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
target_include_directories(JGL PUBLIC
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${OPENGL_INCLUDE_DIRS}
|
||||
${J3ML_SOURCE_DIR}/include
|
||||
${Event_SOURCE_DIR}/include
|
||||
${ReWindow_SOURCE_DIR}/include
|
||||
${glad_SOURCE_DIR}/include
|
||||
${jlog_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
add_executable(JGL_Demo main.cpp)
|
||||
#set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
||||
target_link_libraries(JGL PRIVATE ${FREETYPE_LIBRARIES})
|
||||
target_link_libraries(JGL PUBLIC ${OPENGL_LIBRARIES} J3ML ReWindowLibrary glad jlog Event)
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
target_include_directories(JGL PRIVATE ${freetype_SOURCE_DIR}/include)
|
||||
target_link_libraries(JGL PRIVATE freetype)
|
||||
target_link_libraries(JGL PUBLIC ${OPENGL_LIBRARIES} J3ML ReWindowLibrary glad jlog Event)
|
||||
endif()
|
||||
|
||||
target_link_libraries(JGL_Demo PUBLIC JGL)
|
BIN
assets/fonts/Jupiteroid.ttf
Normal file
BIN
assets/fonts/Jupiteroid.ttf
Normal file
Binary file not shown.
@@ -3,18 +3,15 @@
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <JGL/Color3.h>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.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 {
|
||||
|
||||
@@ -52,9 +49,9 @@ namespace JGL {
|
||||
};
|
||||
|
||||
bool InitTextEngine();
|
||||
|
||||
int LoadFont(const std::string& font_path);
|
||||
void UnloadFont(int font_index);
|
||||
// TODO: implement correct coloring
|
||||
using J3ML::u32;
|
||||
|
||||
namespace J2D {
|
||||
void DrawPixel2D(const Color3 &color, const Vector2 &coordinates);
|
||||
@@ -71,7 +68,7 @@ namespace JGL {
|
||||
void FillTexturedPolygon2D();
|
||||
void DrawSprite2D();
|
||||
void DrawPartialSprite2D();
|
||||
void DrawString2D(const Color3& color, std::string text, float x, float y, float scale, u32 size = 16);
|
||||
void DrawString2D(const Color3& color, std::string text, float x, float y, float scale, u32 size, unsigned int font_index);
|
||||
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);
|
||||
@@ -90,7 +87,7 @@ namespace JGL {
|
||||
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 DrawString3D(const Color3& color, const std::string& text, const Vector3& pos, float scale, u32 size, unsigned int font_index);
|
||||
|
||||
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
|
||||
void DrawMatrixGizmo (const Matrix4x4&);
|
||||
|
43
main.cpp
43
main.cpp
@@ -1,18 +1,11 @@
|
||||
//#include <GL/glew.h>
|
||||
#include <glad/glad.h>
|
||||
#include <JGL/JGL.h>
|
||||
#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>
|
||||
#endif
|
||||
|
||||
struct Character
|
||||
{
|
||||
unsigned int TextureID; // ID handle of the glyph texture
|
||||
@@ -23,21 +16,6 @@ struct Character
|
||||
|
||||
std::map<char, Character> Characters;
|
||||
GLuint VAO, VBO;
|
||||
const std::string vertexShader = "attribute vec4 coord;\n"
|
||||
"varying vec2 texpos;\n"
|
||||
"\n"
|
||||
"void main(void) {\n"
|
||||
" gl_Position = vec4(coord.xy, 0, 1);\n"
|
||||
" texpos = coord.zw;\n"
|
||||
"}\n"
|
||||
"";
|
||||
const std::string fragmentShader = "varying vec2 texpos;\n"
|
||||
"uniform sampler2D tex;\n"
|
||||
"uniform vec4 color;\n"
|
||||
"\n"
|
||||
"void main(void) {\n"
|
||||
" gl_FragColor = vec4(1, 1, 1, texture2D(tex, texpos).a) * color;\n"
|
||||
"}";
|
||||
|
||||
using J3ML::LinearAlgebra::Matrix4x4;
|
||||
|
||||
@@ -48,10 +26,12 @@ struct point {
|
||||
GLfloat t;
|
||||
};
|
||||
|
||||
int FreeSans;
|
||||
int Jupiteroid;
|
||||
|
||||
class JGLDemoWindow : public ReWindow::RWindow
|
||||
{
|
||||
public:
|
||||
LearnOpenGL::Shader shader;
|
||||
|
||||
JGLDemoWindow() : ReWindow::RWindow() {}
|
||||
JGLDemoWindow(const std::string& title, int width, int height) :
|
||||
@@ -76,12 +56,13 @@ public:
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
JGL::InitTextEngine();
|
||||
JGL::InitTextEngine();
|
||||
FreeSans = JGL::LoadFont("assets/fonts/FreeSans.ttf");
|
||||
Jupiteroid = JGL::LoadFont("assets/fonts/Jupiteroid.ttf");
|
||||
}
|
||||
|
||||
|
||||
void display()
|
||||
{
|
||||
void display() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
@@ -99,15 +80,13 @@ public:
|
||||
{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});
|
||||
|
||||
JGL::J3D::DrawString3D(JGL::Colors::Red, "JGL Sample Text", {1, -32, 0.5f}, 1.f, 32, FreeSans);
|
||||
JGL::J2D::DrawString2D(JGL::Colors::Green, "Jupiteroid Font", 0.f, -48.f, 1.f, 16, Jupiteroid);
|
||||
|
||||
//glFlush();
|
||||
}
|
||||
|
||||
@@ -128,7 +107,7 @@ int main(int argc, char** argv)
|
||||
window->setRenderer(RenderingAPI::OPENGL);
|
||||
window->Open();
|
||||
window->initGL();
|
||||
window->setResizable(true);
|
||||
window->setResizable(false);
|
||||
while (window->isAlive())
|
||||
{
|
||||
window->pollEvents();
|
||||
|
@@ -2,40 +2,63 @@
|
||||
// Created by dawsh on 1/17/24.
|
||||
//
|
||||
|
||||
#include <vector>
|
||||
#include <glad/glad.h>
|
||||
#include <JGL/JGL.h>
|
||||
#include <J3ML/LinearAlgebra/Transform2D.h>
|
||||
#include <freetype2/ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include <JGL/Color3.h>
|
||||
#include <iostream>
|
||||
|
||||
#if __linux__
|
||||
#include <freetype2/ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#endif
|
||||
#if _WIN32
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#endif
|
||||
|
||||
GLuint program;
|
||||
GLuint texture;
|
||||
|
||||
namespace JGL
|
||||
{
|
||||
FT_Face face;
|
||||
FT_Library ft;
|
||||
|
||||
struct Font {
|
||||
int index = 0;
|
||||
FT_Face face;
|
||||
};
|
||||
|
||||
std::vector<Font> faces;
|
||||
|
||||
using namespace J3ML;
|
||||
|
||||
bool InitTextEngine() {
|
||||
constexpr u32 default_font_size = 16;
|
||||
if (FT_Init_FreeType(&ft))
|
||||
{
|
||||
std::cout << "Error::FREETYPE: " << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (FT_New_Face(ft, "content/FreeSans.ttf", 0, &face))
|
||||
{
|
||||
int LoadFont(const std::string &font_path) {
|
||||
if (ft == nullptr)
|
||||
return -1;
|
||||
Font font;
|
||||
if (FT_New_Face(ft, font_path.c_str(), 0, &font.face)) {
|
||||
std::cout << "Error::FREETYPE: Failed to load font!" << std::endl;
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return true;
|
||||
unsigned int newIndex = 0;
|
||||
for (const auto& f : faces)
|
||||
if (f.index >= newIndex)
|
||||
newIndex = f.index + 1;
|
||||
font.index = newIndex;
|
||||
faces.push_back(font);
|
||||
|
||||
std::cout << "Loaded font from " << font_path << " with index " << newIndex << std::endl;
|
||||
return newIndex;
|
||||
}
|
||||
|
||||
void UnloadFont(int font_index) {
|
||||
for (int i = 0; i < faces.size(); i++)
|
||||
if (faces[i].index == font_index)
|
||||
FT_Done_Face(faces[i].face),
|
||||
faces.erase(faces.begin() + i);
|
||||
}
|
||||
|
||||
namespace J2D
|
||||
@@ -147,23 +170,38 @@ namespace JGL
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void DrawString2D(const Color3& color, std::string text, float x, float y, float scale, u32 size) {
|
||||
void DrawString2D(const Color3& color, std::string text, float x, float y, float scale, u32 size, unsigned int font_index) {
|
||||
glUseProgram(0); // Fixed-function pipeline.
|
||||
|
||||
Font font{};
|
||||
for (const auto& f : faces)
|
||||
if (f.index == font_index)
|
||||
font = f;
|
||||
if (font.face == NULL) {
|
||||
std::cout << "null font" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
GLfloat currentColor[4];
|
||||
glGetFloatv(GL_CURRENT_COLOR, currentColor);
|
||||
|
||||
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
||||
|
||||
FT_Set_Pixel_Sizes(face, 0, size);
|
||||
FT_Set_Pixel_Sizes(font.face, 0, size);
|
||||
|
||||
const char* c;
|
||||
for (c = text.c_str(); *c; c++)
|
||||
std::vector<GLuint> textures(text.length());
|
||||
for (int i = 0; i < text.length(); i++)
|
||||
{
|
||||
if (FT_Load_Char(face, *c, FT_LOAD_RENDER))
|
||||
if (FT_Load_Char(font.face, text.c_str()[i], FT_LOAD_RENDER))
|
||||
continue;
|
||||
|
||||
FT_GlyphSlot g = face->glyph;
|
||||
|
||||
FT_GlyphSlot g = font.face->glyph;
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glGenTextures(1, &textures.at(i));
|
||||
glBindTexture(GL_TEXTURE_2D, textures[i]);
|
||||
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);
|
||||
@@ -201,9 +239,14 @@ namespace JGL
|
||||
|
||||
x += (g->advance.x >> 6) * scale;
|
||||
y += (g->advance.y >> 6) * scale;
|
||||
|
||||
}
|
||||
for (unsigned int& texture : textures)
|
||||
glDeleteTextures(1, &texture);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
||||
glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]); //Set draw color back to whatever it was before.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +255,6 @@ namespace JGL
|
||||
{
|
||||
void DrawLine3D(const Color3& color, const Vector3& A, const Vector3& B, float thickness)
|
||||
{
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glLineWidth(thickness);
|
||||
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
|
||||
@@ -221,27 +263,42 @@ namespace JGL
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void DrawString3D(const Color3& color, const std::string& text, const Vector3& pos, float scale, u32 size)
|
||||
void DrawString3D(const Color3& color, const std::string& text, const Vector3& pos, float scale, u32 size, unsigned int font_index)
|
||||
{
|
||||
float x = pos.x;
|
||||
float y = pos.y;
|
||||
float z = pos.z;
|
||||
GLfloat currentColor[4];
|
||||
std::vector<GLuint> textures(text.length());;
|
||||
glGetFloatv(GL_CURRENT_COLOR, currentColor);
|
||||
glUseProgram(0); // Fixed-function pipeline.
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
glColor4f(color.r, color.g, color.b, 1.0f);
|
||||
|
||||
FT_Set_Pixel_Sizes(face, 0, size);
|
||||
Font font;
|
||||
for (auto& f : faces)
|
||||
if (f.index == font_index)
|
||||
font = f;
|
||||
if (font.face == NULL) {
|
||||
std::cout << "null font" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const char* c;
|
||||
for (c = text.c_str(); *c; c++)
|
||||
|
||||
FT_Set_Pixel_Sizes(font.face, 0, size);
|
||||
|
||||
//for (c = text.c_str(); *c; c++)
|
||||
for (int i = 0; i < text.length(); i++)
|
||||
{
|
||||
if (FT_Load_Char(face, *c, FT_LOAD_RENDER))
|
||||
if (FT_Load_Char(font.face, text.c_str()[i], FT_LOAD_RENDER))
|
||||
continue;
|
||||
|
||||
FT_GlyphSlot g = face->glyph;
|
||||
|
||||
FT_GlyphSlot g = font.face->glyph;
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glGenTextures(1, &textures.at(i));
|
||||
glBindTexture(GL_TEXTURE_2D, textures[i]);
|
||||
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);
|
||||
@@ -282,7 +339,14 @@ namespace JGL
|
||||
y += (g->advance.y >> 6) * scale;
|
||||
|
||||
}
|
||||
|
||||
for (unsigned int& texture : textures)
|
||||
glDeleteTextures(1, &texture);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
||||
glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]); //Set draw color back to whatever it was before.
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user