So I wrote a helper function that just loads a png file disc and loads it into an OpenGL shader.
This all works fine and well until I try to load multiple textures. The problem that I run into is the fact it seems to overrite all previous textures each time. I have no idea why this is happening. If the code I am providing isn't enough, the full source is posted here
Here is the loadTexture function (resides in Helper.cpp)
GLuint loadTexture(const GLchar* filepath, GLuint& width, GLuint& height)
{
// image vector.
vector<GLubyte> img;
// decodes the image to img
decode(img, filepath, width, height);
// if the image is empty return
if (img.size() == 0)
{
std::cout << "Bad Image" << std::endl;
system("pause");
return 0;
}
// return value
GLuint ret;
// gen textures
glGenTextures(1, &ret);
// bind the ret to GL_TEXTURE_2D so everyting using GL_TEXTURE_2D referrs to ret
glBindTexture(GL_TEXTURE_2D, ret);
// set parameters. Current filtering techunique is GL_LINEAR http://www.arcsynthesis.org/gltut/Texturing/Tut15%20Magnification.html
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// copy the data to the texture associated with ret.
// format is RGBA internally and externally, and the size is unsigned char, which is unsigned byte
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &img[0]);
return ret;
}
The decode method saves the image to img and stores the width and height to width and height respectively.
If there is something that I am missing please tell me.
Thanks for any help I can get!