Compare commits

...

4 Commits

Author SHA1 Message Date
41916a4089 Update JGL.cpp 2024-05-29 15:05:06 -04:00
222dd346fb Fix memleak 2024-05-27 20:48:22 -04:00
e6e567725b Color 2024-05-23 12:05:00 -04:00
93612bb816 Update JGL 2024-05-23 10:57:48 -04:00
4 changed files with 32 additions and 53 deletions

View File

@@ -21,49 +21,38 @@ include(cmake/CPM.cmake)
CPMAddPackage( CPMAddPackage(
NAME J3ML NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-1.zip URL https://git.redacted.cc/josh/j3ml/archive/Release-6.zip
) )
CPMAddPackage( CPMAddPackage(
NAME ReWindow NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.23.zip URL https://git.redacted.cc/Redacted/ReWindow/archive/vA0.2.30.zip
) )
CPMAddPackage( CPMAddPackage(
NAME GLAD NAME GLAD
URL https://git.redacted.cc/Redacted/glad/archive/v2.1.zip URL https://git.redacted.cc/Redacted/glad/archive/v2.1.zip
) )
file(COPY "assets" DESTINATION "${PROJECT_BINARY_DIR}")
CPMAddPackage(
NAME LearnOpenGL
URL https://git.redacted.cc/josh/LearnOpenGL/archive/Prerelease-4.zip
)
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp") file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" ) file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" )
file(GLOB_RECURSE ASSETS "content/*") file(GLOB_RECURSE ASSETS "assets/*")
add_library(JGL SHARED ${SOURCES}) add_library(JGL SHARED ${SOURCES})
set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(Freetype REQUIRED) find_package(Freetype REQUIRED)
add_executable(JGL_Demo main.cpp) add_executable(JGL_Demo main.cpp)
set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib") set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
include_directories(${PROJECT_SOURCE_DIR}/include) include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${OPENGL_INCLUDE_DIRS}) include_directories(${OPENGL_INCLUDE_DIRS})
include_directories(${GLUT_INCLUDE_DIRS})
include_directories(${J3ML_SOURCE_DIR}/include) include_directories(${J3ML_SOURCE_DIR}/include)
include_directories(${ReWindow_SOURCE_DIR}/include) include_directories(${ReWindow_SOURCE_DIR}/include)
include_directories(${glad_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_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS})
target_link_libraries(JGL PRIVATE ${FREETYPE_LIBRARIES}) target_link_libraries(JGL PRIVATE ${FREETYPE_LIBRARIES})
target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS}) target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS})
target_link_libraries(JGL_Demo PUBLIC JGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} J3ML ReWindowLibrary GLEW glad) target_link_libraries(JGL_Demo PUBLIC JGL ${OPENGL_LIBRARIES} J3ML ReWindowLibrary glad)

View File

