Skip to content

Commit

Permalink
disable mip-mapping in fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 13, 2024
1 parent db565d2 commit 0a8ea7e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/assets/assetload_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ assetload::postfunc assetload::font(
if (page == nullptr) {
textures.emplace_back(nullptr);
} else {
textures.emplace_back(Texture::from(page.get()));
auto texture = Texture::from(page.get());
texture->setMipMapping(false);
textures.emplace_back(std::move(texture));
}
}
assets->store(
Expand Down
16 changes: 15 additions & 1 deletion src/graphics/core/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ std::unique_ptr<ImageData> GLTexture::readData() {
glBindTexture(GL_TEXTURE_2D, id);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data.get());
glBindTexture(GL_TEXTURE_2D, 0);
return std::make_unique<ImageData>(ImageFormat::rgba8888, width, height, data.release());
return std::make_unique<ImageData>(
ImageFormat::rgba8888, width, height, data.release()
);
}

void GLTexture::setNearestFilter() {
Expand All @@ -69,6 +71,18 @@ void GLTexture::setNearestFilter() {
glBindTexture(GL_TEXTURE_2D, 0);
}

void GLTexture::setMipMapping(bool flag) {
bind();
if (flag) {
glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST
);
} else {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
glBindTexture(GL_TEXTURE_2D, 0);
}

std::unique_ptr<GLTexture> GLTexture::from(const ImageData* image) {
uint width = image->getWidth();
uint height = image->getHeight();
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/core/GLTexture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class GLTexture : public Texture {

virtual void reload(const ImageData& image) override;

virtual void setMipMapping(bool flag) override;

virtual std::unique_ptr<ImageData> readData() override;
virtual uint getId() const override;

Expand Down
2 changes: 2 additions & 0 deletions src/graphics/core/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ class Texture {

virtual uint getId() const = 0;

virtual void setMipMapping(bool flag) = 0;

static std::unique_ptr<Texture> from(const ImageData* image);
};

0 comments on commit 0a8ea7e

Please sign in to comment.