I really hope someone can help with this because I have been stuck with this,what could be simple problem, for days.
I am fairly new to c++ ,completely self taught and only 14 so I’ve probably made some bad errors. I wan’t to be able to load lots of different PNG textures like this.
GLuint * Player_Current_Texture;
GLuint Vietcong_Texture = loadPNG("Data/Vietcong.png");
GLuint Vietcong_Firing_Texture = loadPNG("Data/Vietcong_Firing.png");
so that I can use them like this:
Draw_Texture(48,*Player_Current_Texture);
my current method of loading PNGs is like this
GLuint loadPNG(const char* filename)
{
GLuint texture;
vector<unsigned char> buffer, image;
LodePNG::loadFile(buffer, filename);
LodePNG::Decoder decoder;
decoder.decode(image, buffer.empty() ? 0 : &buffer[0], (unsigned)buffer.size());
if(decoder.hasError()) PostQuitMessage(0);
unsigned char* pixels=(unsigned char*)malloc(decoder.getWidth()*decoder.getHeight()*decoder.getChannels());
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
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_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
return texture;
}
and my method of drawing them is like so:
void Draw_Texture(float size, GLuint texture)
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture( GL_TEXTURE_2D, texture );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
float X = size/2;
float O = -size/2;
glColor3f(1,1,1);
glBegin(GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex2d(O,O);
glTexCoord2d(1.0,0.0); glVertex2d(X,O);
glTexCoord2d(1.0,1.0); glVertex2d(X,X);
glTexCoord2d(0.0,1.0); glVertex2d(O,X);
glEnd();
}
However this just displays a white rectangle. Any help would be much appreciated as it would be very nice to get this problem out of the way. feel free too ask for more code if needs be.
thanks Rowan.