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

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().

{
int row = 0,column = 0,x = 0;
SDL_Rect rect, darea;
/* Get the Size of drawing surface */
SDL_RenderGetViewport(renderer, &darea);
for( ; row < 8; row++)
{
column = row%2;
x = column;
for( ; column < 4+(row%2); column++)
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
rect.w = darea.w/8;
rect.h = darea.h/8;
rect.x = x * rect.w;
rect.y = row * rect.h;
x = x + 2;
SDL_RenderFillRect(renderer, &rect);
}
}
}
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.

{
while (SDL_PollEvent(&e)) {
/* Re-create when window has been resized */
/* Clear the rendering surface with the specified color */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
}
if (e.type == SDL_QUIT) {
done = 1;
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
#endif
return;
}
if ((e.type == SDL_KEYDOWN) && (e.key.keysym.sym == SDLK_ESCAPE)) {
done = 1;
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
#endif
return;
}
}
/* Got everything on rendering surface,
now Update the drawing image on window screen */
}
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.

{
/* Enable standard application logging */
/* Initialize SDL */
{
return 1;
}
/* Create window and renderer for given surface */
if(!window)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
return 1;
}
if(!renderer)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
return 1;
}
/* Clear the rendering surface with the specified color */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
/* Draw the Image on rendering surface */
done = 0;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done) {
loop();
}
#endif
return 0;
}

Variable Documentation

int done

Definition at line 29 of file testdrawchessboard.c.

SDL_Renderer* renderer

Definition at line 27 of file testdrawchessboard.c.

Definition at line 28 of file testdrawchessboard.c.

Definition at line 26 of file testdrawchessboard.c.