my problem is that while loading any type of image with the library STB image I get the next error: BAD PNG SIG, even if It's not even a PNG, all the code worked before I tried making an OBJECT class as I'm learning OpenGL, now the results that I get are the next:
First I get no apparent errors so far apart to the fact that I should be seeing two textures and not only the crate one,
and the other thing that happens if i run the program but with a different texture is that i get a debugBreak:

The codes for the different parts of the texture Generation/Loading are the next:
Texture creating/adding:
TEXTURE tex1("res/textures/container.jpg", FILTER_LINEAR, GL_RGB, GL_TEXTURE_2D);
TEXTURE tex2("res/textures/dog.jpg", FILTER_NEAREST, GL_RGBA, GL_TEXTURE_2D);
box1.AddTextures(tex1);
box1.AddTextures(tex2);
This is the texture class:
class TEXTURE{
private:
unsigned int m_TextureID;
std::string m_filepath;
int m_width, m_height, m_BPP;
unsigned int m_TextureType;
public:
TEXTURE(std::string filepath, FILTERING_OPTIONS opt, unsigned int RGB_CHANNEL, unsigned int TEXTURE_TYPE, bool FLIP_IMAGE = 0, bool MIPMAP = 1);
~TEXTURE();
void Bind(unsigned int slot = 0);
void Unbind();
inline int GetWidth() const { return m_width; }
inline int GetHeight() const { return m_height; }
};
And its constructor is the next:
TEXTURE::TEXTURE(std::string filepath, FILTERING_OPTIONS opt, unsigned int RGB_CHANNEL, unsigned int TEXTURE_TYPE, bool FLIP_IMAGE, bool MIPMAP) : m_filepath(filepath), m_TextureType(TEXTURE_TYPE){
//stbi_set_flip_vertically_on_load(FLIP_IMAGE);
stbi_set_flip_vertically_on_load(1);
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT));
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT));
float borderColor[] = { 1.0f, 1.0f, 0.0f, 1.0f };
glCall(glTexParameterfv(TEXTURE_TYPE, GL_TEXTURE_BORDER_COLOR, borderColor));
if (MIPMAP) {
switch (opt)
{
case FILTER_NEAREST:
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR));
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
break;
case FILTER_LINEAR:
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
break;
case BOTH:
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR));
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
break;
default:
std::cerr << "[Error]: Wrong option parameter" << std::endl;
return;
break;
}
}
else {
switch (opt)
{
case FILTER_NEAREST:
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
break;
case FILTER_LINEAR:
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
break;
case BOTH:
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
glCall(glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
break;
default:
std::cerr << "[Error]: Wrong option parameter" << std::endl;
return;
break;
}
}
unsigned char* data = stbi_load(filepath.c_str(), &m_width, &m_height, &m_BPP, 0);
glCall(glGenTextures(1, &m_TextureID));
glCall(glBindTexture(m_TextureType, m_TextureID));
std::cerr << stbi_failure_reason() << std::endl;
if (data)
{
glCall(glTexImage2D(TEXTURE_TYPE, 0, GL_RGB, m_width, m_height, 0, RGB_CHANNEL, GL_UNSIGNED_BYTE, data));
glCall(if (MIPMAP) glGenerateMipmap(TEXTURE_TYPE));
}
else
{
std::cout << "Failed to load texture" << std::endl;
};
stbi_image_free(data);
}
This is the texture bind function:
void TEXTURE::Bind(unsigned int slot){
glCall(glActiveTexture(GL_TEXTURE0 + slot));
glCall(glBindTexture(m_TextureType, m_TextureID));
}
And the loading is beeing made by the OBJECT class:
This adds the texture to a vector:
void OBJECT::AddTextures(TEXTURE texture){
textures.push_back(texture);
}
and this loads the OBJECT(and the textures):
void OBJECT::Show(bool INDEXED, callbackFunction preRenderFunction){
vb.Bind();
va.Bind();
shader.Bind();
shader.Use();
for (unsigned int i = 0; i < textures.size(); i++) {
textures[i].Bind(i);
}
preRenderFunction(this);
if (INDEXED) {
ib.Bind();
glCall(glDrawElements(GL_TRIANGLES, ib.GetLength() , GL_UNSIGNED_INT, 0));
}else glDrawArrays(GL_TRIANGLES, 0, vb.GetLength());
}
This is the shader bind and use functions
void SHADER::Bind(){
glCall(glUseProgram(m_ShaderProgramID));
}
void SHADER::Use(){
glCall(glUseProgram(m_ShaderProgramID));
}
This is the vertex shader:
#version 330 core
layout (location = 0) in vec3 aPos; // the position variable has attribute position 0
layout (location = 1) in vec2 aTexCoord;
out vec3 vertexColor; // specify a color output to the fragment shader
out vec2 TexCoord;
uniform mat4 transform;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 MVP;
void main()
{
gl_Position = projection * view * model * transform * vec4(aPos, 1.0); // see how we directly give a vec3 to vec4's constructor
//gl_Position = MVP* vec4(aPos, 1.0);
//gl_Position = projection * view * model * vec4(aPos, 1.0);
TexCoord = aTexCoord;
}
This is the fragment shader:
#version 330 core
out vec4 FragColor;
in vec3 vertexColor; // the input variable from the vertex shader (same name and same type)
in vec2 TexCoord;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform float blend;
void main()
{
//FragColor = texture(texture2, vec2(TexCoord.x, TexCoord.y * -1 ));
FragColor = mix(texture(texture1, TexCoord), texture(texture2, vec2(TexCoord.x, TexCoord.y * -1 )) / 10, blend);
}
That all the code i think its relevant, also, here is the file tree of my project(i'm using Visual Studio btw):
C:.
├───res
│ ├───shaders
│ └───textures
├───src
│ ├───include
│ └───vendor
│ ├───glm
│ │ ├───detail
│ │ ├───ext
│ │ ├───gtc
│ │ ├───gtx
│ │ └───simd
│ ├───imgui
│ └───stb_image
└───x64
├───Debug
│ └───OpenGL-PLSDFMTT.tlog
└───Release
└───OpenGL-PLSDFMTT.tlog
I tried using the debugger of VS for watching what was happening, in the case that it didn't crash the data pointer to the image data was empty (the data was empty), and when it had data it crashed, I tried reviewing my logic, but it all seemed to be ok, that's all I tried (all this in a lapse of 4 hours).

stbi_failure_reason()when something actually fails. The message you're seeing doesn't mean anything if the load succeeded.TEXTURE::Bind()? I guess you bind the textures to different texture image units?shader.Bind()uses the specific texture image units to set thesampleruniforms? Best to also show the shader code.