Merge remote-tracking branch 'origin/master'
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m20s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m20s
# Conflicts: # main.cpp
This commit is contained in:
@@ -27,7 +27,7 @@ CPMAddPackage(
|
|||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
NAME ReWindow
|
NAME ReWindow
|
||||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-3.zip
|
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-9.zip
|
||||||
)
|
)
|
||||||
|
|
||||||
CPMAddPackage(
|
CPMAddPackage(
|
||||||
|
@@ -36,14 +36,16 @@ namespace JGL {
|
|||||||
public:
|
public:
|
||||||
explicit Texture(const std::string& file, TextureFilteringMode filtering_mode = TextureFilteringMode::BILINEAR, TextureWrappingMode wrapping_mode = TextureWrappingMode::CLAMP_TO_EDGE);
|
explicit Texture(const std::string& file, TextureFilteringMode filtering_mode = TextureFilteringMode::BILINEAR, TextureWrappingMode wrapping_mode = TextureWrappingMode::CLAMP_TO_EDGE);
|
||||||
Texture(const std::string& file, const TextureFlag& flags, TextureFilteringMode filtering_mode = TextureFilteringMode::BILINEAR, TextureWrappingMode wrapping_mode = TextureWrappingMode::CLAMP_TO_EDGE);
|
Texture(const std::string& file, const TextureFlag& flags, TextureFilteringMode filtering_mode = TextureFilteringMode::BILINEAR, TextureWrappingMode wrapping_mode = TextureWrappingMode::CLAMP_TO_EDGE);
|
||||||
|
Texture(SoftwareTexture* software_texture, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode);
|
||||||
public:
|
public:
|
||||||
GLuint GetGLTextureHandle() const;
|
[[nodiscard]] GLuint GetGLTextureHandle() const;
|
||||||
Vector2 GetDimensions() const;
|
[[nodiscard]] Vector2 GetDimensions() const;
|
||||||
TextureFilteringMode GetFilteringMode() const;
|
[[nodiscard]] TextureFilteringMode GetFilteringMode() const;
|
||||||
TextureFlag GetFlags() const;
|
[[nodiscard]] TextureWrappingMode GetWrappingMode() const;
|
||||||
TextureFormat GetFormat() const;
|
[[nodiscard]] TextureFlag GetFlags() const;
|
||||||
std::vector<Color4> GetPixelData() const;
|
[[nodiscard]] TextureFormat GetFormat() const;
|
||||||
|
[[nodiscard]] std::vector<Color4> GetPixelData() const;
|
||||||
|
SoftwareTexture GetSoftwareTexture() const;
|
||||||
void Erase();
|
void Erase();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
14
main.cpp
14
main.cpp
@@ -71,6 +71,8 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
Texture* image;
|
Texture* image;
|
||||||
|
Texture* reloaded_image;
|
||||||
|
|
||||||
//The Re3D style base projection.
|
//The Re3D style base projection.
|
||||||
std::vector<GLfloat> perspective(float fov, float aspect, float nearPlane, float farPlane) {
|
std::vector<GLfloat> perspective(float fov, float aspect, float nearPlane, float farPlane) {
|
||||||
std::vector<float> result(16);
|
std::vector<float> result(16);
|
||||||
@@ -153,10 +155,15 @@ public:
|
|||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
image = new Texture("assets/sprites/Re3D.png", TextureFilteringMode::BILINEAR);
|
image = new Texture("assets/sprites/Re3D.png", TextureFilteringMode::BILINEAR);
|
||||||
|
|
||||||
|
auto* software_texture = new SoftwareTexture(image->GetSoftwareTexture());
|
||||||
|
reloaded_image = new Texture(software_texture, TextureFilteringMode::BILINEAR, TextureWrappingMode::CLAMP_TO_EDGE);
|
||||||
|
delete software_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 textAngle = {0,0,0};
|
Vector3 textAngle = {0,0,0};
|
||||||
void display() {
|
void display() {
|
||||||
|
JGL::Update(getSize());
|
||||||
textAngle.y += 2.0f;
|
textAngle.y += 2.0f;
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@@ -175,7 +182,7 @@ public:
|
|||||||
J2D::Begin();
|
J2D::Begin();
|
||||||
J2D::FillQuad(Color4(Colors::Red), {500, 52}, {500, 152}, {600, 152}, {600, 52});
|
J2D::FillQuad(Color4(Colors::Red), {500, 52}, {500, 152}, {600, 152}, {600, 52});
|
||||||
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
|
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
|
||||||
J2D::DrawSprite(*image, {200, 252}, {0.5, 0.5}, {2, 1});
|
J2D::DrawSprite(*reloaded_image, {200, 252}, {0.5, 0.5}, {2, 1});
|
||||||
J2D::FillRect(Colors::Pinks::HotPink, {68, 120}, {32, 32});
|
J2D::FillRect(Colors::Pinks::HotPink, {68, 120}, {32, 32});
|
||||||
J2D::FillGradientRect(Colors::Red, Colors::Blue, Gradient::DiagonalBottomLeft, {100,52}, {100,100});
|
J2D::FillGradientRect(Colors::Red, Colors::Blue, Gradient::DiagonalBottomLeft, {100,52}, {100,100});
|
||||||
J2D::FillRoundedRect(Colors::Red, {200, 52}, {100, 100}, 8, 8);
|
J2D::FillRoundedRect(Colors::Red, {200, 52}, {100, 100}, 8, 8);
|
||||||
@@ -222,6 +229,7 @@ public:
|
|||||||
glSwapBuffers();
|
glSwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override {/* glViewport(0, 0, e.Size.x, e.Size.y); std::cout << e.Size.x;*/ return true;}
|
||||||
|
|
||||||
void OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent & ev) override
|
void OnMouseButtonDown(const ReWindow::WindowEvents::MouseButtonDownEvent & ev) override
|
||||||
{
|
{
|
||||||
@@ -241,7 +249,7 @@ public:
|
|||||||
d.Release();
|
d.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override {return true;}
|
|
||||||
JGLDemoWindow() : ReWindow::RWindow() {}
|
JGLDemoWindow() : ReWindow::RWindow() {}
|
||||||
JGLDemoWindow(const std::string& title, int width, int height) : ReWindow::RWindow(title, width, height){}
|
JGLDemoWindow(const std::string& title, int width, int height) : ReWindow::RWindow(title, width, height){}
|
||||||
};
|
};
|
||||||
@@ -251,7 +259,7 @@ int main(int argc, char** argv) {
|
|||||||
window->setRenderer(RenderingAPI::OPENGL);
|
window->setRenderer(RenderingAPI::OPENGL);
|
||||||
window->Open();
|
window->Open();
|
||||||
window->initGL();
|
window->initGL();
|
||||||
window->setResizable(false);
|
window->setResizable(true);
|
||||||
|
|
||||||
while (window->isAlive()) {
|
while (window->isAlive()) {
|
||||||
window->pollEvents();
|
window->pollEvents();
|
||||||
|
@@ -31,14 +31,14 @@ namespace JGL {
|
|||||||
|
|
||||||
|
|
||||||
void J2D::Begin() {
|
void J2D::Begin() {
|
||||||
|
glViewport(0, 0, wS.x, wS.y);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(0, wS.x, wS.y, 0, -1, 1);
|
glOrtho(0, wS.x, wS.y, 0, -1, 1);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
|
||||||
//Get what the draw color was before we did anything.
|
//Get what the draw color was before we did anything.
|
||||||
glGetFloatv(GL_CURRENT_COLOR, oldColor);
|
glGetFloatv(GL_CURRENT_COLOR, oldColor);
|
||||||
glColor4f(baseColor[0], baseColor[1], baseColor[2], baseColor[3]);
|
glColor4f(baseColor[0], baseColor[1], baseColor[2], baseColor[3]);
|
||||||
|
@@ -5,7 +5,7 @@ using namespace ReTexture;
|
|||||||
|
|
||||||
namespace JGL
|
namespace JGL
|
||||||
{
|
{
|
||||||
Texture::Texture(const std::string &file, const ReTexture::TextureFlag &flags, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode)
|
Texture::Texture(const std::string& file, const ReTexture::TextureFlag& flags, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode)
|
||||||
{
|
{
|
||||||
auto *t = new ReTexture::SoftwareTexture(file, flags);
|
auto *t = new ReTexture::SoftwareTexture(file, flags);
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ namespace JGL
|
|||||||
delete t;
|
delete t;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(const std::string &file, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode) {
|
Texture::Texture(const std::string& file, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode) {
|
||||||
auto *t = new SoftwareTexture(file);
|
auto *t = new SoftwareTexture(file);
|
||||||
|
|
||||||
load(t, {(float) t->getWidth(), (float) t->getHeight()}, t->getTextureFormat(), filtering_mode,
|
load(t, {(float) t->getWidth(), (float) t->getHeight()}, t->getTextureFormat(), filtering_mode,
|
||||||
@@ -27,9 +27,9 @@ namespace JGL
|
|||||||
delete t;
|
delete t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::load(SoftwareTexture *software_texture, const Vector2 &size, const TextureFormat &format,
|
void Texture::load(SoftwareTexture *software_texture, const Vector2& size, const TextureFormat& format,
|
||||||
TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode) {
|
TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode) {
|
||||||
glGenTextures(1, &texture_handle);
|
glGenTextures(1,& texture_handle);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture_handle);
|
glBindTexture(GL_TEXTURE_2D, texture_handle);
|
||||||
|
|
||||||
if (format == TextureFormat::RGBA)
|
if (format == TextureFormat::RGBA)
|
||||||
@@ -119,6 +119,7 @@ namespace JGL
|
|||||||
|
|
||||||
if (texture_format == TextureFormat::RGBA) {
|
if (texture_format == TextureFormat::RGBA) {
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, result.data());
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, result.data());
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,8 +127,9 @@ namespace JGL
|
|||||||
std::vector<Color3> color3((size_t) (texture_size.x * texture_size.y));
|
std::vector<Color3> color3((size_t) (texture_size.x * texture_size.y));
|
||||||
|
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, color3.data());
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, color3.data());
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
for (const auto &c: color3)
|
for (const auto& c: color3)
|
||||||
result.emplace_back(c);
|
result.emplace_back(c);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -135,7 +137,7 @@ namespace JGL
|
|||||||
|
|
||||||
void Texture::Erase() {
|
void Texture::Erase() {
|
||||||
if (texture_handle != 0)
|
if (texture_handle != 0)
|
||||||
glDeleteTextures(1, &texture_handle);
|
glDeleteTextures(1,& texture_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint Texture::GetGLTextureHandle() const {
|
GLuint Texture::GetGLTextureHandle() const {
|
||||||
@@ -158,4 +160,18 @@ namespace JGL
|
|||||||
return texture_filtering_mode;
|
return texture_filtering_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextureWrappingMode Texture::GetWrappingMode() const {
|
||||||
|
return texture_wrapping_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoftwareTexture Texture::GetSoftwareTexture() const {
|
||||||
|
std::vector<unsigned char> software_pixel_data((GetDimensions().x * GetDimensions().y) * 4);
|
||||||
|
|
||||||
|
memcpy(software_pixel_data.data(), GetPixelData().data(), (GetDimensions().x * GetDimensions().y) * 4);
|
||||||
|
return {software_pixel_data, TextureFormat::RGBA, static_cast<unsigned int>(GetDimensions().x), static_cast<unsigned int>(GetDimensions().y)};
|
||||||
|
}
|
||||||
|
|
||||||
|
Texture::Texture(SoftwareTexture* software_texture, TextureFilteringMode filtering_mode, TextureWrappingMode wrapping_mode) {
|
||||||
|
load(software_texture, {static_cast<float>(software_texture->getWidth()), static_cast<float>(software_texture->getHeight())}, software_texture->getTextureFormat(), filtering_mode, wrapping_mode);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user