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
 
SDL_Surfacesurface
 
int done
 

Function Documentation

◆ DrawChessBoard()

void DrawChessBoard ( SDL_Renderer renderer)

Definition at line 32 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().

33 {
34  int row = 0,column = 0,x = 0;
35  SDL_Rect rect, darea;
36 
37  /* Get the Size of drawing surface */
38  SDL_RenderGetViewport(renderer, &darea);
39 
40  for( ; row < 8; row++)
41  {
42  column = row%2;
43  x = column;
44  for( ; column < 4+(row%2); column++)
45  {
46  SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
47 
48  rect.w = darea.w/8;
49  rect.h = darea.h/8;
50  rect.x = x * rect.w;
51  rect.y = row * rect.h;
52  x = x + 2;
53  SDL_RenderFillRect(renderer, &rect);
54  }
55  }
56 }
GLenum GLenum void void * column
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
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 59 of file testdrawchessboard.c.

References done, DrawChessBoard(), e, SDL_WindowEvent::event, SDL_Event::key, SDL_KeyboardEvent::keysym, SDL_CreateSoftwareRenderer, SDL_DestroyRenderer, SDL_GetWindowSurface, SDL_KEYDOWN, SDL_PollEvent, SDL_QUIT, SDL_RenderClear, SDL_SetRenderDrawColor, SDL_UpdateWindowSurface, SDL_WINDOWEVENT, SDL_WINDOWEVENT_SIZE_CHANGED, SDLK_ESCAPE, SDL_Keysym::sym, SDL_Event::type, and SDL_Event::window.

Referenced by main().

60 {
61  SDL_Event e;
62  while (SDL_PollEvent(&e)) {
63 
64  /* Re-create when window has been resized */
66 
68 
71  /* Clear the rendering surface with the specified color */
72  SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
74  }
75 
76  if (e.type == SDL_QUIT) {
77  done = 1;
78 #ifdef __EMSCRIPTEN__
79  emscripten_cancel_main_loop();
80 #endif
81  return;
82  }
83 
84  if ((e.type == SDL_KEYDOWN) && (e.key.keysym.sym == SDLK_ESCAPE)) {
85  done = 1;
86 #ifdef __EMSCRIPTEN__
87  emscripten_cancel_main_loop();
88 #endif
89  return;
90  }
91  }
92 
94 
95  /* Got everything on rendering surface,
96  now Update the drawing image on window screen */
98 }
#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
EGLSurface surface
Definition: eglext.h:248
void DrawChessBoard(SDL_Renderer *renderer)
SDL_WindowEvent window
Definition: SDL_events.h:529
#define SDL_UpdateWindowSurface
#define SDL_GetWindowSurface
SDL_Keysym keysym
Definition: SDL_events.h:199
SDL_Renderer * renderer
#define SDL_CreateSoftwareRenderer
#define SDL_RenderClear
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
SDL_KeyboardEvent key
Definition: SDL_events.h:530
SDL_Keycode sym
Definition: SDL_keyboard.h:50
General event structure.
Definition: SDL_events.h:525
#define SDL_SetRenderDrawColor
#define SDL_DestroyRenderer
int done
Uint32 type
Definition: SDL_events.h:527

◆ main()

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

Definition at line 101 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, SDL_WINDOW_RESIZABLE, and SDL_WINDOWPOS_UNDEFINED.

102 {
103  /* Enable standard application logging */
105 
106  /* Initialize SDL */
107  if(SDL_Init(SDL_INIT_VIDEO) != 0)
108  {
109  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
110  return 1;
111  }
112 
113 
114  /* Create window and renderer for given surface */
116  if(!window)
117  {
118  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
119  return 1;
120  }
123  if(!renderer)
124  {
125  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
126  return 1;
127  }
128 
129  /* Clear the rendering surface with the specified color */
130  SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
132 
133 
134  /* Draw the Image on rendering surface */
135  done = 0;
136 #ifdef __EMSCRIPTEN__
137  emscripten_set_main_loop(loop, 0, 1);
138 #else
139  while (!done) {
140  loop();
141  }
142 #endif
143 
144  SDL_Quit();
145  return 0;
146 }
#define SDL_GetError
EGLSurface surface
Definition: eglext.h:248
#define SDL_CreateWindow
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:130
#define SDL_LogError
void loop()
#define SDL_Quit
#define SDL_GetWindowSurface
SDL_Renderer * renderer
#define SDL_CreateSoftwareRenderer
#define SDL_LogSetPriority
#define SDL_RenderClear
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
#define SDL_Init
#define SDL_SetRenderDrawColor
int done
#define SDL_INIT_VIDEO
Definition: SDL.h:78

Variable Documentation

◆ done

int done

Definition at line 29 of file testdrawchessboard.c.

Referenced by loop(), and main().

◆ renderer

SDL_Renderer* renderer

Definition at line 27 of file testdrawchessboard.c.

◆ surface

Definition at line 28 of file testdrawchessboard.c.

◆ window

Definition at line 26 of file testdrawchessboard.c.