| 1931 | } |
| 1932 | |
| 1933 | LfTexture lf_load_texture_resized(const char* filepath, bool flip, LfTextureFiltering filter, uint32_t w, uint32_t h) { |
| 1934 | LfTexture tex; |
| 1935 | int32_t width, height, channels; |
| 1936 | stbi_uc* image_data = stbi_load(filepath, &width, &height, &channels, 0); |
| 1937 | |
| 1938 | unsigned char* downscaled_image = (unsigned char*)malloc(sizeof(unsigned char) * w * h * channels); |
| 1939 | |
| 1940 | // Resize the original image to the downscaled size |
| 1941 | stbir_resize_uint8_linear(image_data, width, height, 0, downscaled_image, w, h, 0,(stbir_pixel_layout)channels); |
| 1942 | |
| 1943 | glCreateTextures(GL_TEXTURE_2D, 1, &tex.id); |
| 1944 | glBindTexture(GL_TEXTURE_2D, tex.id); |
| 1945 | |
| 1946 | switch(filter) { |
| 1947 | case LF_TEX_FILTER_LINEAR: |
| 1948 | glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1949 | glTextureParameteri(tex.id, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 1950 | break; |
| 1951 | case LF_TEX_FILTER_NEAREST: |
| 1952 | glTextureParameteri(tex.id, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1953 | glTextureParameteri(tex.id, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1954 | break; |
| 1955 | } |
| 1956 | |
| 1957 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 1958 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 1959 | |
| 1960 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, downscaled_image); |
| 1961 | glGenerateMipmap(GL_TEXTURE_2D); |
| 1962 | |
| 1963 | stbi_image_free(image_data); |
| 1964 | free(downscaled_image); |
| 1965 | |
| 1966 | tex.width = width; |
| 1967 | tex.height = height; |
| 1968 | |
| 1969 | return tex; |
| 1970 | |
| 1971 | } |
| 1972 | |
| 1973 | LfTexture lf_load_texture_resized_factor(const char* filepath, bool flip, LfTextureFiltering filter, float wfactor, float hfactor) { |
| 1974 | // Loading the texture into memory with stb_image |
nothing calls this directly
no outgoing calls
no test coverage detected