| 1895 | } |
| 1896 | |
| 1897 | LfTexture lf_load_texture(const char* filepath, bool flip, LfTextureFiltering filter) { |
| 1898 | LfTexture tex; |
| 1899 | int width, height, channels; |
| 1900 | unsigned char* image = stbi_load(filepath, &width, &height, &channels, STBI_rgb_alpha); |
| 1901 | if (!image) { |
| 1902 | LF_ERROR("Failed to load texture at '%s'.", filepath); |
| 1903 | return tex; |
| 1904 | } |
| 1905 | |
| 1906 | glGenTextures(1, &tex.id); |
| 1907 | glBindTexture(GL_TEXTURE_2D, tex.id); |
| 1908 | |
| 1909 | // Set texture parameters |
| 1910 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 1911 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 1912 | switch(filter) { |
| 1913 | case LF_TEX_FILTER_LINEAR: |
| 1914 | glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1915 | glTextureParameteri(tex.id, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 1916 | break; |
| 1917 | case LF_TEX_FILTER_NEAREST: |
| 1918 | glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1919 | glTextureParameteri(tex.id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1920 | break; |
| 1921 | } |
| 1922 | |
| 1923 | // Load texture data |
| 1924 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); |
| 1925 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1926 | stbi_image_free(image); // Free image data |
| 1927 | // |
| 1928 | tex.width = width; |
| 1929 | tex.height = height; |
| 1930 | return tex; |
| 1931 | } |
| 1932 | |
| 1933 | LfTexture lf_load_texture_resized(const char* filepath, bool flip, LfTextureFiltering filter, uint32_t w, uint32_t h) { |
| 1934 | LfTexture tex; |
no outgoing calls
no test coverage detected