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 6131\u0417\u0434\u0435\u0441\u044c \u044f \u0445\u043e\u0447\u0443 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u043b\u044b\u0439 \u0448\u0443\u043c \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435: \u0441 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0438 \u0441 \u0440\u0430\u0437\u043c\u044b\u0432\u043a\u043e\u0439 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. \u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n\n\n\n
\u042d\u0442\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435Texture<\/em>.<\/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 C:\\CPP\\a997modeler<\/em>\\p_windows\\p_windows.sln<\/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.cpp<\/em> \u043a\u043e\u0434 \u043d\u0430:<\/p>\n\n\n <\/p>\n\n\n\n \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439.<\/p>\n\n\n\n \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0440\u0435\u043d\u0434\u0440\u0438\u0442 3 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e \u0440\u0430\u0437\u043c\u044b\u0432\u043a\u0438:<\/p>\n\n\n <\/p>\n\n\n\n 4. \u041e\u0442\u043a\u0440\u043e\u0435\u043c TheGame.cpp<\/em> \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e TheGame::run()<\/strong><\/em> \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439.<\/p>\n\n\n\n \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438:<\/p>\n\n\n\n a) \u0421\u0442\u0440\u043e\u043a\u0430 13: \u0441\u043e\u0437\u0434\u0430\u0435\u043c 64×64 RGBA buffer.<\/p>\n\n\n\n b) \u0421\u0442\u0440\u043e\u043a\u0438 14-19: \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0431\u0443\u0444\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u044b\u043c \u0444\u043e\u043d\u043e\u043c (\u043a\u0430\u043a \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0433\u043b\u0430\u0432\u0435). \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 4-\u0445 \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a<\/p>\n\n\n\n \u0421\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435:<\/p>\n\n\n\n c) \u0421\u0442\u0440\u043e\u043a\u0438 21-23: \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443, render buffer \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c rendering \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 render buffer\/texture.<\/p>\n\n\n\n d) \u0421\u0442\u0440\u043e\u043a\u0438 29-49: \u0441\u043e\u0437\u0434\u0430\u0435\u043c flat 1×1 \u043a\u0432\u0430\u0434\u0440\u0430\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0431\u0443\u0434\u0435\u043c \u0440\u0435\u043d\u0434\u0440\u0438\u0442\u044c \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443.<\/p>\n\n\n\n e) \u0421\u0442\u0440\u043e\u043a\u0430 55: \u0414\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 6×6.<\/p>\n\n\n\n f) \u0421\u0442\u0440\u043e\u043a\u0438 58-72: \u0420\u0435\u043d\u0434\u0440\u0438\u043c \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u043a\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432 \u0432 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b.<\/p>\n\n\n\n g) \u0421\u0442\u0440\u043e\u043a\u0430 73: \u0427\u0438\u0442\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0438\u0437 GPU:<\/p>\n\n\n\n \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a<\/p>\n\n\n\n h) \u0421\u0442\u0440\u043e\u043a\u0430 74: \u0420\u0430\u0437\u043c\u044b\u0432\u043a\u0430 (Blur):<\/p>\n\n\n\n \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a<\/p>\n\n\n\n i) \u0421\u0442\u0440\u043e\u043a\u0430 78: \u0417\u0430\u043f\u0438\u0441\u044c \u0444\u0430\u0439\u043b\u0430.<\/p>\n\n\n\n j) \u0421\u0442\u0440\u043e\u043a\u0438 \u044177 \u043f\u043e 126: \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0440\u0430\u0437\u043c\u044b\u0432\u043a\u0438 2<\/p>\n\n\n\n \u0438 1<\/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. \u041d\u043e\u0432\u044b\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b \u0432<\/p>\n\n\n\n C:\\CPP\\a997modeler\\p_windows\\Debug\\dt\\out<\/strong><\/em><\/p>\n\n\n\n 6. \u0412 Windows File Explorer<\/strong>-\u0435 \u0441\u043a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0438\u0437 <\/p>\n\n\n\n C:\\CPP\\a997modeler\\p_windows\\Debug\\dt\\out<\/strong><\/em> <\/p>\n\n\n\n \u0432\u00a0C:\\CPP\\engine\\dt\\common\\img\\whitenoise<\/em><\/p>\n\n\n\n \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0442\u0430\u043c 5 BMP \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n\n\n\n 7. \u041a\u0430\u0442\u0430\u043b\u043e\u0433 C:\\CPP\\a997modeler\\p_windows\\Debug<\/strong>\\dt<\/strong><\/em> \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c.<\/p>\n\n\n\n \u0421\u0430\u043c\u0438-\u043f\u043e-\u0441\u0435\u0431\u0435 \u044d\u0442\u0438 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b, \u0430 \u0432\u043e\u0442 \u0438\u0445 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u044b\u0435 \u043a\u0430\u043d\u0430\u043b\u044b – \u0432\u0435\u0441\u044c\u043c\u0430. \u0418 \u0441\u043a\u043e\u0440\u043e \u043e\u043d\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f.<\/p>\n\n\n\n <\/p>\n\n\n\n <\/p>\n","protected":false},"excerpt":{"rendered":" \u0417\u0434\u0435\u0441\u044c \u044f \u0445\u043e\u0447\u0443 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u043b\u044b\u0439 \u0448\u0443\u043c \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435: \u0441 \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0438 \u0441 \u0440\u0430\u0437\u043c\u044b\u0432\u043a\u043e\u0439 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. \u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438: \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 (\u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0433\u043b\u0430\u0432\u0435) \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0433\u043e GL \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443 \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0435 renderable (\u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0435\u0435 \u0441 render buffer-\u043e\u043c) \u041d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c GL \u0440\u0435\u043d\u0434\u0435\u0440 \u0432 \u043d\u043e\u0432\u044b\u0439 render buffer \u041d\u0430\u0440\u0435\u043d\u0434\u0440\u0438\u0442\u044c \u0442\u0443\u0434\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u044b\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0442\u043e\u0447\u0435\u043a […]<\/p>\n","protected":false},"author":1,"featured_media":1225,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-772","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cross-platform-3d"],"_links":{"self":[{"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/posts\/772","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=772"}],"version-history":[{"count":8,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/posts\/772\/revisions"}],"predecessor-version":[{"id":1414,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/posts\/772\/revisions\/1414"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/media\/1225"}],"wp:attachment":[{"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/media?parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/categories?post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/writingagame.ru\/index.php\/wp-json\/wp\/v2\/tags?post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\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;\n\npublic:\n static int loadTexture(std::string filePath, int glRepeatH = GL_MIRRORED_REPEAT, int glRepeatV = GL_MIRRORED_REPEAT);\n static int findTexture(std::string filePath);\n static int cleanUp();\n static unsigned int getGLid(int texN) { return textures.at(texN)->GLid; };\n\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\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\n\/\/static array (vector) of all loaded textures\nstd::vector<Texture*> Texture::textures;\n\nint Texture::loadTexture(std::string filePath, 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 \/\/ 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}\n\n<\/pre><\/div>\n\n\n
\n\n\n\n\nint TheGame::run() {\n \/*\n getReady();\n while (!bExitGame) {\n drawFrame();\n }\n cleanUp();\n *\/\n Shader::loadShaders();\n\n int wh[2] = { 64,64 };\n int bytesPerPixel = 4;\n unsigned char* imgData = new unsigned char[wh[1] * wh[0] * 4];\n for (int y = 0; y < wh[1]; y++)\n for (int x = 0; x < wh[0]; x++) {\n int idx = (y * wh[1] + x) * bytesPerPixel;\n for (int i = 0; i < 4; i++)\n imgData[idx + i] = getRandom(0, 1) * 255;\n }\n \/\/background generated, generate texture:\n int texN = Texture::generateTexture("", wh[0], wh[1], imgData);\n Texture::attachRenderBuffer(texN);\n Texture::setRenderToTexture(texN);\n\n mat4x4 mProjection, mMVP;\n mat4x4_ortho(mProjection, -wh[0] \/ 2, wh[0] \/ 2, -wh[1] \/ 2, wh[1] \/ 2, 1.f, -1.f);\n unsigned char RGBA[4];\n\n \/\/create a simple 1x1 ucolor square\n GameSubj* pSquare = new GameSubj();\n gameSubjs.push_back(pSquare);\n ModelBuilder* pMB = new ModelBuilder();\n pMB->useSubjN(gameSubjs.size() - 1);\n \/\/define VirtualShape\n VirtualShape vs;\n vs.setShapeType("box");\n v3set(vs.whl, 1, 1, 0);\n Material mt;\n \/\/define material - flat red\n mt.shaderN = Shader::spN_flat_ucolor;\n mt.primitiveType = GL_TRIANGLES;\n mt.uColor.setRGBA(255, 0, 0, 255); \/\/red\n pMB->useMaterial(&mt);\n pMB->buildBoxFace(pMB, "front", &vs);\n pMB->buildDrawJobs(gameSubjs);\n delete pMB;\n \/\/copy mt to pAltMaterial\n pSquare->pAltMaterial = new Material(mt);\n \/\/--end of pSquare\n DrawJob* pDJ = DrawJob::drawJobs.back();\n\n \/\/-------------blurLevel 3\n int blurLevel = 3;\n std::string fileName = "wn64_blur3";\n int dotSize = blurLevel * 2;\n v3set(pSquare->scale, dotSize, dotSize, 1);\n\n for (int i = 0; i < 500; i++) {\n pSquare->ownCoords.pos[0] = getRandom(-wh[0] \/ 2, wh[0] \/ 2);\n pSquare->ownCoords.pos[1] = getRandom(-wh[1] \/ 2, wh[1] \/ 2);\n pSquare->ownCoords.setDegrees(0,0,getRandom(0,90));\n for (int ch = 0; ch < 4; ch++)\n RGBA[ch] = (unsigned char)(getRandom(0, 1) * 255);\n pSquare->pAltMaterial->uColor.setRGBA(RGBA);\n\n \/\/prepare subject for rendering\n pSquare->buildModelMatrix(pSquare);\n \/\/build MVP matrix for given subject\n mat4x4_mul(mMVP, mProjection, pSquare->ownModelMatrix);\n \/\/render subject\n pDJ->execute((float*)mMVP, NULL, NULL, NULL, pSquare->pAltMaterial);\n }\n Texture::getImageFromTexture(texN, imgData);\n Texture::blurRGBA(imgData, wh[0], wh[1], blurLevel);\n\n Texture::saveBMP("\/dt\/out\/" + fileName + ".bmp", imgData, wh[0], wh[1]);\n \/\/-------------blurLevel 2\n blurLevel = 2;\n fileName = "wn64_blur2";\n dotSize = blurLevel * 2;\n v3set(pSquare->scale, dotSize, dotSize, 1);\n\n for (int i = 0; i < 500; i++) {\n pSquare->ownCoords.pos[0] = getRandom(-wh[0] \/ 2, wh[0] \/ 2);\n pSquare->ownCoords.pos[1] = getRandom(-wh[1] \/ 2, wh[1] \/ 2);\n pSquare->ownCoords.setDegrees(0, 0, getRandom(0, 90));\n for (int ch = 0; ch < 4; ch++)\n RGBA[ch] = (unsigned char)(getRandom(0, 1) * 255);\n pSquare->pAltMaterial->uColor.setRGBA(RGBA);\n\n \/\/prepare subject for rendering\n pSquare->buildModelMatrix(pSquare);\n \/\/build MVP matrix for given subject\n mat4x4_mul(mMVP, mProjection, pSquare->ownModelMatrix);\n \/\/render subject\n pDJ->execute((float*)mMVP, NULL, NULL, NULL, pSquare->pAltMaterial);\n }\n Texture::getImageFromTexture(texN, imgData);\n Texture::blurRGBA(imgData, wh[0], wh[1], blurLevel);\n\n Texture::saveBMP("\/dt\/out\/" + fileName + ".bmp", imgData, wh[0], wh[1]);\n \/\/-------------blurLevel 1\n blurLevel = 1;\n fileName = "wn64_blur1";\n dotSize = blurLevel * 2;\n v3set(pSquare->scale, dotSize, dotSize, 1);\n\n for (int i = 0; i < 500; i++) {\n pSquare->ownCoords.pos[0] = getRandom(-wh[0] \/ 2, wh[0] \/ 2);\n pSquare->ownCoords.pos[1] = getRandom(-wh[1] \/ 2, wh[1] \/ 2);\n pSquare->ownCoords.setDegrees(0, 0, getRandom(0, 90));\n for (int ch = 0; ch < 4; ch++)\n RGBA[ch] = (unsigned char)(getRandom(0, 1) * 255);\n pSquare->pAltMaterial->uColor.setRGBA(RGBA);\n\n \/\/prepare subject for rendering\n pSquare->buildModelMatrix(pSquare);\n \/\/build MVP matrix for given subject\n mat4x4_mul(mMVP, mProjection, pSquare->ownModelMatrix);\n \/\/render subject\n pDJ->execute((float*)mMVP, NULL, NULL, NULL, pSquare->pAltMaterial);\n }\n Texture::getImageFromTexture(texN, imgData);\n Texture::blurRGBA(imgData, wh[0], wh[1], blurLevel);\n\n Texture::saveBMP("\/dt\/out\/" + fileName + ".bmp", imgData, wh[0], wh[1]);\n\n delete[] imgData;\n mylog("Ready\\n");\n\n return 1;\n}\n\n<\/pre><\/div>\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
<\/p>\n\n\n\n
\n\n\n\n
\n\n\n\n
\n\n\n\n
\n\n\n\n
\n\n\n\n