Compare commits
7 Commits
Prerelease
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
|
f5f590164a | ||
c45485cabd | |||
143703dea3 | |||
|
48493cb2fc | ||
5b7829b1f8 | |||
868f52464e | |||
d1d2493435 |
144
CMakeLists.txt
144
CMakeLists.txt
@@ -1,67 +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.14.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME GLAD
|
||||
URL https://git.redacted.cc/Redacted/glad/archive/v2.1.zip
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE HEADERS "include/*.h" "include/*.hpp")
|
||||
file(GLOB_RECURSE SOURCES "src/*.c" "src/*.cpp" )
|
||||
file(GLOB_RECURSE ASSETS "content/*")
|
||||
|
||||
add_library(JGL SHARED ${SOURCES}
|
||||
include/JGL/JGL.h
|
||||
src/JGL/JGL.cpp
|
||||
include/LearnOpenGL/Shader.h
|
||||
include/LearnOpenGL/Texture2D.h
|
||||
include/JGL/Color3.h
|
||||
include/JGL/Colors.h
|
||||
include/JGL/Color4.h
|
||||
)
|
||||
set_target_properties(JGL PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLUT REQUIRED)
|
||||
find_package(Freetype REQUIRED)
|
||||
|
||||
add_executable(JGL_Demo main.cpp)
|
||||
set_target_properties(JGL_Demo PROPERTIES LINK_FLAGS "-Wl,-rpath,./lib")
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
include_directories(${OPENGL_INCLUDE_DIRS})
|
||||
include_directories(${GLUT_INCLUDE_DIRS})
|
||||
include_directories(${J3ML_SOURCE_DIR}/include)
|
||||
include_directories(${ReWindow_SOURCE_DIR}/include)
|
||||
include_directories(${glad_SOURCE_DIR}/include)
|
||||
|
||||
target_link_libraries(JGL PRIVATE ${FREETYPE_LIBRARIES})
|
||||
target_include_directories(JGL PRIVATE ${FREETYPE_INCLUDE_DIRS})
|
||||
target_link_libraries(JGL_Demo PUBLIC JGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} J3ML ReWindowLibrary GLEW glad)
|
||||
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)
|
||||
|
@@ -10,6 +10,10 @@
|
||||
#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 {
|
||||
@@ -22,6 +26,10 @@ namespace JGL {
|
||||
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;
|
||||
@@ -50,32 +58,19 @@ namespace JGL {
|
||||
|
||||
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 DrawCubicBezierCurve2D();
|
||||
|
||||
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(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);
|
||||
@@ -87,8 +82,14 @@ namespace JGL {
|
||||
}
|
||||
namespace J3D {
|
||||
void DrawLine3D(const Color3& color, const Vector3 &A, const Vector3 &B, float thickness = 1);
|
||||
void FillSphere3D();
|
||||
void WireframeSphere3D(const Sphere& sphere);
|
||||
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&);
|
||||
|
@@ -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);
|
||||
};
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace {
|
||||
// Texture2D is able to store and configure a texture in OpenGL
|
||||
// It also hosts utility functions for easy management.
|
||||
class Texture2D {
|
||||
public:
|
||||
unsigned int ID; // ID of the texture object
|
||||
unsigned int Width, Height;
|
||||
unsigned int InternalFormat;
|
||||
unsigned int ImageFormat;
|
||||
unsigned int WrapS;
|
||||
unsigned int WrapT;
|
||||
unsigned int Filter_Min;
|
||||
unsigned int Filter_Max;
|
||||
|
||||
Texture2D();
|
||||
|
||||
void Generate(unsigned int width, unsigned int height, unsigned char *data);
|
||||
|
||||
void Bind() const;
|
||||
};
|
||||
}
|
12
main.cpp
12
main.cpp
@@ -53,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)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -69,7 +71,7 @@ public:
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
//glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
@@ -122,9 +124,9 @@ public:
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
auto* 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())
|
||||
|
@@ -4,9 +4,7 @@
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <JGL/JGL.h>
|
||||
#include <GL/glut.h>
|
||||
#include <J3ML/LinearAlgebra/Transform2D.h>
|
||||
#include <rewindow/types/window.h>
|
||||
#include <freetype2/ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include <JGL/Color3.h>
|
||||
|
@@ -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() {}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
#include <LearnOpenGL/Texture2D.h>
|
||||
#include <glad/glad.h>
|
||||
#include <GL/glut.h>
|
||||
|
||||
Texture2D::Texture2D()
|
||||
: Width(0), Height(0), InternalFormat(GL_RGB), ImageFormat(GL_RGB), WrapS(GL_REPEAT), WrapT(GL_REPEAT),
|
||||
Filter_Min(GL_LINEAR), Filter_Max(GL_LINEAR) {
|
||||
glGenTextures(1, &this->ID);
|
||||
}
|
||||
|
||||
void Texture2D::Generate(unsigned int width, unsigned int height, unsigned char *data) {
|
||||
this->Width = width;
|
||||
this->Height = height;
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, this->InternalFormat, width, height, 0, this->ImageFormat, GL_UNSIGNED_BYTE,
|
||||
data);
|
||||
// set Texture wrap and filter modes
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, this->WrapS);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, this->WrapT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, this->Filter_Min);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, this->Filter_Max);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void Texture2D::Bind() const
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
}
|
Reference in New Issue
Block a user