MCPcopy Create free account
hub / github.com/cococry/leif / lf_create_texture_from_image_data

Function lf_create_texture_from_image_data

leif.c:2189–2212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2187}
2188
2189void lf_create_texture_from_image_data(LfTextureFiltering filter, uint32_t* id, int32_t width, int32_t height, int32_t channels, unsigned char* data) {
2190 GLenum internal_format = (channels == 4) ? GL_RGBA8 : GL_RGB8;
2191 GLenum data_format = (channels == 4) ? GL_RGBA : GL_RGB;
2192 glGenTextures(1, id);
2193 glBindTexture(GL_TEXTURE_2D, *id);
2194
2195 // Set texture parameters
2196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
2197 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
2198 switch(filter) {
2199 case LF_TEX_FILTER_LINEAR:
2200 glTextureParameteri(*id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2201 glTextureParameteri(*id, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
2202 break;
2203 case LF_TEX_FILTER_NEAREST:
2204 glTextureParameteri(*id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2205 glTextureParameteri(*id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2206 break;
2207 }
2208
2209 // Load texture data
2210 glTexImage2D(GL_TEXTURE_2D, 0, data_format, width, height, 0, data_format, GL_UNSIGNED_BYTE, data);
2211 glGenerateMipmap(GL_TEXTURE_2D);
2212}
2213
2214void lf_free_texture(LfTexture* tex) {
2215 glDeleteTextures(1, &tex->id);

Calls

no outgoing calls

Tested by

no test coverage detected