39 LOGE(
"Texture initialing error");
44 bool Texture::LoadFromPNG(
const char* file_path) {
45 FILE*
file = fopen(file_path,
"rb");
48 LOGE(
"fp not loaded: %s", strerror(errno));
52 fseek(file, 8, SEEK_CUR);
55 png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
56 png_infop info_ptr = png_create_info_struct(png_ptr);
58 png_init_io(png_ptr, file);
59 png_set_sig_bytes(png_ptr, 8);
60 png_read_info(png_ptr, info_ptr);
69 png_bytep* row_pointers =
new png_bytep[height_];
70 for (
uint i = 0;
i < height_; ++
i) {
73 png_read_image(png_ptr, row_pointers);
74 png_destroy_read_struct(&png_ptr, &info_ptr, 0);
78 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
84 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_, height_, 0, GL_RGBA,
87 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width_, height_, 0, GL_RGB,
91 glBindTexture(GL_TEXTURE_2D, 0);
94 delete[] row_pointers;