test/testdrawchessboard.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sat, 27 Jul 2013 21:07:07 +0200
changeset 7540 b1c08daea9cd
parent 7538 1d187795e103
child 7541 913786dec9d5
permissions -rw-r--r--
Removed unused variable from test program.
     1 /*
     2    Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     3 
     4    This software is provided 'as-is', without any express or implied
     5    warranty.  In no event will the authors be held liable for any damages
     6    arising from the use of this software.
     7 
     8    Permission is granted to anyone to use this software for any purpose,
     9    including commercial applications, and to alter it and redistribute it
    10    freely.
    11 
    12    This file is created by : Nitin Jain (nitin.j4@samsung.com)
    13 */
    14 
    15 /* Sample program:  Draw a Chess Board  by using SDL_CreateSoftwareRenderer API */
    16 
    17 #include <stdlib.h>
    18 #include <stdio.h>
    19 
    20 #include "SDL.h"
    21 
    22 void
    23 DrawChessBoard(SDL_Renderer * renderer)
    24 {
    25 	int row = 0,coloum = 0,x = 0;
    26 	SDL_Rect rect, darea;
    27 
    28 	/* Get the Size of drawing surface */
    29 	SDL_RenderGetViewport(renderer, &darea);
    30 
    31 	for(row; row < 8; row++)
    32 	{
    33 		coloum = row%2;
    34 		x = x + coloum;
    35 		for(coloum; coloum < 4+(row%2); coloum++)
    36 		{
    37 			SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
    38 
    39 			rect.w = darea.w/8;
    40 			rect.h = darea.h/8;
    41 			rect.x = x * rect.w;
    42 			rect.y = row * rect.h;
    43 			x = x + 2;
    44 			SDL_RenderFillRect(renderer, &rect);
    45 		}
    46 		x=0;
    47 	}
    48 }
    49 
    50 int
    51 main(int argc, char *argv[])
    52 {
    53 
    54 	/* Initialize SDL */
    55 	if(SDL_Init(SDL_INIT_VIDEO) != 0)
    56 	{
    57 		fprintf(stderr,"SDL_Init fail : %s\n", SDL_GetError());
    58 		return 1;
    59 	}
    60 
    61 
    62 	/* Create window and renderer for given surface */
    63 	SDL_Window *window = SDL_CreateWindow("Chess Board",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_SHOWN);
    64 	if(!window)
    65 	{
    66 		fprintf(stderr,"Window creation fail : %s\n",SDL_GetError());
    67 		return 1;
    68 	}	
    69 	SDL_Surface *surface = SDL_GetWindowSurface(window);
    70 	SDL_Renderer *renderer = SDL_CreateSoftwareRenderer(surface);
    71 	if(!renderer)
    72 	{
    73 		fprintf(stderr,"Render creation for surface fail : %s\n",SDL_GetError());
    74 		return 1;
    75 	}
    76 
    77 	/* Clear the rendering surface with the specified color */
    78 	SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0);
    79 	SDL_RenderClear(renderer);
    80 
    81 
    82 	/* Draw the Image on rendering surface */
    83 	while(1)
    84 	{
    85 		SDL_Event e;
    86 		if (SDL_PollEvent(&e)) {
    87 			if (e.type == SDL_QUIT) 
    88 				break;
    89 
    90 			if(e.key.keysym.sym == SDLK_ESCAPE)
    91 				break;
    92 		}
    93 		
    94 		DrawChessBoard(renderer);
    95 		
    96 		/* Got everything on rendering surface,
    97  		   now Update the drawing image on window screen */
    98 		SDL_UpdateWindowSurface(window);
    99 
   100 	}
   101 
   102 	return 0;
   103 }
   104