@@ -1,9 +1,6 @@
//#include <GL/glew.h>
#include <glad/glad.h> #include <glad/glad.h>
#include <JGL/JGL.h> #include <JGL/JGL.h>
#include <rewindow/types/window.h> #include <rewindow/types/window.h>
#include <iostream>
#include <LearnOpenGL/Shader.h>
#include <JGL/Colors.h> #include <JGL/Colors.h>
#include <J3ML/LinearAlgebra/Vector2.h> #include <J3ML/LinearAlgebra/Vector2.h>
@@ -23,21 +20,6 @@ struct Character
std::map<char, Character> Characters; std::map<char, Character> Characters;
GLuint VAO, VBO; 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; using J3ML::LinearAlgebra::Matrix4x4;
@@ -51,7 +33,6 @@ struct point {
class JGLDemoWindow : public ReWindow::RWindow class JGLDemoWindow : public ReWindow::RWindow
{ {
public: public:
LearnOpenGL::Shader shader;
JGLDemoWindow() : ReWindow::RWindow() {} JGLDemoWindow() : ReWindow::RWindow() {}
JGLDemoWindow(const std::string& title, int width, int height) : JGLDemoWindow(const std::string& title, int width, int height) :
@@ -101,7 +82,7 @@ public:
JGL::J2D::FillTriangle2D(JGL::Colors::Yellow, tri); JGL::J2D::FillTriangle2D(JGL::Colors::Yellow, tri);
JGL::J3D::DrawString3D(JGL::Colors::White, "JGL Sample Text", {1, -120, 0.5f}, 2.f); JGL::J3D::DrawString3D(JGL::Colors::Red, "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::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::J2D::DrawLine2D(JGL::Colors::Greens::DarkGreen, {10, 10}, {200, 300});

View File

@@ -4,7 +4,6 @@
#include <glad/glad.h> #include <glad/glad.h>
#include <JGL/JGL.h> #include <JGL/JGL.h>
#include <J3ML/LinearAlgebra/Transform2D.h>
#include <freetype2/ft2build.h> #include <freetype2/ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include <JGL/Color3.h> #include <JGL/Color3.h>
@@ -12,7 +11,6 @@
GLuint program; GLuint program;
GLuint texture;
namespace JGL namespace JGL
{ {
@@ -29,7 +27,7 @@ namespace JGL
return false; return false;
} }
if (FT_New_Face(ft, "content/FreeSans.ttf", 0, &face)) if (FT_New_Face(ft, "assets/fonts/FreeSans.ttf", 0, &face))
{ {
std::cout << "Error::FREETYPE: Failed to load font!" << std::endl; std::cout << "Error::FREETYPE: Failed to load font!" << std::endl;
return false; return false;
@@ -153,17 +151,17 @@ namespace JGL
FT_Set_Pixel_Sizes(face, 0, size); FT_Set_Pixel_Sizes(face, 0, size);
const char* c; GLuint textures[text.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(face, text.c_str()[i], FT_LOAD_RENDER))
continue; continue;
FT_GlyphSlot g = face->glyph; FT_GlyphSlot g = face->glyph;
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &texture); glGenTextures(1, &textures[i]);
glBindTexture(GL_TEXTURE_2D, texture); 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_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 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_MIN_FILTER, GL_LINEAR);
@@ -201,8 +199,9 @@ namespace JGL
x += (g->advance.x >> 6) * scale; x += (g->advance.x >> 6) * scale;
y += (g->advance.y >> 6) * scale; y += (g->advance.y >> 6) * scale;
} }
for (auto& t : textures)
glDeleteTextures(1, &t);
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
} }
} }
@@ -212,7 +211,6 @@ namespace JGL
{ {
void DrawLine3D(const Color3& color, const Vector3& A, const Vector3& B, float thickness) void DrawLine3D(const Color3& color, const Vector3& A, const Vector3& B, float thickness)
{ {
glBegin(GL_LINES); glBegin(GL_LINES);
glLineWidth(thickness); glLineWidth(thickness);
glColor3f(color.r/255.f, color.g/255.f, color.b/255.f); glColor3f(color.r/255.f, color.g/255.f, color.b/255.f);
@@ -226,22 +224,27 @@ namespace JGL
float x = pos.x; float x = pos.x;
float y = pos.y; float y = pos.y;
float z = pos.z; float z = pos.z;
GLfloat currentColor[4];
GLuint textures[text.size()];
glGetFloatv(GL_CURRENT_COLOR, currentColor);
glUseProgram(0); // Fixed-function pipeline. 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); FT_Set_Pixel_Sizes(face, 0, size);
const char* c; //for (c = text.c_str(); *c; c++)
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(face, text.c_str()[i], FT_LOAD_RENDER))
continue; continue;
FT_GlyphSlot g = face->glyph; FT_GlyphSlot g = face->glyph;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &texture); glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture); glGenTextures(1, &textures[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_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 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_MIN_FILTER, GL_LINEAR);
@@ -282,7 +285,13 @@ namespace JGL
y += (g->advance.y >> 6) * scale; y += (g->advance.y >> 6) * scale;
} }
for (auto& t : textures)
glDeleteTextures(1, &t);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture 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.
} }
} }