Home | History | Annotate | Download | only in test
      1 /*
      2    Copyright (C) 1997-2014 Sam Lantinga <slouken (at) 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 (at) 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, 0xFF);
     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 	SDL_Window *window;
     54 	SDL_Surface *surface;
     55 	SDL_Renderer *renderer;
     56 
     57     /* Enable standard application logging */
     58     SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
     59 
     60 	/* Initialize SDL */
     61 	if(SDL_Init(SDL_INIT_VIDEO) != 0)
     62 	{
     63 		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
     64 		return 1;
     65 	}
     66 
     67 
     68 	/* Create window and renderer for given surface */
     69 	window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
     70 	if(!window)
     71 	{
     72 		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
     73 		return 1;
     74 	}
     75 	surface = SDL_GetWindowSurface(window);
     76 	renderer = SDL_CreateSoftwareRenderer(surface);
     77 	if(!renderer)
     78 	{
     79 		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
     80 		return 1;
     81 	}
     82 
     83 	/* Clear the rendering surface with the specified color */
     84 	SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
     85 	SDL_RenderClear(renderer);
     86 
     87 
     88 	/* Draw the Image on rendering surface */
     89 	while(1)
     90 	{
     91 		SDL_Event e;
     92 		if (SDL_PollEvent(&e)) {
     93 			if (e.type == SDL_QUIT)
     94 				break;
     95 
     96 			if(e.key.keysym.sym == SDLK_ESCAPE)
     97 				break;
     98 		}
     99 
    100 		DrawChessBoard(renderer);
    101 
    102 		/* Got everything on rendering surface,
    103  		   now Update the drawing image on window screen */
    104 		SDL_UpdateWindowSurface(window);
    105 
    106 	}
    107 
    108 	return 0;
    109 }
    110 
    111