mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Now properly loads internal textures(jpg) in 3D models
This commit is contained in:
@@ -41,7 +41,7 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
|
||||
Texture::Texture(glm::vec2 size, GLenum format, GLenum format2, GLenum format3, void* data)
|
||||
Texture::Texture(Vector2 size, GLenum format, GLenum format2, GLenum format3, void* data)
|
||||
{
|
||||
m_RendererId = 0;
|
||||
m_Format = format;
|
||||
@@ -67,24 +67,20 @@ namespace Nuake
|
||||
//glGenerateMipmap(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
Texture::Texture(Vector2 size, unsigned char* data, int len)
|
||||
Texture::Texture(unsigned char* data, int len)
|
||||
{
|
||||
m_RendererId = 0;
|
||||
m_Width = size.x;
|
||||
m_Height = size.y;
|
||||
int channels = 0;
|
||||
m_LocalBuffer = stbi_load_from_memory(data, len, &m_Width, &m_Height, &channels, 0);
|
||||
glGenTextures(1, &m_RendererId);
|
||||
glBindTexture(GL_TEXTURE_2D, m_RendererId);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -1.0f);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_Width, m_Height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_LocalBuffer);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
if (m_LocalBuffer)
|
||||
@@ -93,12 +89,12 @@ namespace Nuake
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::string msg = "failed to load texture buffer";
|
||||
const std::string msg = "Failed to load texture from buffer";
|
||||
Logger::Log(msg, "texture", WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
Texture::Texture(glm::vec2 size, msdfgen::BitmapConstRef<unsigned char, 4>& bitmap, bool t)
|
||||
Texture::Texture(Vector2 size, msdfgen::BitmapConstRef<unsigned char, 4>& bitmap, bool t)
|
||||
{
|
||||
m_RendererId = 0;
|
||||
m_Width = size.x;
|
||||
@@ -110,7 +106,6 @@ namespace Nuake
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
|
||||
auto pixel = bitmap(0, bitmap.height - 0 - 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)bitmap.pixels);
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@ namespace Nuake
|
||||
int m_BPP; // byte per pixel.
|
||||
|
||||
public:
|
||||
Texture(const std::string& path);
|
||||
Texture(glm::vec2 size, msdfgen::BitmapConstRef<unsigned char, 4>& bitmap, bool t);
|
||||
Texture(glm::vec2 size, GLenum format, GLenum format2 = 0, GLenum format3 = 0, void* data = NULL);
|
||||
Texture(Vector2 size, unsigned char* data, int len);
|
||||
Texture(const std::string& path); // Load texture from file
|
||||
Texture(unsigned char* data, int len); // Used to load texture from a memory buffer
|
||||
|
||||
Texture(Vector2 size, GLenum format, GLenum format2 = 0, GLenum format3 = 0, void* data = 0); // Used to load texture from memeory with known size
|
||||
Texture(Vector2 size, msdfgen::BitmapConstRef<unsigned char, 4>& bitmap, bool t); // Used internally for MSDF fonts
|
||||
~Texture();
|
||||
|
||||
void Resize(glm::vec2 size);
|
||||
|
||||
@@ -522,9 +522,19 @@ namespace Nuake
|
||||
uint32_t textureIndex = std::atoi(String::Split(path, '*')[1].c_str());
|
||||
const aiTexture* aitexture = scene->GetEmbeddedTexture(path.c_str());
|
||||
|
||||
Vector2 textureSize = Vector2(aitexture->mWidth, aitexture->mHeight);
|
||||
auto texture = CreateRef<Texture>(textureSize, (unsigned char*)aitexture->pcData, textureSize.x);
|
||||
return texture;
|
||||
Ref<Texture> nuakeTexture;
|
||||
if (aitexture->mHeight == 0)
|
||||
{
|
||||
// We are using a compression like jpeg, where width is the size of the buffer in bytes.
|
||||
nuakeTexture = CreateRef<Texture>((unsigned char*)aitexture->pcData, aitexture->mWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 textureSize = Vector2(aitexture->mWidth, aitexture->mHeight);
|
||||
nuakeTexture = CreateRef<Texture>((unsigned char*)aitexture->pcData, textureSize.x);
|
||||
}
|
||||
|
||||
return nuakeTexture;
|
||||
}
|
||||
|
||||
std::string texturePath = modelDir + path;
|
||||
|
||||
Reference in New Issue
Block a user