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);
|