38 LOGE(
"Texture initialing error");
43 FILE* file = fopen(file_path,
"rb");
46 LOGE(
"fp not loaded: %s", strerror(errno));
50 fseek(file, 8, SEEK_CUR);
53 png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL,
NULL,
NULL);
54 png_infop info_ptr = png_create_info_struct(png_ptr);
56 png_init_io(png_ptr, file);
57 png_set_sig_bytes(png_ptr, 8);
58 png_read_info(png_ptr, info_ptr);
67 png_bytep* row_pointers =
new png_bytep[
height_];
69 row_pointers[i] = (png_bytep)(byte_data_ + i * row);
71 png_read_image(png_ptr, row_pointers);
72 png_destroy_read_struct(&png_ptr, &info_ptr, 0);
76 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
77 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
78 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
79 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
81 if (color_type_ == PNG_COLOR_TYPE_RGBA) {
82 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
width_, height_, 0, GL_RGBA,
83 GL_UNSIGNED_BYTE, byte_data_);
85 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
width_, height_, 0, GL_RGB,
86 GL_UNSIGNED_BYTE, byte_data_);
89 glBindTexture(GL_TEXTURE_2D, 0);
92 delete[] row_pointers;
GLM_FUNC_DECL genType::row_type row(genType const &m, length_t const &index)
GLuint GetTextureID() const
bool LoadFromPNG(const char *file_path)
Texture(const char *file_path)
void CheckGlError(const char *operation)
static int RoundUpPowerOfTwo(int w)
static const int kMaxExponentiation