diff options
| author | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-09-17 22:17:48 +0700 |
|---|---|---|
| committer | Nguyễn Gia Phong <mcsinyx@disroot.org> | 2021-09-17 22:17:48 +0700 |
| commit | b1e4fa0d290c3f484054b61f8d2875cae33e099d (patch) | |
| tree | a35307ae1ce237386da728623ad7211dac8b7513 /src/Textures.cpp | |
| parent | 1084e3f994eeedaf54cc8c9785f75ddb1727191e (diff) | |
| download | blackshades-b1e4fa0d290c3f484054b61f8d2875cae33e099d.tar.gz | |
Convert texture loading code to Zig
LodePNG replaces stb because complicated headers don't play nice with Zig. Textures are now loaded from installed path instead of CWD too.
Diffstat (limited to 'src/Textures.cpp')
| -rw-r--r-- | src/Textures.cpp | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/src/Textures.cpp b/src/Textures.cpp deleted file mode 100644 index 78808a1..0000000 --- a/src/Textures.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// Texture loader implementation -// Copyright (C) 2021 Nguyễn Gia Phong -// -// This file is part of Black Shades. -// -// Black Shades is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Black Shades is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Black Shades. If not, see <https://www.gnu.org/licenses/>. - -#include <stdio.h> - -#define STB_IMAGE_IMPLEMENTATION -#include <stb/stb_image.h> -#include <GL/glu.h> - -#include "Textures.h" - -GLuint loadTexture(const char* filename_) -{ - // TODO: get rid of the :Data: thing - char filename[1024]; - strcpy(filename, filename_+1); - while (true) { - char *c = strchr(filename, ':'); - if (!c) break; - *c = '/'; - } - - int req_format = STBI_rgb_alpha; - int width, height, orig_format; - unsigned char* data = stbi_load(filename, &width, &height, - &orig_format, req_format); - if (data == nullptr) { - fprintf(stderr, "Loading image failed: %s\n", - stbi_failure_reason()); - return 0; - } - - GLuint tex = 0; - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - GLint internal_format; - GLenum pixel_format; - if (req_format == STBI_rgb) { - internal_format = 3; - pixel_format = GL_RGB; - } else { // STBI_rgb_alpha (RGBA) - internal_format = 4; - pixel_format = GL_RGBA; - } - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, - pixel_format, GL_UNSIGNED_BYTE, data); - gluBuild2DMipmaps(GL_TEXTURE_2D, internal_format, width, height, - pixel_format, GL_UNSIGNED_BYTE, data); - - stbi_image_free(data); - return tex; -} |
