gba-x3dtest

diff src/main_sdl.c @ 6:73b5f2e5d18a

first triangle on screen
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 18 Jun 2014 04:13:02 +0300
parents 850be43b3135
children fb0a0d6a8b52
line diff
     1.1 --- a/src/main_sdl.c	Mon Jun 16 22:01:45 2014 +0300
     1.2 +++ b/src/main_sdl.c	Wed Jun 18 04:13:02 2014 +0300
     1.3 @@ -13,14 +13,23 @@
     1.4  static SDL_Surface *surf;
     1.5  static struct pixel_buffer bbuf;
     1.6  static unsigned int keystate;
     1.7 +static int sdlscale = 2;
     1.8  
     1.9  int main(void)
    1.10  {
    1.11 -	int i, j;
    1.12 +	int i, j, k, l;
    1.13 +	char *env;
    1.14 +
    1.15 +	if((env = getenv("SDLSCALE"))) {
    1.16 +		if(!(sdlscale = atoi(env))) {
    1.17 +			fprintf(stderr, "invalid SDLSCALE envvar value (%s)\n", env);
    1.18 +			sdlscale = 2;
    1.19 +		}
    1.20 +	}
    1.21  
    1.22  	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE);
    1.23  
    1.24 -	if(!(surf = SDL_SetVideoMode(WIDTH * SDLSCALE, HEIGHT * SDLSCALE, 16, SDL_SWSURFACE))) {
    1.25 +	if(!(surf = SDL_SetVideoMode(WIDTH * sdlscale, HEIGHT * sdlscale, 16, SDL_SWSURFACE))) {
    1.26  		fprintf(stderr, "failed to initialize graphics\n");
    1.27  		return 1;
    1.28  	}
    1.29 @@ -58,10 +67,16 @@
    1.30  
    1.31  		for(i=0; i<HEIGHT; i++) {
    1.32  			for(j=0; j<WIDTH; j++) {
    1.33 -				dest[0] = dest[1] = dest[WIDTH] = dest[WIDTH + 1] = *src++;
    1.34 -				dest += 2;
    1.35 +				uint16_t pixel = *src++;
    1.36 +
    1.37 +				for(k=0; k<sdlscale; k++) {
    1.38 +					for(l=0; l<sdlscale; l++) {
    1.39 +						dest[k * sdlscale * WIDTH + l] = pixel;
    1.40 +					}
    1.41 +				}
    1.42 +				dest += sdlscale;
    1.43  			}
    1.44 -			dest += WIDTH;
    1.45 +			dest += WIDTH * sdlscale * (sdlscale - 1);
    1.46  		}
    1.47  
    1.48  		if(SDL_MUSTLOCK(surf)) {