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_Window * | window
SDL_Renderer * | renderer
int | done

## Function Documentation

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

{
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);
}
}
}
column
GLenum GLenum void void * column
Definition: SDL_opengl_glext.h:3138
x
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1567
rect
SDL_Rect rect
Definition: testrelative.c:27
SDL_RenderFillRect
#define SDL_RenderFillRect
Definition: SDL_dynapi_overrides.h:347
SDL_RenderGetViewport
#define SDL_RenderGetViewport
Definition: SDL_dynapi_overrides.h:331
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_SetRenderDrawColor
#define SDL_SetRenderDrawColor
Definition: SDL_dynapi_overrides.h:336
row
GLenum GLenum void * row
Definition: SDL_opengl_glext.h:3138
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64

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

{
SDL_Event e;
while (SDL_PollEvent(&e)) {
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;
}
}
DrawChessBoard(renderer);
/* Got everything on rendering surface,
now Update the drawing image on window screen */
SDL_UpdateWindowSurface(window);
}
SDL_PollEvent
#define SDL_PollEvent
Definition: SDL_dynapi_overrides.h:128
SDL_KEYDOWN
Definition: SDL_events.h:93
e
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
Definition: SDL_dynapi_procs.h:121
SDL_QUIT
Definition: SDL_events.h:60
DrawChessBoard
void DrawChessBoard(SDL_Renderer *renderer)
Definition: testdrawchessboard.c:31
SDL_UpdateWindowSurface
#define SDL_UpdateWindowSurface
Definition: SDL_dynapi_overrides.h:545
window
SDL_Window * window
Definition: testdrawchessboard.c:26
SDL_KeyboardEvent::keysym
SDL_Keysym keysym
Definition: SDL_events.h:196
renderer
SDL_Renderer * renderer
Definition: testdrawchessboard.c:27
SDL_Event::key
SDL_KeyboardEvent key
Definition: SDL_events.h:526
SDL_Keysym::sym
SDL_Keycode sym
Definition: SDL_keyboard.h:50
SDL_Event
General event structure.
Definition: SDL_events.h:521
done
int done
Definition: testdrawchessboard.c:28
SDLK_ESCAPE
Definition: SDL_keycode.h:52
SDL_Event::type
Uint32 type
Definition: SDL_events.h:523

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, SDL_WINDOW_SHOWN, and SDL_WINDOWPOS_UNDEFINED.

{
SDL_Surface *surface;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL */
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
return 1;
}
/* Create window and renderer for given surface */
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
if(!window)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
return 1;
}
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
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);
SDL_RenderClear(renderer);
/* Draw the Image on rendering surface */
done = 0;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done) {
loop();
}
#endif
SDL_Quit();
return 0;
}
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:119
SDL_Surface
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
SDL_CreateWindow
#define SDL_CreateWindow
Definition: SDL_dynapi_overrides.h:518
SDL_WINDOWPOS_UNDEFINED
#define SDL_WINDOWPOS_UNDEFINED
Definition: SDL_video.h:120
SDL_WINDOW_SHOWN
Definition: SDL_video.h:100
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:42
loop
void loop()
Definition: testdrawchessboard.c:58
SDL_Quit
#define SDL_Quit
Definition: SDL_dynapi_overrides.h:64
window
SDL_Window * window
Definition: testdrawchessboard.c:26
SDL_GetWindowSurface
#define SDL_GetWindowSurface
Definition: SDL_dynapi_overrides.h:544
SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
renderer
SDL_Renderer * renderer
Definition: testdrawchessboard.c:27
SDL_CreateSoftwareRenderer
#define SDL_CreateSoftwareRenderer
Definition: SDL_dynapi_overrides.h:308
SDL_LogSetPriority
#define SDL_LogSetPriority
Definition: SDL_dynapi_overrides.h:242
SDL_RenderClear
#define SDL_RenderClear
Definition: SDL_dynapi_overrides.h:340
SDL_Init
#define SDL_Init
Definition: SDL_dynapi_overrides.h:60
SDL_SetRenderDrawColor
#define SDL_SetRenderDrawColor
Definition: SDL_dynapi_overrides.h:336
done
int done
Definition: testdrawchessboard.c:28
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77

## Variable Documentation

int done

Definition at line 28 of file testdrawchessboard.c.

Referenced by loop(), and main().

SDL_Renderer* renderer

Definition at line 27 of file testdrawchessboard.c.

SDL_Window* window

Definition at line 26 of file testdrawchessboard.c.