bool kit::Texture::saveToFile(const std::string&filename) { // Fetch data from GPU unsigned char * data = new unsigned char[(m_resolution.x * m_resolution.y) * 4]; #ifndef KIT_SHITTY_INTEL glGetTextureImage(m_glHandle, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLsizei)(((m_resolution.x * m_resolution.y) * 4) * sizeof(unsigned char)), &data[0]); #else bind(); glGetTexImage(m_type, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]); #endif stbi_write_set_flip_vertically_on_save(1); // Write data to disk if(stbi_write_tga(filename.c_str(), m_resolution.x, m_resolution.y, 4, (void*)data) == 0) { KIT_ERR("Failed to write image to file") delete[] data; return false; } delete[] data; return true; }
bool kit::Texture::saveToFile(std::string filename) { // Fetch data from GPU unsigned char * data = new unsigned char[(this->m_resolution.x * this->m_resolution.y) * 4]; KIT_GL(glGetTextureImage(this->m_glHandle, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLsizei)(((this->m_resolution.x * this->m_resolution.y) * 4) * sizeof(unsigned char)), &data[0])); stbi_write_set_flip_vertically_on_save(1); // Write data to disk if(stbi_write_tga(filename.c_str(), this->m_resolution.x, this->m_resolution.y, 4, (void*)data) == 0) { KIT_ERR("Failed to write image to file") delete[] data; return false; } delete[] data; return true; }