//lodepng용 추가 함수 static void PrintLog(LodePNG::Decoder &decoder) { if(decoder.hasError()) { std::cout << "error " << decoder.getError() << ": " << LodePNG_error_text(decoder.getError()) << std::endl; } else { std::cout << "\n" << "w: " << decoder.getWidth() << "\n" << "h: " << decoder.getHeight() << "\n" << "bitDepth: " << decoder.getInfoPng().color.bitDepth << "\n" << "bpp: " << decoder.getBpp() << "\n" << "colorChannels: " << decoder.getChannels() << "\n" << "paletteSize: " << decoder.getInfoPng().color.palettesize / 4 << "\n" << "colorType: " << decoder.getInfoPng().color.colorType << "\n" << "compressionMethod: " << decoder.getInfoPng().compressionMethod << "\n" << "filterMethod: " << decoder.getInfoPng().filterMethod << "\n" << "interlaceMethod: " << decoder.getInfoPng().interlaceMethod << "\n"; for(size_t i = 0; i < decoder.getInfoPng().text.num; i++) { std::cout << decoder.getInfoPng().text.keys[i] << ": " << decoder.getInfoPng().text.strings[i] << "\n"; } } }
static GLuint LoadTexture(const char* filename) { unsigned char* buffer; unsigned char* image; size_t buffersize, imagesize; LodePNG_Decoder decoder; LodePNG_loadFile(&buffer, &buffersize, filename); LodePNG_Decoder_init(&decoder); decoder.infoRaw.color.colorType = 0; decoder.infoRaw.color.bitDepth = 8; LodePNG_Decoder_decode(&decoder, &image, &imagesize, buffer, buffersize); pezCheck(!decoder.error, "error %u: %s\n", decoder.error, LodePNG_error_text(decoder.error)); int bpp = LodePNG_InfoColor_getBpp(&decoder.infoPng.color); int bitDepth = decoder.infoPng.color.bitDepth; int colorChannels = LodePNG_InfoColor_getChannels(&decoder.infoPng.color); pezCheck(bpp == 8 && bitDepth == 8 && colorChannels == 1); int w = decoder.infoPng.width; int h = decoder.infoPng.height; pezPrintString("Loaded %s (%d x %d) bufferSize = %d, imageSize = %d\n", filename, w, h, buffersize, imagesize); GLuint handle; glGenTextures(1, &handle); glBindTexture(GL_TEXTURE_2D, handle); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, image); free(buffer); free(image); LodePNG_Decoder_cleanup(&decoder); pezCheck(OpenGLError); return handle; }