antispam-bee domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/ruwritingagame/public_html/wp-includes/functions.php on line 6131Chroma keying<\/strong>, \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0446\u0432\u0435\u0442 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 – \u0437\u0435\u043b\u0435\u043d\u044b\u0439:<\/p>\n\n\n\n <\/p>\n\n\n\n \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0437\u0435\u043b\u0435\u043d\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0445 \u0410\u043b\u044c\u0444\u0430-\u043a\u0430\u043d\u0430\u043b\u044b \u0432 \u043d\u043e\u043b\u044c. \u041f\u0440\u0430\u0432\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 GL rasterizer \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 tUV <\/em>\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0440\u044f\u0434\u043e\u043c \u0441 \u0437\u0435\u043b\u0435\u043d\u043e\u0439 \u0437\u043e\u043d\u043e\u0439, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u044c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e<\/em> “\u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c” \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e<\/em> – \u0437\u0435\u043b\u0435\u043d\u044b\u043c<\/strong>. \u041a\u0441\u0442\u0430\u0442\u0438, \u0431\u0435\u0437\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0437\u0435\u043b\u0435\u043d\u043e\u0432\u0430\u0442\u044b\u0435 \u0442\u043e\u043d\u043a\u0438\u0435 \u043b\u0438\u043d\u0438\u0438 \u043f\u043e \u0433\u0440\u0430\u043d\u0438\u0446\u0430\u043c \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0439:<\/p>\n\n\n\n \u0414\u0430, \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e, \u043a\u0430\u043a\u0438\u0435 \u0446\u0432\u0435\u0442\u0430 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0442 \u0432\u0430\u0448\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n\n\n\n \u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/strong>: \u043f\u0440\u0438 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0437\u0435\u043b\u0435\u043d\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0445 \u0410\u043b\u044c\u0444\u0430-\u043a\u0430\u043d\u0430\u043b\u044b \u0432 \u043d\u043e\u043b\u044c, \u0418 \u0442\u0430\u043a\u0436\u0435<\/strong> \u0438\u0445 RGB \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b – \u0432 \u0446\u0432\u0435\u0442\u0430 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u043d\u0435\u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439. \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e:<\/p>\n\n\n\n <\/p>\n\n\n\n \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>:<\/p>\n\n\n\n 1. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c VS, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c\u00a0C:\\CPP\\a997modeler\\p_windows\\p_windows.sln<\/em>.<\/p>\n\n\n\n \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 Texture <\/strong>\u0443 \u043d\u0430\u0441 \u043d\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, applyCkey(..)<\/em>, \u0438 \u043d\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0432 loadTexture(..)<\/em>.<\/p>\n\n\n\n 2. \u0417\u0430\u043c\u0435\u043d\u0438\u043c Texture.h<\/em> \u043a\u043e\u0434 \u043d\u0430:<\/p>\n\n\n <\/p>\n\n\n\n 3. \u0417\u0430\u043c\u0435\u043d\u0438\u043c Texture.<\/em>cpp<\/em> <\/strong>\u043a\u043e\u0434 \u043d\u0430: <\/p>\n\n\n <\/p>\n\n\n\n \u0412 ModelLoader<\/em>-\u0435 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442 chroma key<\/em> \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b. \u041d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c chroma key<\/em> \u0432 model descriptor.<\/p>\n\n\n\n 4. \u0412 \u0422\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435<\/strong> \u043e\u0442\u043a\u0440\u043e\u0435\u043c<\/p>\n\n\n\n C:\\CPP\\a997modeler<\/strong>\\dt\\models\\misc\\marlboro01\\root01.txt<\/strong><\/em><\/p>\n\n\n\n \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u043a\u043e\u0434 \u043d\u0430:<\/p>\n\n\n <\/p>\n\n\n\n <\/p>\n\n\n\n 5. \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u0438 \u0437\u0430\u043f\u0443\u0441\u043a.<\/p>\n\n\n\n \u0422\u0435\u043f\u0435\u0440\u044c – \u0431\u0435\u0437 <\/strong>\u0437\u0435\u043b\u0435\u043d\u044b\u0445 \u043b\u0438\u043d\u0438\u0439!<\/p>\n\n\n\n \u041f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043e \u043d\u0430 \u0410\u043d\u0434\u0440\u043e\u0438\u0434\u0435 \u0442\u043e\u0436\u0435 – \u0432\u0441\u0435 \u043d\u043e\u0440\u043c.<\/p>\n\n\n\n \u041d\u0430\u0448\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0446\u0435\u043b\u044c – \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u0435\u0435 \u0447\u0435\u043c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438!<\/p>\n\n\n\n <\/p>\n","protected":false},"excerpt":{"rendered":" Chroma keying, \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0446\u0432\u0435\u0442 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 – \u0437\u0435\u043b\u0435\u043d\u044b\u0439: \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043d\u0430 \u043f\u0440\u0435\u0434\u043c\u0435\u0442 \u0437\u0435\u043b\u0435\u043d\u044b\u0445 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0438\u0445 \u0410\u043b\u044c\u0444\u0430-\u043a\u0430\u043d\u0430\u043b\u044b \u0432 \u043d\u043e\u043b\u044c. \u041f\u0440\u0430\u0432\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 GL rasterizer \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 tUV \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0440\u044f\u0434\u043e\u043c \u0441 \u0437\u0435\u043b\u0435\u043d\u043e\u0439 \u0437\u043e\u043d\u043e\u0439, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u044c \u043d\u0430 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-884","post","type-post","status-publish","format-standard","hentry","category-cross-platform-3d"],"_links":{"self":[{"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/posts\/884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/comments?post=884"}],"version-history":[{"count":6,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/posts\/884\/revisions"}],"predecessor-version":[{"id":1458,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/posts\/884\/revisions\/1458"}],"wp:attachment":[{"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/media?parent=884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/categories?post=884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/tags?post=884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
\n\n\n\n\n#pragma once\n#include <string>\n#include <vector>\n#include "platform.h"\n\nclass Texture\n{\npublic:\n \/\/texture's individual descriptor:\n unsigned int GLid = -1; \/\/ GL texture id\n int size[2] = { 0,0 }; \/\/ image size\n std::string source; \/\/file name\n \/\/if renderable ?\n unsigned int frameBufferId = 0;\n unsigned int depthBufferId = 0;\n \/\/end of descriptor\n\n \/\/static array (vector) of all loaded textures\n static std::vector<Texture*> textures;\npublic:\n static int loadTexture(std::string filePath, unsigned int ckey, int glRepeatH = GL_MIRRORED_REPEAT, int glRepeatV = GL_MIRRORED_REPEAT);\n static int applyCkey(unsigned char* imgData, int w, int h, unsigned int ckey);\n static int findTexture(std::string filePath);\n static int cleanUp();\n static unsigned int getGLid(int texN) { return textures.at(texN)->GLid; };\n static int saveBMP(std::string filePath, unsigned char* buff, int w, int h, int bytesPerPixel=4);\n static int saveTGA(std::string filePath, unsigned char* buff, int w, int h, int bytesPerPixel=4);\n static int generateTexture(std::string imgID, int w, int h, unsigned char* imgData, int glRepeatH = GL_MIRRORED_REPEAT, int glRepeatV = GL_MIRRORED_REPEAT);\n static int detachRenderBuffer(Texture* pTex);\n static int attachRenderBuffer(int texN, bool zBuffer = false) { return attachRenderBuffer(textures.at(texN), zBuffer); };\n static int attachRenderBuffer(Texture* pTex, bool zBuffer = false);\n static int setRenderToTexture(int texN) { return setRenderToTexture(textures.at(texN)); };\n static int setRenderToTexture(Texture* pTex);\n static int getImageFromTexture(int texN, unsigned char* imgData);\n static int blurRGBA(unsigned char* imgData, int w, int h, int blurLevel);\n};\n\n<\/pre><\/div>\n\n\n
\n\n\n\n\n#include "Texture.h"\n#define STB_IMAGE_IMPLEMENTATION \/\/required by stb_image.h\n#include "stb_image.h"\n#include "platform.h"\n#include "utils.h"\n#include "MyColor.h"\n\n\/\/static array (vector) of all loaded textures\nstd::vector<Texture*> Texture::textures;\n\nint Texture::loadTexture(std::string filePath, unsigned int ckey, int glRepeatH, int glRepeatV) {\n int texN = findTexture(filePath);\n if (texN >= 0)\n return texN;\n \/\/if here - texture wasn't loaded\n \/\/ load an image\n int nrChannels, w, h;\n unsigned char* imgData = stbi_load(filePath.c_str(),\n &w, &h, &nrChannels, 4); \/\/"4"-convert to 4 channels -RGBA\n if (imgData == NULL) {\n mylog("ERROR in Texture::loadTexture loading image %s\\n", filePath.c_str());\n }\n if (ckey != 0)\n applyCkey(imgData, w, h, ckey);\n \/\/ generate texture\n generateTexture(filePath, w, h, imgData, glRepeatH, glRepeatV);\n \/\/ release image data\n stbi_image_free(imgData);\n\n return (textures.size() - 1);\n}\nint Texture::findTexture(std::string filePath) {\n int texturesN = textures.size();\n if (texturesN < 1)\n return -1;\n for (int i = 0; i < texturesN; i++) {\n Texture* pTex = textures.at(i);\n if (pTex->source.compare(filePath) == 0)\n return i;\n }\n return -1;\n}\nint Texture::cleanUp() {\n int texturesN = textures.size();\n if (texturesN < 1)\n return -1;\n \/\/detach all textures\n glActiveTexture(GL_TEXTURE0); \/\/ activate the texture unit first before binding texture\n glBindTexture(GL_TEXTURE_2D, 0);\n glActiveTexture(GL_TEXTURE1);\n glBindTexture(GL_TEXTURE_2D, 0);\n glActiveTexture(GL_TEXTURE2);\n glBindTexture(GL_TEXTURE_2D, 0);\n glActiveTexture(GL_TEXTURE3);\n glBindTexture(GL_TEXTURE_2D, 0);\n \/\/release all textures\n for (int i = 0; i < texturesN; i++) {\n Texture* pTex = textures.at(i);\n detachRenderBuffer(pTex);\n glDeleteTextures(1, (GLuint*)&pTex->GLid);\n pTex->GLid = 0;\n delete pTex;\n }\n textures.clear();\n return 1;\n}\nint Texture::saveBMP(std::string filePath, unsigned char* buff, int w, int h, int bytesPerPixel) {\n std::string fullPath = getFullPath(filePath);\n std::string inAppPath = getInAppPath(fullPath);\n makeDirs(inAppPath);\n FILE* outFile;\n myFopen_s(&outFile, fullPath.c_str(), "wb");\n if (outFile == NULL) {\n mylog("ERROR in Texture::saveBMP: Can't create file %s\\n", filePath.c_str());\n return -1;\n }\n struct {\n char chars2skip[2]; \/\/\n \/\/BMP Header\n char bm[2] = { 0x42, 0x4D }; \/\/\t"BM"\n myUint32 fileSize = 0; \/\/ Size of the BMP file, little-endian\n myUint32 unused = 0;\n myUint32 dataOffset = 0; \/\/ Offset where the pixel array (bitmap data) can be found, little-endian\n \/\/DIB Header\n myUint32 dibHeaderSize = 0; \/\/ Number of bytes in the DIB header, little-endian\n myUint32 imgW = 0; \/\/ Width of the bitmap in pixels, little-endian\n myUint32 imgH = 0; \/\/ Height of the bitmap in pixels, little-endian\n char colorPlainsN[2] = { 1,0 };\n char bitsPerPixel[2] = { 32,0 };\n myUint32 compression = 0; \/\/0-BI_RGB\n myUint32 dataSize = 0; \/\/ Size of the raw bitmap data (including padding), little-endian\n myUint32 printResution[2] = { 2835 ,2835 }; \/\/ Print resolution of the image,\n \/\/72 DPI \u00d7 39.3701 inches per metre yields 2834.6472, little-endian\n myUint32 paletteColors = 0; \/\/ Number of colors in the palette\n myUint32 importantColors = 0; \/\/0 means all colors are important\n } bmpHeader;\n int rowSize = w * bytesPerPixel;\n int rowPadding = (4 - rowSize % 4) % 4;\n int rowSizeWithPadding = rowSize + rowPadding;\n int dataSize = rowSizeWithPadding * h;\n int headerSize = sizeof(bmpHeader) - 2; \/\/-chars2skip\n bmpHeader.fileSize = dataSize + headerSize;\n bmpHeader.dataOffset = headerSize;\n bmpHeader.dibHeaderSize = headerSize - 14; \/\/-BMP Header size\n bmpHeader.imgW = w;\n bmpHeader.imgH = h;\n if (bytesPerPixel != 4)\n bmpHeader.bitsPerPixel[0] = bytesPerPixel * 8;\n bmpHeader.dataSize = dataSize;\n fwrite(&bmpHeader.bm, 1, headerSize, outFile);\n \/\/data, from bottom to top\n unsigned char zero[4] = { 0,0,0,0 };\n unsigned char bgra[4];\n for (int y = h - 1; y >= 0; y--) {\n for (int x = 0; x < w; x++) {\n int pixelOffset = y * rowSize + x * 4;\n bgra[0] = buff[pixelOffset + 2];\n bgra[1] = buff[pixelOffset + 1];\n bgra[2] = buff[pixelOffset + 0];\n bgra[3] = buff[pixelOffset + 3];\n fwrite(bgra, 1, bytesPerPixel, outFile);\n }\n if (rowPadding != 0)\n fwrite(zero, 1, rowPadding, outFile);\n }\n fflush(outFile);\n fclose(outFile);\n\n return 1;\n}\n\nint Texture::saveTGA(std::string filePath, unsigned char* buff, int w, int h, int bytesPerPixel) {\n std::string fullPath = getFullPath(filePath);\n std::string inAppPath = getInAppPath(fullPath);\n makeDirs(inAppPath);\n FILE* outFile;\n myFopen_s(&outFile, fullPath.c_str(), "wb");\n if (outFile == NULL) {\n mylog("ERROR in Texture::saveBMP: Can't create file %s\\n", filePath.c_str());\n return -1;\n }\n unsigned char tgaHeader[18] = { 0,0,2,0,0,0,0,0,0,0,0,0, (unsigned char)(w % 256), (unsigned char)(w \/ 256),\n (unsigned char)(h % 256), (unsigned char)(h \/ 256), (unsigned char)(bytesPerPixel * 8), 0x20 };\n fwrite(tgaHeader, 1, 18, outFile);\n \/\/data\n unsigned char bgra[4];\n for (int i = 0; i < w * h; i++) {\n int pixelOffset = i * 4;\n bgra[0] = buff[pixelOffset + 2];\n bgra[1] = buff[pixelOffset + 1];\n bgra[2] = buff[pixelOffset + 0];\n bgra[3] = buff[pixelOffset + 3];\n fwrite(bgra, 1, bytesPerPixel, outFile);\n }\n fflush(outFile);\n fclose(outFile);\n\n return 1;\n}\nint Texture::generateTexture(std::string imgID, int w, int h, unsigned char* imgData, int glRepeatH, int glRepeatV) {\n \/\/glRepeat options: GL_REPEAT, GL_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT\n if (!imgID.empty()) {\n int texN = findTexture(imgID);\n if (texN >= 0)\n return texN;\n }\n \/\/if here - texture wasn't generated\n \/\/create Texture object\n Texture* pTex = new Texture();\n textures.push_back(pTex);\n pTex->size[0] = w;\n pTex->size[1] = h;\n pTex->source.assign(imgID);\n \/\/ generate texture\n glGenTextures(1, (GLuint*)&pTex->GLid);\n glBindTexture(GL_TEXTURE_2D, pTex->GLid);\n \/\/ set the texture wrapping\/filtering options (on the currently bound texture object)\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glRepeatH);\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glRepeatV);\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);\/\/ GL_LINEAR); \/\/\n glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\n \/\/ attach image data (if provided)\n if (imgData != NULL) {\n glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pTex->size[0], pTex->size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData);\n glGenerateMipmap(GL_TEXTURE_2D);\n }\n return (textures.size() - 1);\n}\nint Texture::detachRenderBuffer(Texture* pTex) {\n if (pTex->frameBufferId == 0)\n return 0;\n if (pTex->depthBufferId > 0) {\n glDeleteRenderbuffers(1, (GLuint*)&pTex->depthBufferId);\n pTex->depthBufferId = 0;\n }\n glDeleteFramebuffers(1, (GLuint*)&pTex->frameBufferId);\n pTex->frameBufferId = 0;\n return 1;\n}\n\nint Texture::attachRenderBuffer(Texture* pTex, bool zBuffer) {\n if (pTex->frameBufferId > 0)\n return 0; \/\/attached already\n \/\/generate frame buffer\n glGenFramebuffers(1, (GLuint*)&pTex->frameBufferId);\n if (zBuffer) {\n \/\/generate depth buffer\n glGenRenderbuffers(1, (GLuint*)&pTex->depthBufferId);\n \/\/ create render buffer and bind 16-bit depth buffer\n glBindRenderbuffer(GL_RENDERBUFFER, pTex->depthBufferId);\n glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, pTex->size[0], pTex->size[1]);\n glBindRenderbuffer(GL_RENDERBUFFER, 0); \/\/release\n }\n return 1;\n}\nint Texture::setRenderToTexture(Texture* pTex) {\n if (pTex->frameBufferId == 0) {\n mylog("ERROR in Texture::setRenderToTexture: %s not renderable", pTex->source.c_str());\n return -1;\n }\n \/\/ Bind the framebuffer\n glBindFramebuffer(GL_FRAMEBUFFER, pTex->frameBufferId);\n \/\/ specify texture as color attachment\n glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pTex->GLid, 0);\n \/\/ attach render buffer as depth buffer\n if (pTex->depthBufferId > 0) {\n glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, pTex->depthBufferId);\n glClear(GL_DEPTH_BUFFER_BIT);\n }\n \/\/ check status\n int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);\n if (status != GL_FRAMEBUFFER_COMPLETE) {\n std::string str;\n if (status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)\n str.assign("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");\n else if (status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)\n str.assign("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");\n else if (status == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)\n str.assign("GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE");\n else if (status == GL_FRAMEBUFFER_UNSUPPORTED)\n str.assign("GL_FRAMEBUFFER_UNSUPPORTED");\n else\n str.assign("hz");\n mylog("Modeler.setRenderToTextureBind to texture %s failed: %s\\n", pTex->source.c_str(), str.c_str());\n return -1;\n }\n glViewport(0, 0, pTex->size[0], pTex->size[1]);\n return 1;\n}\nint Texture::getImageFromTexture(int texN, unsigned char* imgData) {\n Texture* pTex = textures.at(texN);\n glBindTexture(GL_TEXTURE_2D, pTex->GLid);\n glBindFramebuffer(GL_FRAMEBUFFER, pTex->frameBufferId);\n\n glReadPixels(0, 0, pTex->size[0], pTex->size[1], GL_RGBA, GL_UNSIGNED_BYTE, imgData);\n return 1;\n}\nint Texture::blurRGBA(unsigned char* imgData, int w0, int h0, int blurLevel) {\n unsigned char* imgTemp = new unsigned char[w0 * h0 * 4];\n int w00 = blurLevel * 2 + 1;\n for (int y0 = 0; y0 < h0; y0++) {\n int y1 = y0 - blurLevel;\n int h1 = w00;\n if (y1 < 0) {\n int d = -y1;\n y1 += d;\n h1 -= d;\n }\n else if (y1 > h0 - w00) {\n int d = y1 - (h0 - w00);\n h1 -= d;\n }\n for (int x0 = 0; x0 < w0; x0++) {\n int x1 = x0 - blurLevel;\n int w1 = w00;\n if (x1 < 0) {\n int d = -x1;\n x1 += d;\n w1 -= d;\n }\n else if (x1 > w0 - w00) {\n int d = x1 - (w0 - w00);\n w1 -= d;\n }\n int sum[4] = { 0,0,0,0 };\n for (int y = y1; y < y1 + h1; y++) {\n for (int x = x1; x < x1 + w1; x++) {\n int idx = (y * w0 + x) * 4;\n for (int ch = 0; ch < 4; ch++)\n sum[ch] += imgData[idx + ch];\n }\n }\n int n = w1 * h1;\n int idx = (y0 * w0 + x0) * 4;\n for (int ch = 0; ch < 4; ch++)\n imgTemp[idx + ch] = (unsigned char)(sum[ch] \/ n);\n }\n }\n memcpy(imgData, imgTemp, w0 * h0 * 4);\n delete[] imgTemp;\n return 1;\n}\nint Texture::applyCkey(unsigned char* imgData, int w0, int h0, unsigned int ckey) {\n if (ckey == 0)\n return 0;\n MyColor transparentPixel;\n transparentPixel.setRGBA(127, 127, 127, 0);\n unsigned int transparentValue = transparentPixel.getUint32();\n unsigned int* pIntData = (unsigned int*)imgData;\n int dataIntsN = w0 * h0;\n int transparentPixelsN = 0;\n for (int i = 0; i < dataIntsN; i++) {\n if (pIntData[i] != ckey)\n continue;\n \/\/here - have ckey pixel\n transparentPixelsN++;\n pIntData[i] = transparentValue;\n }\n if (transparentPixelsN == 0)\n return 0;\n \/\/re-calculate transparent RGBs\n int dataCharsN = dataIntsN * 4;\n \/\/duplicate image\n unsigned char* imgTemp = new unsigned char[dataCharsN];\n memcpy(imgTemp, imgData, dataCharsN);\n \/\/scan\n int blurLevel = 1;\n int w00 = blurLevel * 2 + 1;\n for (int y0 = 0; y0 < h0; y0++) {\n int y1 = y0 - blurLevel;\n int h1 = w00;\n if (y1 < 0) {\n int d = -y1;\n y1 += d;\n h1 -= d;\n }\n else if (y1 > h0 - w00) {\n int d = y1 - (h0 - w00);\n h1 -= d;\n }\n for (int x0 = 0; x0 < w0; x0++) {\n if (imgData[(y0 * w0 + x0) * 4 + 3] != 0) \/\/check current pixel's alpha component\n continue; \/\/non-transparent pixel\n int x1 = x0 - blurLevel;\n int w1 = w00;\n if (x1 < 0) {\n int d = -x1;\n x1 += d;\n w1 -= d;\n }\n else if (x1 > w0 - w00) {\n int d = x1 - (w0 - w00);\n w1 -= d;\n }\n int sum[3] = { 0,0,0 };\n int opaquePixelsN = 0;\n for (int y = y1; y < y1 + h1; y++) {\n for (int x = x1; x < x1 + w1; x++) {\n int idx = (y * w0 + x) * 4;\n if (imgTemp[idx + 3] == 0) \/\/check alpha channel\n continue; \/\/transparent pixel\n opaquePixelsN++;\n for (int ch = 0; ch < 3; ch++)\n sum[ch] += imgTemp[idx + ch];\n }\n }\n if (opaquePixelsN == 0)\n continue;\n int idx = (y0 * w0 + x0) * 4;\n for (int ch = 0; ch < 3; ch++)\n imgData[idx + ch] = (unsigned char)(sum[ch] \/ opaquePixelsN);\n }\n }\n delete[] imgTemp;\n saveTGA("\/dt\/02.tga", imgData, w0, h0, 3);\n return 1;\n}\n\n<\/pre><\/div>\n\n\n
\n\n\n\n\n<texture_as="tx0" src="marlboro03small.png" ckey="#00ff00"\/>\n<mt_type="phong" uTex0_use="tx0" \/>\n<vs="box_tank" whl="53,83,21" ext=1 sectR=1 \/>\n<a="front v,back v" xywh="2,1,323,495"\/>\n<a="right all" xywh="327,1,128,495"\/>\n<a="left all" xywh="457,1,128,495"\/>\n<a="top" xywh="588,1,323,133"\/>\n<a="bottom" xywh="587,136,324,134"\/>\n\n<\/pre><\/div>\n\n\n
\n\n\n\n
\n\n\n\n
\n\n\n\n