{"id":391479,"date":"2024-06-29T09:50:52","date_gmt":"2024-06-29T09:50:52","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=391479"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T09:50:52","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=391479","title":{"rendered":"<span>\u0423\u0440\u043e\u043a\u0438 \u043f\u043e SDL 2: \u0423\u0440\u043e\u043a 8 \u2014 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u0439 \u0444\u043e\u043d<\/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>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440: \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u043e\u0431\u0440\u0430\u043b\u0441\u044f \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c &#8212; \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u0442 \u043d\u0438\u0433\u0434\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u0421\\\u0421++, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u0431\u0440\u043e\u0441\u0430\u044e\u0442 \u044d\u0442\u043e \u0434\u0435\u043b\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0436\u0430\u0441.<\/p>\n<p><strong>\u0421\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0433\u043e \u0444\u043e\u043d\u0430 \u0434\u043b\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043a\u0440\u0430\u0442\u043a\u043e:<\/strong> <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/140\/0c6\/5f6\/1400c65f630409c0a428726a313acf5f.png\" width=\"2048\" height=\"2011\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/140\/0c6\/5f6\/1400c65f630409c0a428726a313acf5f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>SDL \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0447\u0435\u0440\u0435\u0437 SDL_SetColorKey \u0443\u0431\u0440\u0430\u0442\u044c \u0444\u043e\u043d \u0443 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e\u0435 \u043d\u0430\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041a\u043e\u0434, \u043f\u043e\u0435\u0445\u0430\u043b\u0438:<\/p>\n<pre><code class=\"cpp\">#include&lt;SDL2\/SDL.h>  int main(void)  {      SDL_Window* window; \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u043a\u043d\u043e   SDL_Renderer* gRenderer; \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439.      SDL_Surface *backgroundImage; \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0435\u0432   SDL_Surface *humanImage;      SDL_Texture *backGroundTex;  \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b   SDL_Texture *humanTex;      SDL_Init(SDL_INIT_VIDEO); \/\/\u044f\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0435\u043e      window = SDL_CreateWindow( \"transparentImage\", 0,0,640,480,SDL_WINDOW_OPENGL); \/\/\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u043a\u043d\u0430   gRenderer = SDL_CreateRenderer(window, -1, 0); \/\/\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0440\u0435\u043d\u0434\u0435\u0440\u0430 \u043a \u043e\u043a\u043d\u0443      SDL_SetRenderDrawColor(gRenderer, 0, 0, 50, 255); \/\/\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0446\u0432\u0435\u0442\u0430 red green blue bright   SDL_RenderClear(gRenderer);\/\/\u043e\u0447\u0438\u0441\u0442\u043a\u0430 \u044d\u043a\u0440\u0430\u043d\u0430   SDL_RenderPresent(gRenderer);\/\/\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043a\u0440\u0430\u043d\u0430      SDL_Delay(1000); \/\/\u043f\u0435\u0440\u0435\u0434\u044b\u0448\u043a\u0430 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443      backgroundImage = SDL_LoadBMP(\"hw.bmp\");\/\/\u043f\u043e\u0434\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f   humanImage = SDL_LoadBMP(\"foo.bmp\");   SDL_SetColorKey( humanImage, SDL_TRUE, SDL_MapRGB( humanImage->format, 0, 0xFF, 0xFF ) ); \/\/\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f   backGroundTex = SDL_CreateTextureFromSurface(gRenderer,backgroundImage); \/\/\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b      SDL_RenderCopy(gRenderer,backGroundTex,NULL,NULL); \/\/\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435     \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b \u0432 \u0440\u0435\u043d\u0434\u0435\u0440   SDL_RenderPresent(gRenderer);       SDL_Delay(1000);   humanTex = SDL_CreateTextureFromSurface(gRenderer,humanImage);    \/*\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f*\/   SDL_Rect topLeftViewport;   topLeftViewport.x = 220;   topLeftViewport.y = 220;   topLeftViewport.h = 300;   topLeftViewport.w = 250;   SDL_RenderSetViewport( gRenderer,&amp;topLeftViewport);    SDL_RenderCopy(gRenderer, humanTex,NULL,NULL);   SDL_RenderPresent(gRenderer);      SDL_Delay(3000);   SDL_DestroyWindow(window); \/\/\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u043a\u043d\u0430   SDL_Quit(); \/\/\u0432\u044b\u0445\u043e\u0434  return 0; }  <\/code><\/pre>\n<p><a href=\"https:\/\/www.dropbox.com\/sh\/63no8x0jtx08e26\/AACJb8EBfmfmHc2fkcue2mBFa?dl=0\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/users\/LLEMOON\/posts\/\" rel=\"noopener noreferrer nofollow\">\u2190 \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0443\u0440\u043e\u043a<\/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\/579526\/\"> https:\/\/habr.com\/ru\/articles\/579526\/<\/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>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440: \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u043e\u0431\u0440\u0430\u043b\u0441\u044f \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c &#8212; \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u0442 \u043d\u0438\u0433\u0434\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0434\u043b\u044f \u0421\\\u0421++, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u0431\u0440\u043e\u0441\u0430\u044e\u0442 \u044d\u0442\u043e \u0434\u0435\u043b\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0436\u0430\u0441.<\/p>\n<p><strong>\u0421\u043c\u044b\u0441\u043b \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0433\u043e \u0444\u043e\u043d\u0430 \u0434\u043b\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043a\u0440\u0430\u0442\u043a\u043e:<\/strong> <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>SDL \u0434\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0447\u0435\u0440\u0435\u0437 SDL_SetColorKey \u0443\u0431\u0440\u0430\u0442\u044c \u0444\u043e\u043d \u0443 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e\u0435 \u043d\u0430\u043c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>\u041a\u043e\u0434, \u043f\u043e\u0435\u0445\u0430\u043b\u0438:<\/p>\n<pre><code class=\"cpp\">#include&lt;SDL2\/SDL.h>  int main(void)  {      SDL_Window* window; \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u043a\u043d\u043e   SDL_Renderer* gRenderer; \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u043d\u0434\u0435\u0440\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439.      SDL_Surface *backgroundImage; \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0435\u0432   SDL_Surface *humanImage;      SDL_Texture *backGroundTex;  \/\/\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b   SDL_Texture *humanTex;      SDL_Init(SDL_INIT_VIDEO); \/\/\u044f\u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0435\u043e      window = SDL_CreateWindow( \"transparentImage\", 0,0,640,480,SDL_WINDOW_OPENGL); \/\/\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u043a\u043d\u0430   gRenderer = SDL_CreateRenderer(window, -1, 0); \/\/\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0440\u0435\u043d\u0434\u0435\u0440\u0430 \u043a \u043e\u043a\u043d\u0443      SDL_SetRenderDrawColor(gRenderer, 0, 0, 50, 255); \/\/\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0446\u0432\u0435\u0442\u0430 red green blue bright   SDL_RenderClear(gRenderer);\/\/\u043e\u0447\u0438\u0441\u0442\u043a\u0430 \u044d\u043a\u0440\u0430\u043d\u0430   SDL_RenderPresent(gRenderer);\/\/\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u044d\u043a\u0440\u0430\u043d\u0430      SDL_Delay(1000); \/\/\u043f\u0435\u0440\u0435\u0434\u044b\u0448\u043a\u0430 1 \u0441\u0435\u043a\u0443\u043d\u0434\u0443      backgroundImage = SDL_LoadBMP(\"hw.bmp\");\/\/\u043f\u043e\u0434\u0433\u0440\u0443\u0437\u043a\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f   humanImage = SDL_LoadBMP(\"foo.bmp\");   SDL_SetColorKey( humanImage, SDL_TRUE, SDL_MapRGB( humanImage->format, 0, 0xFF, 0xFF ) ); \/\/\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f   backGroundTex = SDL_CreateTextureFromSurface(gRenderer,backgroundImage); \/\/\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b      SDL_RenderCopy(gRenderer,backGroundTex,NULL,NULL); \/\/\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435     \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b \u0432 \u0440\u0435\u043d\u0434\u0435\u0440   SDL_RenderPresent(gRenderer);       SDL_Delay(1000);   humanTex = SDL_CreateTextureFromSurface(gRenderer,humanImage);    \/*\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f*\/   SDL_Rect topLeftViewport;   topLeftViewport.x = 220;   topLeftViewport.y = 220;   topLeftViewport.h = 300;   topLeftViewport.w = 250;   SDL_RenderSetViewport( gRenderer,&amp;topLeftViewport);    SDL_RenderCopy(gRenderer, humanTex,NULL,NULL);   SDL_RenderPresent(gRenderer);      SDL_Delay(3000);   SDL_DestroyWindow(window); \/\/\u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u043a\u043d\u0430   SDL_Quit(); \/\/\u0432\u044b\u0445\u043e\u0434  return 0; }  <\/code><\/pre>\n<p><a href=\"https:\/\/www.dropbox.com\/sh\/63no8x0jtx08e26\/AACJb8EBfmfmHc2fkcue2mBFa?dl=0\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/a><\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/users\/LLEMOON\/posts\/\" rel=\"noopener noreferrer nofollow\">\u2190 \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0443\u0440\u043e\u043a<\/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\/579526\/\"> https:\/\/habr.com\/ru\/articles\/579526\/<\/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-391479","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/391479","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=391479"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/391479\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=391479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=391479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=391479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}