Skip to content
Snippets Groups Projects
Commit 83f8eb5b authored by BATON Theau's avatar BATON Theau
Browse files

Resolve texture Bug

parent 5390465c
No related branches found
No related tags found
No related merge requests found
Showing
with 46 additions and 40 deletions
assets/textures/Cube_Redy.png

1.17 KiB

assets/textures/Cube_Saumon.png

314 B

assets/textures/Cube_Sepia.png

282 B

assets/textures/Cube_Void.png

307 B

assets/textures/Cube_Yellow.png

314 B | W: | H:

assets/textures/Cube_Yellow.png

282 B | W: | H:

assets/textures/Cube_Yellow.png
assets/textures/Cube_Yellow.png
assets/textures/Cube_Yellow.png
assets/textures/Cube_Yellow.png
  • 2-up
  • Swipe
  • Onion skin
assets/textures/Cube_Yellowy.png

1.36 KiB

......@@ -17,6 +17,13 @@ namespace megu {
Texture::Texture(const Texture & texture)
: _id(texture._id), _type(texture._type), _slot(texture._slot) {}
Texture & Texture::operator=(const Texture & texture) {
this->_id = texture._id;
this->_slot = texture._slot;
this->_type = texture._type;
return *this;
}
Texture::~Texture() {
glDeleteTextures(1, &this->_id);
}
......
......@@ -11,7 +11,7 @@ namespace megu {
Texture(GLuint = 0, GLuint = GL_TEXTURE_2D);
Texture(const std::filesystem::path &, GLuint = 0);
Texture(const Texture &);
Texture & operator=(const Texture &) = delete;
Texture & operator=(const Texture &);
~Texture();
enum Wraping {
......
......@@ -9,7 +9,7 @@ namespace megu {
public:
TextureBuffer();
TextureBuffer(GLuint, GLuint, GLubyte *, GLenum);
TextureBuffer(const std::filesystem::path &, bool = false);
TextureBuffer(const std::filesystem::path &, bool = true);
TextureBuffer(const TextureBuffer &);
TextureBuffer & operator=(const TextureBuffer & src);
~TextureBuffer() = default;
......
#pragma once
#include <engine/graphics/back/cameras/Camera.hpp>
#include <engine/io/Window.hpp>
namespace megu {
class DrawGroup {
public:
virtual void draw(const Camera &) const = 0;
virtual void draw(const Window &, const Camera &) const = 0;
};
}
\ No newline at end of file
......@@ -32,18 +32,18 @@ namespace megu {
}
}
void ImageGroup::draw(const Camera & camera) const {
void ImageGroup::draw(const Window & window, const Camera & camera) const {
this->_vao.bind();
this->_program.use();
std::map<std::reference_wrapper<const Texture>, std::vector<std::reference_wrapper<const glm::mat4>>> data;
std::map<std::reference_wrapper<const Texture>, std::vector<glm::mat4>, std::greater<megu::Texture>> data;
for(auto & image : this->_images) {
data[image.get().texture()].push_back(image.get().transformation().model());
}
for(auto &[texture, models] : data) {
texture.get().bind();
texture.get().bind(0);
this->_program.setUniform("uProj", camera.projection());
this->_program.setUniform("uView", camera.view());
......
......@@ -20,7 +20,7 @@ namespace megu {
ImageGroup();
~ImageGroup() = default;
void draw(const Camera & camera) const override;
void draw(const Window &, const Camera &) const override;
void add(const Image &);
void update();
......
......@@ -9,7 +9,7 @@ namespace megu {
}
if(img1.transformation().y() != img2.transformation().y()) {
return img1.transformation().y() < img2.transformation().y();
return img1.transformation().y() > img2.transformation().y();
}
if(img1.transformation().x() != img2.transformation().x()) {
......
......@@ -14,9 +14,11 @@ namespace megu {
}
Image::Image(const Texture & texture)
: _texture(texture),
: _texture(),
_geometry(),
_transformation() {}
_transformation() {
this->load(texture);
}
Image::Image(const Image & src)
: _texture(src._texture),
......@@ -34,4 +36,9 @@ namespace megu {
this->setSize(static_cast<float>(buffer.width()), static_cast<float>(buffer.height()));
this->_texture.store(buffer);
}
void Image::load(const Texture & texture) {
this->setSize(static_cast<float>(texture.width()), static_cast<float>(texture.height()));
this->_texture = texture;
}
}
\ No newline at end of file
......@@ -26,8 +26,9 @@ namespace megu {
inline void setRotation(float a) {this->_transformation.setRotation(a, Transformable::Axis::Z);}
inline void setLayer(float l) {this->_transformation.setZ(l);}
void load(const std::filesystem::path &, bool = true);
void load(const std::filesystem::path &, bool = false);
void load(const TextureBuffer &);
void load(const Texture &);
inline const Texture & texture() const {return this->_texture;}
inline const Quads & geometry() const {return this->_geometry;}
......
......@@ -50,29 +50,16 @@ int main(int argc, const char * argv[]) {
//? Image
std::vector<int> map = {
1, 0, 0, 0, 1, 1, 0, 0, 0, 1,
0, 1, 0, 1, 0, 0, 1, 0, 1, 0,
0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 1, 0, 1, 0,
1, 0, 0, 0, 1, 1, 0, 0, 0, 1,
1, 0, 0, 0, 1, 1, 0, 0, 0, 1,
0, 1, 0, 1, 0, 0, 1, 0, 1, 0,
0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 1, 0, 1, 0,
1, 0, 0, 0, 1, 1, 0, 0, 0, 1,
};
std::vector<std::string> textures = {
"assets/textures/Cube_Red.png",
"assets/textures/Cube_Blue.png",
"assets/textures/Cube_Green.png",
"assets/textures/Cube_Cyan.png",
"assets/textures/Cube_Pink.png",
"assets/textures/Cube_Yellow.png",
"assets/textures/Cube_Magenta.png",
"assets/textures/Cube_Purple.png",
"assets/textures/Cube_Gray.png",
"assets/textures/Cube_Orange.png"
0, 0, 0, 0, 1, 2, 3, 0, 0, 3,
0, 0, 0, 2, 0, 3, 0, 0, 3, 1,
0, 0, 1, 3, 3, 0, 0, 0, 2, 2,
0, 2, 1, 0, 0, 1, 0, 2, 0, 0,
2, 1, 3, 1, 0, 0, 3, 0, 1, 0,
1, 3, 0, 2, 3, 0, 0, 1, 0, 0,
0, 1, 0, 0, 1, 2, 3, 1, 0, 0,
0, 0, 0, 0, 2, 0, 1, 0, 1, 0,
0, 0, 0, 2, 0, 0, 0, 1, 3, 0,
0, 0, 3, 1, 2, 0, 0, 0, 2, 3,
};
size_t x = 0;
......@@ -80,13 +67,16 @@ int main(int argc, const char * argv[]) {
std::vector<std::unique_ptr<megu::Image>> images;
megu::Texture texture;
texture.store(megu::TextureBuffer("assets/textures/Cube_Grass.png"));
for(auto id : map) {
if(x == 10) {
x = 0;
++y;
}
images.push_back(std::make_unique<megu::Image>(textures.at(3)));
images.push_back(std::make_unique<megu::Image>(texture));
glm::vec2 pos = to_screen_coordinate({x, y}, 32.f, 32.f);
images.back()->setPosition(pos.x + 160, pos.y);
......@@ -106,7 +96,7 @@ int main(int argc, const char * argv[]) {
ImGui_ImplGlfw_InitForOpenGL(window.ptr(), true);
//? Render Loop
glClearColor(NORMALIZE(110), NORMALIZE(110), NORMALIZE(255), 0.f);
glClearColor(1.f, 1.f, 1.f, 1.f);
double lastTime = glfwGetTime();
int nbFrames = 0;
......@@ -130,9 +120,9 @@ int main(int argc, const char * argv[]) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
window.pollEvents();
group.draw(view);
group.draw(window, view);
ImGui_ImplOpenGL3_NewFrame();
/*ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
......@@ -184,7 +174,7 @@ int main(int argc, const char * argv[]) {
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());*/
window.swapBuffers();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment