SDL  2.0
testdrawchessboard.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
+ Include dependency graph for testdrawchessboard.c:

Go to the source code of this file.

Functions

void DrawChessBoard (SDL_Renderer *renderer)
 
void loop ()
 
int main (int argc, char *argv[])
 

Variables

SDL_Windowwindow
 
SDL_Rendererrenderer
 
int done
 

Function Documentation

◆ DrawChessBoard()

void DrawChessBoard ( SDL_Renderer renderer)

Definition at line 31 of file testdrawchessboard.c.

References SDL_Rect::h, rect, SDL_RenderFillRect, SDL_RenderGetViewport, SDL_SetRenderDrawColor, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by loop().

32 {
33  int row = 0,column = 0,x = 0;
34  SDL_Rect rect, darea;
35 
36  /* Get the Size of drawing surface */
37  SDL_RenderGetViewport(renderer, &darea);
38 
39  for( ; row < 8; row++)
40  {
41  column = row%2;
42  x = column;
43  for( ; column < 4+(row%2); column++)
44  {
45  SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
46 
47  rect.w = darea.w/8;
48  rect.h = darea.h/8;
49  rect.x = x * rect.w;
50  rect.y = row * rect.h;
51  x = x + 2;
52  SDL_RenderFillRect(renderer, &rect);
53  }
54  }
55 }
GLenum GLenum void void * column
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
SDL_Rect rect
Definition: testrelative.c:27
#define SDL_RenderFillRect
#define SDL_RenderGetViewport
int x
Definition: SDL_rect.h:66
int w
Definition: SDL_rect.h:67
int h
Definition: SDL_rect.h:67
#define SDL_SetRenderDrawColor
GLenum GLenum void * row
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

◆ loop()

void loop ( )

Definition at line 58 of file testdrawchessboard.c.

References done, DrawChessBoard(), e, SDL_Event::key, SDL_KeyboardEvent::keysym, SDL_KEYDOWN, SDL_PollEvent, SDL_QUIT, SDL_UpdateWindowSurface, SDLK_ESCAPE, SDL_Keysym::sym, and SDL_Event::type.

Referenced by main().

59 {
60  SDL_Event e;
61  while (SDL_PollEvent(&e)) {
62  if (e.type == SDL_QUIT) {
63  done = 1;
64 #ifdef __EMSCRIPTEN__
65  emscripten_cancel_main_loop();
66 #endif
67  return;
68  }
69 
70  if ((e.type == SDL_KEYDOWN) && (e.key.keysym.sym == SDLK_ESCAPE)) {
71  done = 1;
72 #ifdef __EMSCRIPTEN__
73  emscripten_cancel_main_loop();
74 #endif
75  return;
76  }
77  }
78 
80 
81  /* Got everything on rendering surface,
82  now Update the drawing image on window screen */
84 }
#define SDL_PollEvent
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 * e
void DrawChessBoard(SDL_Renderer *renderer)
#define SDL_UpdateWindowSurface
SDL_Window * window
SDL_Keysym keysym
Definition: SDL_events.h:199
SDL_Renderer * renderer
SDL_KeyboardEvent key
Definition: SDL_events.h:530
SDL_Keycode sym
Definition: SDL_keyboard.h:50
General event structure.
Definition: SDL_events.h:525
int done
Uint32 type
Definition: SDL_events.h:527

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 87 of file testdrawchessboard.c.

References done, loop(), SDL_CreateSoftwareRenderer, SDL_CreateWindow, SDL_GetError, SDL_GetWindowSurface, SDL_Init, SDL_INIT_VIDEO, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, SDL_Quit, SDL_RenderClear, SDL_SetRenderDrawColor, and SDL_WINDOWPOS_UNDEFINED.

88 {
89  SDL_Surface *surface;
90 
91  /* Enable standard application logging */
93 
94  /* Initialize SDL */
95  if(SDL_Init(SDL_INIT_VIDEO) != 0)
96  {
97  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
98  return 1;
99  }
100 
101 
102  /* Create window and renderer for given surface */
104  if(!window)
105  {
106  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
107  return 1;
108  }
109  surface = SDL_GetWindowSurface(window);
111  if(!renderer)
112  {
113  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
114  return 1;
115  }
116 
117  /* Clear the rendering surface with the specified color */
118  SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
120 
121 
122  /* Draw the Image on rendering surface */
123  done = 0;
124 #ifdef __EMSCRIPTEN__
125  emscripten_set_main_loop(loop, 0, 1);
126 #else
127  while (!done) {
128  loop();
129  }
130 #endif
131 
132  SDL_Quit();
133  return 0;
134 }
#define SDL_GetError
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
#define SDL_CreateWindow
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:127
#define SDL_LogError
void loop()
#define SDL_Quit
SDL_Window * window
#define SDL_GetWindowSurface
SDL_Renderer * renderer
#define SDL_CreateSoftwareRenderer
#define SDL_LogSetPriority
#define SDL_RenderClear
#define SDL_Init
#define SDL_SetRenderDrawColor
int done
#define SDL_INIT_VIDEO
Definition: SDL.h:77

Variable Documentation

◆ done

int done

Definition at line 28 of file testdrawchessboard.c.

Referenced by loop(), and main().

◆ renderer

SDL_Renderer* renderer

Definition at line 27 of file testdrawchessboard.c.

◆ window

SDL_Window* window

Definition at line 26 of file testdrawchessboard.c.