{"id":278051,"date":"2016-04-11T17:40:01","date_gmt":"2016-04-11T13:40:01","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=278051"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=278051","title":{"rendered":"\u041e\u0431\u043b\u0435\u0433\u0447\u0430\u0435\u043c \u0441\u0435\u0431\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 SDL2"},"content":{"rendered":"\n<p>\u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438\u0433\u0440\u044b \u043d\u0430 SDL \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0435\u043a \u2014 \u043e\u0447\u0435\u043d\u044c \u043c\u0443\u0442\u043e\u0440\u043d\u043e\u0435 \u0434\u0435\u043b\u043e.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0449\u0435\u0439 \u0436\u0438\u0437\u043d\u044c.<\/li>\n<li>\u0411\u0440\u043e\u0441\u0430\u0435\u043c SDL \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<a name=\"habracut\"><\/a><\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041c\u044b \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0442\u0440\u0443\u0434\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u2014 \u21161.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0448\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Core-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043e\u043a\u043d\u043e\u043c, \u0440\u0435\u043d\u0434\u0435\u0440\u043e\u043c, \u0438.\u0442.\u0434.<\/li>\n<li>\u041e\u0431\u043b\u0435\u0433\u0447\u0451\u043d\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u043e \u0441\u043f\u0440\u0430\u0439\u0442\u0430\u043c\u0438 \u2014 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0430, \u043f\u043e\u0432\u043e\u0440\u043e\u0442, \u043e\u0431\u0440\u0435\u0437 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b.<\/li>\n<li>\u0420\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0451\u043c! \u0421\u043e\u0437\u0434\u0430\u0451\u043c header \u0438 source \u0444\u0430\u0439\u043b\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li>ITopping.h<\/li>\n<li>ITopping.cpp<\/li>\n<\/ul>\n<p>  <\/p>\n<p>(\u041d\u0430\u0448\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043c\u044b \u043d\u0430\u0437\u043e\u0432\u0451\u043c ITopping)<\/p>\n<p>  <\/p>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u043c Core-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 (\u043e\u043a\u043d\u043e+\u0440\u0435\u043d\u0434\u0435\u0440):<\/p>\n<p>  <\/p>\n<p><strong>ITopping.h<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#ifndef ITOPPING_H_ #define ITOPPING_H_  #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;vector&gt; #include &lt;SDL2\/SDL.h&gt; #include &lt;SDL2\/SDL_image.h&gt; #include &lt;SDL2\/SDL_mixer.h&gt; #include &lt;SDL2\/SDL_ttf.h&gt;  typedef struct{      SDL_Window* window;     SDL_Renderer* render;  } ITCore;  \/\/...  #endif \/* ITOPPING_H_ *\/ <\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Core-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b:<\/p>\n<p>  <\/p>\n<p><strong>ITopping.h<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">ITCore initCore(char* title,int screenx,int screeny,bool isResizable,int w,int h,bool isAcceleratedRender); <\/code><\/pre>\n<p>  <\/p>\n<p><strong>ITopping.cpp<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">ITCore initCore(char* title,int screenx,int screeny,bool isResizable,int w,int h,bool isAcceleratedRender) { ITCore core; if(isResizable == true) core.window = SDL_CreateWindow(title,screenx,screeny,w,h,SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if(isResizable == false) core.window = SDL_CreateWindow(title,screenx,screeny,w,h,SDL_WINDOW_SHOWN); if(isAcceleratedRender == true) core.render = SDL_CreateRenderer(core.window,-1,SDL_RENDERER_ACCELERATED); if(isAcceleratedRender == false) core.render = SDL_CreateRenderer(core.window,-1,SDL_RENDERER_SOFTWARE); return(core); } <\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a \u0441\u043f\u0440\u0430\u0439\u0442\u0430\u043c:<\/p>\n<p>  <\/p>\n<p>\u0421\u043f\u0440\u0430\u0439\u0442 \u2014 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0438 (\u0438\u043d\u043e\u0433\u0434\u0430) \u0443\u0433\u043e\u043b.<\/p>\n<p>  <\/p>\n<p><strong>ITopping.h<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">ITSprite initSprite(ITCore* core,char* texturepath,int imagew,int imageh,int initx,int inity,bool isCropped,SDL_Rect crop); <\/code><\/pre>\n<p>  <\/p>\n<p><strong>ITopping.cpp<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">ITSprite initSprite(ITCore* core,char* texturepath,int imagew,int imageh,int initx,int inity,bool isCropped,SDL_Rect crop) {     ITSprite spr;     spr.texture = IMG_LoadTexture(core-&gt;render,texturepath);     spr.rect.x = initx;     spr.rect.y = inity;     spr.rect.w = imagew;     spr.rect.h = imageh;     if(isCropped == true)     {         spr.crop = crop;     }     return spr; } <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0432\u043e\u0440\u043e\u0442 \u0441\u043f\u0440\u0430\u0439\u0442\u0430:<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0448 \u0441\u043f\u0440\u0430\u0439\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0443\u0433\u043b\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u0432\u043e\u0440\u043e\u0442 \u2014 \u044d\u0442\u043e \u0441\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0432\u0435\u0434\u0451\u043d\u044b\u0445 \u0433\u0440\u0430\u0434\u0443\u0441\u043e\u0432 \u0441 \u0443\u0433\u043b\u043e\u043c \u0441\u043f\u0440\u0430\u0439\u0442\u0430 \u043f\u043e \u043c\u043e\u0434\u0443\u043b\u044e 360:<\/p>\n<p>  <\/p>\n<p><strong>ITopping.h<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void turnSprite(ITSprite* spr,int angle); <\/code><\/pre>\n<p>  <\/p>\n<p><strong>ITopping.cpp<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void turnSprite(ITSprite* spr,int angle) {     spr-&gt;angle = ((spr-&gt;angle + angle) % 360); } <\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 \u0441\u043f\u0440\u0430\u0439\u0442\u0430:<\/p>\n<p>  <\/p>\n<p><strong>ITopping.h<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void drawSprite(ITCore* core,ITSprite* spr,bool isCropped); <\/code><\/pre>\n<p>  <\/p>\n<p><strong>ITopping.cpp<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void drawSprite(ITCore* core,ITSprite* spr,bool isCropped) {     if(isCropped) SDL_RenderCopyEx(core-&gt;render,spr-&gt;texture,&amp;(spr-&gt;crop),&amp;(spr-&gt;rect),spr-&gt;angle,NULL,SDL_FLIP_NONE);     else SDL_RenderCopyEx(core-&gt;render,spr-&gt;texture,NULL,&amp;(spr-&gt;rect),spr-&gt;angle,NULL,SDL_FLIP_NONE); } <\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u043d\u0434\u0435\u0440 \u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<p>  <\/p>\n<p>\u0420\u0435\u043d\u0434\u0435\u0440\u0438\u043c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u044c \u0432 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443, \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0441 \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u043e\u043c\/\u0431\u0435\u0437 \u043f\u043e\u0432\u043e\u0440\u043e\u0442\u0430.<\/p>\n<p>  <\/p>\n<p><strong>ITopping.h<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void drawText(ITCore* core,const char* text,const char* fontpath,int basesize,SDL_Color color,int x,int y,bool isRotated,int angle); <\/code><\/pre>\n<p>  <\/p>\n<p><strong>ITopping.cpp<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void drawText(ITCore* core,const char* text,const char* fontpath,int basesize,SDL_Color color,int x,int y,bool isRotated,int angle) {     TTF_Font* font = TTF_OpenFont(fontpath,basesize);     SDL_Surface* textSurface = TTF_RenderText_Solid(font, text, color);     SDL_Texture* textTexture = SDL_CreateTextureFromSurface(core-&gt;render,textSurface);     SDL_Rect textrect;     textrect.w = textSurface-&gt;w;     textrect.h = textSurface-&gt;h;     textrect.x = x;     textrect.y = y;     if(isRotated == false) SDL_RenderCopy(core-&gt;render,textTexture,NULL,&amp;textrect);     else SDL_RenderCopyEx(core-&gt;render,textTexture,NULL,&amp;textrect,angle,NULL,SDL_FLIP_NONE); } <\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043d\u0430 GitHub&#8217;\u0435: <a href=\"https:\/\/github.com\/Fedorsturov\/itopping\">https:\/\/github.com\/Fedorsturov\/itopping<\/a><\/p>\n<p>  <\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<div class=\"clear\"><\/div>\n<p> \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:\/\/habrahabr.ru\/post\/281368\/\"> https:\/\/habrahabr.ru\/post\/281368\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<p>\u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438\u0433\u0440\u044b \u043d\u0430 SDL \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0435\u043a \u2014 \u043e\u0447\u0435\u043d\u044c \u043c\u0443\u0442\u043e\u0440\u043d\u043e\u0435 \u0434\u0435\u043b\u043e.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0449\u0435\u0439 \u0436\u0438\u0437\u043d\u044c.<\/li>\n<li>\u0411\u0440\u043e\u0441\u0430\u0435\u043c SDL \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443.<br \/>\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-278051","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/278051","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=278051"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/278051\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=278051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=278051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=278051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}