/
Zamar_Terrier
/
TigorEngineWeb2
Обзор
Документация
Войти
/
Zamar_Terrier
/
TigorEngineWeb2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/e_texture.c
167 строк
6 KB
Ilia Zamaruev
wasi delete and make local mini stb lib
17 фев 2026, 16:41
17 фев 2026, 16:41
f5863af
Код
Авторство
О чём код?
#include "e_texture.h" #include "e_texture_variables.h" //#define STB_IMAGE_IMPLEMENTATION //#include "stb_image.h" #include "malloc.h" #include "gameObject2D.h" extern TEngine engine; int TextureFindTexture(const char *path) { if(path == NULL) return 0; engine_buffered_image *buff_images = engine.DataR.e_var_images; char *temp; for(int i=0;i < engine.DataR.e_var_num_images;i++) { temp = buff_images[i].path; if(!strcmp(temp, path)){ return i; } } return -1; } void TextureLoad2DImage(GameObject *go, const char *filePath){ GameObject2D *go2D = (GameObject2D *) go; engine_buffered_image *images = engine.DataR.e_var_images; int img_indx = TextureFindTexture(filePath); if(img_indx > -1) { go2D->image->texture_id = images[img_indx].buffer; go2D->image->imgWidth = images[img_indx].texture.image_data.texWidth; go2D->image->imgHeight = images[img_indx].texture.image_data.texHeight; return; } if(engine.DataR.e_var_num_images > MAX_IMAGES - 2) { #ifndef NDEBUG consoleLog("Too much images!\n"); #endif go2D->image->texture_id = images[MAX_IMAGES - 1].buffer; go2D->image->imgWidth = images[MAX_IMAGES - 1].texture.image_data.texWidth; go2D->image->imgHeight = images[MAX_IMAGES - 1].texture.image_data.texHeight; return; } int len = strlen(filePath); memset(images[engine.DataR.e_var_num_images].path, 0, 256); memcpy(images[engine.DataR.e_var_num_images].path, filePath, len); int width, height, nrChannels; char *pixels = NULL;// stbi_load(filePath, &width, &height, &nrChannels, 0); go2D->image->imgWidth = width; go2D->image->imgHeight = height; images[engine.DataR.e_var_num_images].texture.image_data.texWidth = width; images[engine.DataR.e_var_num_images].texture.image_data.texHeight = height; // Determine GL texture format int format = -1; if (nrChannels == 3) format = GL_RGB; else if (nrChannels == 4) format = GL_RGBA; #ifndef NDEBUG //consoleLog ("Image dimensions %dx%d, %d bits per pixel\n", width, height, nrChannels * 8); #endif glGenTextures(1, &go2D->image->texture_id); glBindTexture(GL_TEXTURE_2D, go2D->image->texture_id); // set the texture wrapping parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // set texture filtering parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, pixels); //stbi_image_free(pixels); glBindTexture(GL_TEXTURE_2D, 0); images[engine.DataR.e_var_num_images].buffer = go2D->image->texture_id; engine.DataR.e_var_num_images ++; } void TextureLoad3DImage(GameObject *go, const char *filePath){ GameObject3D *go3D = (GameObject3D *) go; engine_buffered_image *images = engine.DataR.e_var_images; int img_indx = TextureFindTexture(filePath); if(img_indx > -1) { go3D->image->texture_id = images[img_indx].buffer; go3D->image->imgWidth = images[img_indx].texture.image_data.texWidth; go3D->image->imgHeight = images[img_indx].texture.image_data.texHeight; return; } if(engine.DataR.e_var_num_images > MAX_IMAGES - 2) { #ifndef NDEBUG consoleLog("Too much images!\n"); #endif go3D->image->texture_id = images[MAX_IMAGES - 1].buffer; go3D->image->imgWidth = images[MAX_IMAGES - 1].texture.image_data.texWidth; go3D->image->imgHeight = images[MAX_IMAGES - 1].texture.image_data.texHeight; return; } int len = strlen(filePath); memset(images[engine.DataR.e_var_num_images].path, 0, 256); memcpy(images[engine.DataR.e_var_num_images].path, filePath, len); int width, height, nrChannels; char *pixels = NULL;// stbi_load(filePath, &width, &height, &nrChannels, 0); go3D->image->imgWidth = width; go3D->image->imgHeight = height; images[engine.DataR.e_var_num_images].texture.image_data.texWidth = width; images[engine.DataR.e_var_num_images].texture.image_data.texHeight = height; // Determine GL texture format int format = -1; if (nrChannels == 3) format = GL_RGB; else if (nrChannels == 4) format = GL_RGBA; #ifndef NDEBUG //consoleLog("Image dimensions %dx%d, %d bits per pixel\n", width, height, nrChannels * 8); #endif glGenTextures(1, &go3D->image->texture_id); glBindTexture(GL_TEXTURE_2D, go3D->image->texture_id); // set the texture wrapping parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // set texture wrapping to GL_REPEAT (default wrapping method) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // set texture filtering parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, pixels); //stbi_image_free(pixels); glBindTexture(GL_TEXTURE_2D, 0); images[engine.DataR.e_var_num_images].buffer = go3D->image->texture_id; engine.DataR.e_var_num_images ++; }