-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "external/stb_image"] | ||
path = external/stb_image | ||
url = https://github.com/nothings/stb.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* File: ImageLoader.h | ||
* Author: kissholic | ||
* Copyright (c) 2024 kissholic. All wrongs reserved. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
namespace be { | ||
|
||
|
||
struct ImageWrapper { | ||
ImageWrapper() = default; | ||
ImageWrapper(unsigned char* Data, int Width, int Height, int Channels) | ||
: Data(Data), Width(Width), Height(Height), Channels(Channels) | ||
{} | ||
|
||
~ImageWrapper(); | ||
|
||
unsigned char* Data; | ||
int Width; | ||
int Height; | ||
int Channels; | ||
}; | ||
|
||
|
||
ImageWrapper LoadImage(std::filesystem::path const& ImagePath); | ||
|
||
|
||
} // namespace be |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* File: Texture.h | ||
* Author: kissholic | ||
* Copyright (c) 2024 kissholic. All wrongs reserved. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include "ImageLoader.h" | ||
|
||
namespace be { | ||
|
||
|
||
class Texture { | ||
public: | ||
Texture(ImageWrapper& Source); | ||
~Texture(); | ||
|
||
unsigned int GetTextureHandle() const noexcept { return mTextureHandle; } | ||
int GetWidth() const noexcept { return mWidth; } | ||
int GetHeight() const noexcept { return mHeight; } | ||
int GetChannels() const noexcept { return mChannels; } | ||
|
||
private: | ||
unsigned int mTextureHandle; | ||
int mWidth; | ||
int mHeight; | ||
int mChannels; | ||
}; | ||
|
||
|
||
} // namespace be |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* File: ImageLoader.cpp | ||
* Author: kissholic | ||
* Copyright (c) 2024 kissholic. All wrongs reserved. | ||
*/ | ||
|
||
#include "Graphics/ImageLoader.h" | ||
#include "spdlog/spdlog.h" | ||
|
||
#include "stb_image.h" | ||
|
||
namespace be { | ||
|
||
|
||
ImageWrapper::~ImageWrapper() | ||
{ | ||
stbi_image_free(Data); | ||
} | ||
|
||
ImageWrapper LoadImage(std::filesystem::path const& ImagePath) { | ||
ImageWrapper image; | ||
|
||
image.Data = stbi_load(ImagePath.c_str(), &image.Width, &image.Height, &image.Channels, 0); | ||
if (image.Data == nullptr) { | ||
spdlog::error("Failed to load image: {}", ImagePath.c_str()); | ||
} | ||
|
||
return image; | ||
} | ||
|
||
|
||
} // namespace be |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* File: STBImage.cpp | ||
* Author: kissholic | ||
* Copyright (c) 2024 kissholic. All wrongs reserved. | ||
*/ | ||
|
||
|
||
#define STB_IMAGE_IMPLEMENTATION | ||
#include "stb_image.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* File: Texture.cpp | ||
* Author: kissholic | ||
* Copyright (c) 2024 kissholic. All wrongs reserved. | ||
*/ | ||
|
||
#include "Graphics/Texture.h" | ||
#include "Graphics/ImageLoader.h" | ||
#include "glad/glad.h" | ||
|
||
|
||
|
||
namespace be { | ||
|
||
|
||
Texture::Texture(ImageWrapper& Source) | ||
: mTextureHandle(0), mWidth(Source.Width), mHeight(Source.Height), mChannels(Source.Channels) { | ||
glGenTextures(1, &mTextureHandle); | ||
glBindTexture(GL_TEXTURE_2D, mTextureHandle); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
|
||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, Source.Data); | ||
glGenerateMipmap(GL_TEXTURE_2D); | ||
} | ||
|
||
|
||
Texture::~Texture() { | ||
glDeleteTextures(1, &mTextureHandle); | ||
} | ||
|
||
|
||
} // namespace be |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters