LodePNG Function

closed account (2NywAqkS)
After many failed attempts of trying to make a function to load PNG textures like:

GLuint Texture_1 = LoadTexture("Texture 1.png");

so that I could them like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, Texture_1 );
	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();

I came across the LodePNG texture loader. I really have no idea how to use it to make a function like the one I explained above. I vaguely know you decode the png files like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
LodePNG_Decoder decoder;
	LodePNG_Decoder_init(&decoder);
	unsigned char* buffer;
	unsigned int* image;
	size_t buffersize, imagesize;

	LodePNG_loadFile(&buffer, &buffersize, filename); /*load the image file with given filename*/

	LodePNG_decode(&decoder, image, &imagesize, buffer, buffersize);

	int width = decoder.infoPng.width; int height = decoder.infoPng.height;

	glGenTextures(1, (GLuint *)&texture);
	glBindTexture(GL_TEXTURE_2D, texture);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);


but even this has a few errors. How would I go about loading the png files and making them into textures. If it helps here http://lodev.org/lodepng/ is the LodePNG website. Any help is much appreciated.

Thanks Rowan.
Topic archived. No new replies allowed.