summaryrefslogtreecommitdiff
path: root/src/graphic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphic.c')
-rw-r--r--src/graphic.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/graphic.c b/src/graphic.c
new file mode 100644
index 0000000..dbdb55c
--- /dev/null
+++ b/src/graphic.c
@@ -0,0 +1,82 @@
+#include "graphic.h"
+#include "utils.h"
+
+void my_SDL_init_or_die(char title[], SDL_Rect win_pos, Uint32 init_flags, Uint32 win_flags, Uint32 rend_flags, SDL_Window **win, SDL_Renderer **rend, SDL_RendererInfo *rend_info, SDL_Rect *viewport)
+{
+ int res, i;
+ Uint32 tf;
+
+ res=SDL_Init(init_flags);
+ MPL_CHECK(
+ res==0, // Expression to evaluate
+ {exit(1);} , // Code to execute if expression is not true
+ SDL_LOG_PRIORITY_CRITICAL, // SDL_LogPriority (_CRITICAL, _ERROR, _WARN, _INFO, DEBUG, _VERBOSE)
+ "SDL_Init failed (%i)",res // var args list starting with a fmt string like in printf()
+ );
+
+
+ *win=SDL_CreateWindow(title,win_pos.x,win_pos.y,win_pos.w,win_pos.h,win_flags);
+ MPL_CHECK(
+ *win, // Just put the pointer if you want to check if it's not NULL
+ {SDL_Quit(); exit(2);},
+ SDL_LOG_PRIORITY_CRITICAL,
+ "SDL_CreateWindow failed"
+ );
+
+
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,
+ "SDL_GetWindowPixelFormat() returns %i", SDL_GetWindowPixelFormat(*win)
+ );
+
+ *rend=SDL_CreateRenderer(*win,-1, rend_flags);
+ MPL_CHECK(
+ *rend,
+ {SDL_DestroyWindow(*win);SDL_Quit(); exit(3);},
+ SDL_LOG_PRIORITY_CRITICAL,
+ "SDL_CreateRenderer(...,SDL_RENDERER_ACCELERATED) failed"
+ );
+
+ res=SDL_GetRendererInfo(*rend, rend_info);
+ MPL_CHECK(
+ res==0,
+ {SDL_DestroyRenderer(*rend);SDL_DestroyWindow(*win);SDL_Quit(); exit(4);},
+ SDL_LOG_PRIORITY_CRITICAL,
+ "res=SDL_GetRendererInfo() failed"
+ );
+
+ tf=1;
+ for(i=0;i<16 && tf!=0;i++) {
+ tf=rend_info->texture_formats[i];
+
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,
+ "rend_info->texture_formats[%i] == %i", i, tf
+ );
+ }
+
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,
+ "rend_info->flags==%i", rend_info->flags );
+
+ if ( (rend_info->flags & SDL_RENDERER_SOFTWARE) == SDL_RENDERER_SOFTWARE) {
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,
+ "rend_info->flags contains SDL_RENDERER_SOFTWARE");
+ }
+
+ if ( (rend_info->flags & SDL_RENDERER_ACCELERATED) == SDL_RENDERER_ACCELERATED) {
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,
+ "rend_info->flags contains SDL_RENDERER_ACCELERATED");
+ }
+
+ if ( (rend_info->flags & SDL_RENDERER_PRESENTVSYNC) == SDL_RENDERER_PRESENTVSYNC) {
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,
+ "rend_info->flags contains SDL_RENDERER_PRESENTVSYNC");
+ }
+
+ if ( (rend_info->flags & SDL_RENDERER_TARGETTEXTURE) == SDL_RENDERER_TARGETTEXTURE) {
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION,SDL_LOG_PRIORITY_INFO,
+ "rend_info->flags contains SDL_RENDERER_TARGETTEXTURE");
+ }
+
+ // Remarks : When the window is resized, the current viewport is automatically centered within the new window size.
+ SDL_RenderGetViewport(*rend, viewport);
+}
+