ccdemos/common_sdl.h
branchpyrit
changeset 46 6493fb65f0b1
parent 40 929aad02c5f2
child 72 7c3f38dff082
equal deleted inserted replaced
45:76b254ce92cf 46:6493fb65f0b1
    19 	t = tnow;
    19 	t = tnow;
    20 	char s[40];
    20 	char s[40];
    21 	sprintf(s, "fps:%3d.%1d", fp10s/10, fp10s%10);
    21 	sprintf(s, "fps:%3d.%1d", fp10s/10, fp10s%10);
    22 	SDL_WM_SetCaption(s, NULL);
    22 	SDL_WM_SetCaption(s, NULL);
    23 
    23 
    24 	rt.render(w, h, render_buffer);
    24 	rt.render();
    25 
    25 
    26 	if (SDL_MUSTLOCK(screen))
    26 	if (SDL_MUSTLOCK(screen))
    27 		if (SDL_LockSurface(screen) < 0)
    27 		if (SDL_LockSurface(screen) < 0)
    28 			return;
    28 			return;
    29 
    29 
    57 	SDL_Surface *screen;
    57 	SDL_Surface *screen;
    58 	Float *render_buffer;
    58 	Float *render_buffer;
    59 
    59 
    60 	pyrit_verbosity = 0;
    60 	pyrit_verbosity = 0;
    61 	render_buffer = (Float *) malloc(w*h*3*sizeof(Float));
    61 	render_buffer = (Float *) malloc(w*h*3*sizeof(Float));
       
    62 	DefaultSampler sampler(render_buffer, w, h);
       
    63 	rt.setSampler(&sampler);
    62 
    64 
    63 	if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    65 	if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    64 		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    66 		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    65 		exit(1);
    67 		exit(1);
    66 	}
    68 	}
    81 			switch (event.type) {
    83 			switch (event.type) {
    82 				case SDL_VIDEORESIZE:
    84 				case SDL_VIDEORESIZE:
    83 					w = (event.resize.w-1) / 8 * 8 + 8;
    85 					w = (event.resize.w-1) / 8 * 8 + 8;
    84 					h = (event.resize.h-1) / 8 * 8 + 8;
    86 					h = (event.resize.h-1) / 8 * 8 + 8;
    85 					render_buffer = (Float *) realloc(render_buffer, w*h*3*sizeof(Float));
    87 					render_buffer = (Float *) realloc(render_buffer, w*h*3*sizeof(Float));
       
    88 					sampler.resetBuffer(render_buffer, w, h);
    86 					screen = SDL_SetVideoMode(w, h, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE);
    89 					screen = SDL_SetVideoMode(w, h, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE);
    87 					break;
    90 					break;
    88 				case SDL_KEYDOWN:
    91 				case SDL_KEYDOWN:
    89 					if (event.key.keysym.sym == SDLK_ESCAPE) {
    92 					if (event.key.keysym.sym == SDLK_ESCAPE) {
    90 						quit = true;
    93 						quit = true;