{"id":384589,"date":"2024-06-29T05:35:55","date_gmt":"2024-06-29T05:35:55","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=384589"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T05:35:55","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=384589","title":{"rendered":"<span>\u0423\u0440\u043e\u043a\u0438 \u043f\u043e SDL 2: \u0423\u0440\u043e\u043a 15 \u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0438 \u0422\u0438\u043b\u043b\u0438\u043d\u0433<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u0438\u0437 \u043c\u0438\u043d\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0436\u0435 \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043a\u043e\u043d, \u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u043f\u0435\u0440\u0435\u0434.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c06\/334\/3f3\/c063343f32fb55992d9e669beeb919c4.png\" width=\"637\" height=\"478\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c06\/334\/3f3\/c063343f32fb55992d9e669beeb919c4.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043a\u043e\u0434\u0443:<\/p>\n<pre><code class=\"cpp\">static int TestThread(void *ptr) {    SDL_Window *gWindow = SDL_CreateWindow(\"gamesBond\",0,0,300,300,SDL_WINDOW_SHOWN); ;   SDL_Surface *imageThreadSurface = SDL_LoadBMP(\"hw.bmp\");     int cnt;   SDL_Surface *windowSurface = SDL_GetWindowSurface(gWindow); SDL_BlitSurface(imageThreadSurface,NULL, windowSurface,NULL); SDL_UpdateWindowSurface( gWindow );     for (cnt = 0; cnt &lt; 10; ++cnt) {         printf(\"Thread counter: %d\\n\", cnt);         SDL_Delay(50);     }        SDL_Delay(4000);     SDL_FreeSurface(windowSurface);     SDL_FreeSurface(imageThreadSurface);     SDL_DestroyWindow(gWindow);     return cnt; } <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d86\/718\/a8f\/d86718a8fbeab18ca6dd47339ca55c42.png\" width=\"303\" height=\"319\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d86\/718\/a8f\/d86718a8fbeab18ca6dd47339ca55c42.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448\u0438\u043c \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c, \u043e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u043a\u043d\u043e(<strong>gWindow<\/strong>), \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432(<strong>imageThreadSurface<\/strong>), \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c <strong>windowSurface <\/strong>\u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043e\u043a\u043d\u0443, \u0438 \u0432 \u043d\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0447\u0438\u0441\u043b\u0430 \u043e\u0442 1 \u0434\u043e 9, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c 4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, <br \/>\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043e\u043a\u043d\u043e.<\/p>\n<pre><code class=\"cpp\">void writeMap(int *i,SDL_Renderer* gRenderer, SDL_Surface* mapSurface) {  int yMap = 0;int xMap = 0;  int xSize = 80; int ySize = 80;  SDL_Rect coubPositionRect = {xMap,yMap,xSize,ySize};  SDL_Rect coubColorRect = {xMap,yMap,xSize,ySize };   SDL_Texture* mapTexture = SDL_CreateTextureFromSurface(gRenderer,mapSurface);  SDL_RenderClear;   while (xMap &lt; 640)   {     if ( *i == REDSQUARE ) {                coubColorRect.x = 0;        coubColorRect.y = 0;     }else if ( *i == GREENSQUARE ) {                    coubColorRect.y = 80;          coubColorRect.x = 0;     }else if ( *i == BLUESQUARE ) {                         coubColorRect.y = 160;         coubColorRect.x = 0;     }else if ( *i == BLACKLEFTMID ) {                  coubColorRect.y = 80;         coubColorRect.x = xSize;     }else if ( *i == BLACKLEFTTOP ) {          coubColorRect.y = 0;         coubColorRect.x = 80;      }else if ( *i == BLACKLEFTBOT ) {          coubColorRect.x = 80;         coubColorRect.y = 160;     }else if (*i == BLACKRIGHTTOP) {                  coubColorRect.x = 240;         coubColorRect.y = 0;         }else if (*i == BLACKRIGHTMID) {          coubColorRect.x = 240;         coubColorRect.y = 80;     }else if (*i == BLACKRIGHTBOT) {          coubColorRect.x = 240;         coubColorRect.y = 160;     }      coubPositionRect.x = xMap;     coubPositionRect.y = yMap;     SDL_RenderCopy(gRenderer,mapTexture,&amp;coubColorRect,&amp;coubPositionRect);      yMap+=ySize;     if (yMap>=480) {     xMap+=xSize;         yMap = 0;     }      i++;   }    SDL_RenderPresent(gRenderer);   return; } <\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/84d\/671\/19f\/84d67119f9e19a5688e6175635f36306.png\" width=\"160\" height=\"120\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/84d\/671\/19f\/84d67119f9e19a5688e6175635f36306.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 0 \u0434\u043e 8, \u043c\u044b \u043e\u0442\u0440\u0438\u0441\u0443\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0443, \u0447\u0435\u0440\u0435\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435, \u0445\u043e\u0442\u044c \u043e\u043d\u0430 \u0438 \u0431\u043e\u043b\u044c\u0448\u0430\u044f, \u0432 \u043d\u0435\u0439 \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0447\u0438\u0441\u043b\u043e\u043c \u0438 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u043c \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435, \u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<pre><code class=\"cpp\">int main(void) {    int mWidth = 640, mHeight = 480;     SDL_Init(SDL_INIT_VIDEO);   SDL_Window* window = SDL_CreateWindow(\"tilling\",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,mWidth,mHeight,SDL_WINDOW_SHOWN);   SDL_Renderer* gRenderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);    SDL_Surface* imageSurface = IMG_Load(\"tiles.png\");   SDL_Texture* imageTexture = SDL_CreateTextureFromSurface(gRenderer,imageSurface);   SDL_Rect imageRect = {0,0,80,80};    SDL_Event e;   SDL_RenderCopy(gRenderer,imageTexture,&amp;imageRect,&amp;imageRect);   SDL_RenderPresent(gRenderer);    int quit = 0;   int *k; k =(int*)calloc(50,4);   int threadReturnValue;    readData(k); <\/code><\/pre>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e \u0437\u0430\u0434\u0430\u0435\u043c \u043e\u043a\u043d\u043e, \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043c\u0438\u043d\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 <strong>k.<\/strong><\/p>\n<p>\u0418 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0438\u0444\u0440\u0430\u043c\u0438 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 r<strong>eadData(k)<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043e\u043c \u0446\u0432\u0435\u0442\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u043d\u0430 \u043a\u0430\u0440\u0442\u0435.<\/p>\n<pre><code class=\"cpp\"> writeMap( k, gRenderer, imageSurface);   free(k);<\/code><\/pre>\n<p>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0432 \u043e\u043a\u043d\u0435(<strong>window<\/strong>). \u043d\u0430\u0448\u0443 \u043a\u0430\u0440\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044e(<strong>writeMap<\/strong>)<br \/>\u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <strong>k<\/strong><\/p>\n<pre><code class=\"cpp\">  SDL_Thread *thread;   thread = SDL_CreateThread(TestThread,\"testMultiThread\",(void *)NULL);    SDL_WaitThread(thread, &amp;threadReturnValue);<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0442\u043e\u043a, SDL_CreateThread \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043f\u0435\u0440\u0432\u0430\u044f \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f(TestThread), \u0432\u0442\u043e\u0440\u0430\u044f \u044d\u0442\u043e \u0438\u043c\u044f \u043f\u043e\u0442\u043e\u043a\u0430, \u0438 \u0442\u0440\u0435\u0442\u044c\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e NULL.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u043e\u0442\u043e\u043a \u0447\u0435\u0440\u0435\u0437 <strong>SDL_WaitThread<\/strong> \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>threadReturnValue<\/strong><\/p>\n<pre><code class=\"cpp\">    SDL_RaiseWindow(window);    SDL_ShowWindow(window);      SDL_RenderPresent(gRenderer);   untilPressKey (quit, e); <\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>SDL_RaiseWindow<\/strong> \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u043a\u043d\u043e \u043f\u043e\u0432\u0435\u0440\u0445 \u0432\u0441\u0435\u0445 \u043e\u043a\u043e\u043d, \u0432\u0442\u043e\u0440\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>SDL_ShowWindow<\/strong>, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u043a\u043d\u043e, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435  \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <strong>untilPressKey:<\/strong><\/p>\n<pre><code>  SDL_FreeSurface(imageSurface);   SDL_DestroyTexture(imageTexture);    SDL_RenderClear(gRenderer);   SDL_DestroyWindow(window);   SDL_Quit(); <\/code><\/pre>\n<p><a href=\"https:\/\/habr.com\/ru\/users\/LLEMOON\/posts\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0443\u0440\u043e\u043a\u0438 1-7<\/a><br \/><a href=\"https:\/\/habr.com\/ru\/users\/scorpka\/posts\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0443\u0440\u043e\u043a\u0438 > 7<\/a><\/p>\n<p><a href=\"https:\/\/www.dropbox.com\/sh\/q7zp5pe1lw3s7jv\/AADppyJpDb32g53Hw0IZ6UFva?dl=0\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0444\u0430\u0439\u043b\u044b<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/584846\/\"> https:\/\/habr.com\/ru\/articles\/584846\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u044d\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 \u0443\u0440\u043e\u0432\u043d\u0438 \u0438\u0437 \u043c\u0438\u043d\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0436\u0435 \u043d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043a\u043e\u043d, \u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u043f\u0435\u0440\u0435\u0434.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043a\u043e\u0434\u0443:<\/p>\n<pre><code class=\"cpp\">static int TestThread(void *ptr) {    SDL_Window *gWindow = SDL_CreateWindow(\"gamesBond\",0,0,300,300,SDL_WINDOW_SHOWN); ;   SDL_Surface *imageThreadSurface = SDL_LoadBMP(\"hw.bmp\");     int cnt;   SDL_Surface *windowSurface = SDL_GetWindowSurface(gWindow); SDL_BlitSurface(imageThreadSurface,NULL, windowSurface,NULL); SDL_UpdateWindowSurface( gWindow );     for (cnt = 0; cnt &lt; 10; ++cnt) {         printf(\"Thread counter: %d\\n\", cnt);         SDL_Delay(50);     }        SDL_Delay(4000);     SDL_FreeSurface(windowSurface);     SDL_FreeSurface(imageThreadSurface);     SDL_DestroyWindow(gWindow);     return cnt; } <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448\u0438\u043c \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u043c, \u043e\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u043a\u043d\u043e(<strong>gWindow<\/strong>), \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432(<strong>imageThreadSurface<\/strong>), \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c <strong>windowSurface <\/strong>\u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043e\u043a\u043d\u0443, \u0438 \u0432 \u043d\u0435\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435. <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0447\u0438\u0441\u043b\u0430 \u043e\u0442 1 \u0434\u043e 9, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c 4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, <br \/>\u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043e\u043a\u043d\u043e.<\/p>\n<pre><code class=\"cpp\">void writeMap(int *i,SDL_Renderer* gRenderer, SDL_Surface* mapSurface) {  int yMap = 0;int xMap = 0;  int xSize = 80; int ySize = 80;  SDL_Rect coubPositionRect = {xMap,yMap,xSize,ySize};  SDL_Rect coubColorRect = {xMap,yMap,xSize,ySize };   SDL_Texture* mapTexture = SDL_CreateTextureFromSurface(gRenderer,mapSurface);  SDL_RenderClear;   while (xMap &lt; 640)   {     if ( *i == REDSQUARE ) {                coubColorRect.x = 0;        coubColorRect.y = 0;     }else if ( *i == GREENSQUARE ) {                    coubColorRect.y = 80;          coubColorRect.x = 0;     }else if ( *i == BLUESQUARE ) {                         coubColorRect.y = 160;         coubColorRect.x = 0;     }else if ( *i == BLACKLEFTMID ) {                  coubColorRect.y = 80;         coubColorRect.x = xSize;     }else if ( *i == BLACKLEFTTOP ) {          coubColorRect.y = 0;         coubColorRect.x = 80;      }else if ( *i == BLACKLEFTBOT ) {          coubColorRect.x = 80;         coubColorRect.y = 160;     }else if (*i == BLACKRIGHTTOP) {                  coubColorRect.x = 240;         coubColorRect.y = 0;         }else if (*i == BLACKRIGHTMID) {          coubColorRect.x = 240;         coubColorRect.y = 80;     }else if (*i == BLACKRIGHTBOT) {          coubColorRect.x = 240;         coubColorRect.y = 160;     }      coubPositionRect.x = xMap;     coubPositionRect.y = yMap;     SDL_RenderCopy(gRenderer,mapTexture,&amp;coubColorRect,&amp;coubPositionRect);      yMap+=ySize;     if (yMap>=480) {     xMap+=xSize;         yMap = 0;     }      i++;   }    SDL_RenderPresent(gRenderer);   return; } <\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0447\u0438\u0441\u0435\u043b \u043e\u0442 0 \u0434\u043e 8, \u043c\u044b \u043e\u0442\u0440\u0438\u0441\u0443\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0443, \u0447\u0435\u0440\u0435\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432\u044b\u0448\u0435, \u0445\u043e\u0442\u044c \u043e\u043d\u0430 \u0438 \u0431\u043e\u043b\u044c\u0448\u0430\u044f, \u0432 \u043d\u0435\u0439 \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432, \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0447\u0438\u0441\u043b\u043e\u043c \u0438 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u043c \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435, \u0438 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<pre><code class=\"cpp\">int main(void) {    int mWidth = 640, mHeight = 480;     SDL_Init(SDL_INIT_VIDEO);   SDL_Window* window = SDL_CreateWindow(\"tilling\",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,mWidth,mHeight,SDL_WINDOW_SHOWN);   SDL_Renderer* gRenderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);    SDL_Surface* imageSurface = IMG_Load(\"tiles.png\");   SDL_Texture* imageTexture = SDL_CreateTextureFromSurface(gRenderer,imageSurface);   SDL_Rect imageRect = {0,0,80,80};    SDL_Event e;   SDL_RenderCopy(gRenderer,imageTexture,&amp;imageRect,&amp;imageRect);   SDL_RenderPresent(gRenderer);    int quit = 0;   int *k; k =(int*)calloc(50,4);   int threadReturnValue;    readData(k); <\/code><\/pre>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e \u0437\u0430\u0434\u0430\u0435\u043c \u043e\u043a\u043d\u043e, \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043c\u0438\u043d\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 <strong>k.<\/strong><\/p>\n<p>\u0418 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0446\u0438\u0444\u0440\u0430\u043c\u0438 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 r<strong>eadData(k)<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043e\u043c \u0446\u0432\u0435\u0442\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u043d\u0430 \u043a\u0430\u0440\u0442\u0435.<\/p>\n<pre><code class=\"cpp\"> writeMap( k, gRenderer, imageSurface);   free(k);<\/code><\/pre>\n<p>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0432 \u043e\u043a\u043d\u0435(<strong>window<\/strong>). \u043d\u0430\u0448\u0443 \u043a\u0430\u0440\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044e(<strong>writeMap<\/strong>)<br \/>\u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <strong>k<\/strong><\/p>\n<pre><code class=\"cpp\">  SDL_Thread *thread;   thread = SDL_CreateThread(TestThread,\"testMultiThread\",(void *)NULL);    SDL_WaitThread(thread, &amp;threadReturnValue);<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0442\u043e\u043a, SDL_CreateThread \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043f\u0435\u0440\u0432\u0430\u044f \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f(TestThread), \u0432\u0442\u043e\u0440\u0430\u044f \u044d\u0442\u043e \u0438\u043c\u044f \u043f\u043e\u0442\u043e\u043a\u0430, \u0438 \u0442\u0440\u0435\u0442\u044c\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e NULL.<\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u043e\u0442\u043e\u043a \u0447\u0435\u0440\u0435\u0437 <strong>SDL_WaitThread<\/strong> \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>threadReturnValue<\/strong><\/p>\n<pre><code class=\"cpp\">    SDL_RaiseWindow(window);    SDL_ShowWindow(window);      SDL_RenderPresent(gRenderer);   untilPressKey (quit, e); <\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>SDL_RaiseWindow<\/strong> \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043e\u043a\u043d\u043e \u043f\u043e\u0432\u0435\u0440\u0445 \u0432\u0441\u0435\u0445 \u043e\u043a\u043e\u043d, \u0432\u0442\u043e\u0440\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>SDL_ShowWindow<\/strong>, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u043a\u043d\u043e, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435  \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <strong>untilPressKey:<\/strong><\/p>\n<pre><code>  SDL_FreeSurface(imageSurface);   SDL_DestroyTexture(imageTexture);    SDL_RenderClear(gRenderer);   SDL_DestroyWindow(window);   SDL_Quit(); <\/code><\/pre>\n<p><a href=\"https:\/\/habr.com\/ru\/users\/LLEMOON\/posts\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0443\u0440\u043e\u043a\u0438 1-7<\/a><br \/><a href=\"https:\/\/habr.com\/ru\/users\/scorpka\/posts\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0443\u0440\u043e\u043a\u0438 > 7<\/a><\/p>\n<p><a href=\"https:\/\/www.dropbox.com\/sh\/q7zp5pe1lw3s7jv\/AADppyJpDb32g53Hw0IZ6UFva?dl=0\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0444\u0430\u0439\u043b\u044b<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/584846\/\"> https:\/\/habr.com\/ru\/articles\/584846\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-384589","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/384589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=384589"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/384589\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=384589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=384589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=384589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}