Esempio n. 1
0
qboolean VID_ScreenShot( const char *filename, int shot_type )
{
	rgbdata_t *r_shot;
	uint	flags = IMAGE_FLIP_Y;
	int	width = 0, height = 0;
	qboolean	result;

	r_shot = Mem_Alloc( r_temppool, sizeof( rgbdata_t ));
	r_shot->width = (glState.width + 3) & ~3;
	r_shot->height = (glState.height + 3) & ~3;
	r_shot->flags = IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA;
	r_shot->type = PF_RGBA_32;
	r_shot->size = r_shot->width * r_shot->height * PFDesc[r_shot->type].bpp;
	r_shot->palette = NULL;
	r_shot->buffer = Mem_Alloc( r_temppool, r_shot->size );

	// get screen frame
	pglPixelStorei(GL_PACK_ALIGNMENT, 1);	// PANDORA, just in case
	pglReadPixels( 0, 0, r_shot->width, r_shot->height, GL_RGBA, GL_UNSIGNED_BYTE, r_shot->buffer );
	switch( shot_type )
	{
	case VID_SCREENSHOT:
		if( !gl_overview->integer )
			VID_ImageAdjustGamma( r_shot->buffer, r_shot->width, r_shot->height ); // scrshot gamma
		break;
	case VID_SNAPSHOT:
		if( !gl_overview->integer )
			VID_ImageAdjustGamma( r_shot->buffer, r_shot->width, r_shot->height ); // scrshot gamma
		FS_AllowDirectPaths( true );
		break;
	case VID_LEVELSHOT:
		flags |= IMAGE_RESAMPLE;
		if( glState.wideScreen )
		{
			height = 480;
			width = 800;
		}
		else
		{
			height = 480;
			width = 640;
		}
		break;
	case VID_MINISHOT:
		flags |= IMAGE_RESAMPLE;
		height = 200;
		width = 320;
		break;
	case VID_MAPSHOT:
		V_WriteOverviewScript();		// store overview script too
		flags |= IMAGE_RESAMPLE|IMAGE_QUANTIZE;	// GoldSrc request overviews in 8-bit format
		height = 768;
		width = 1024;
		break;
	}

	Image_Process( &r_shot, width, height, 0.0f, flags, NULL );

	// write image
	result = FS_SaveImage( filename, r_shot );
	host.write_to_clipboard = false;		// disable write to clipboard
	FS_AllowDirectPaths( false );			// always reset after store screenshot
	FS_FreeImage( r_shot );

	return result;
}
Esempio n. 2
0
SDL_bool
blitter_opengl_init()
{
	Uint32 sdl_flags;
	Uint32 width = visible_area.w;
	Uint32 height = visible_area.h;		
	
        if (load_glproc() == SDL_FALSE) return SDL_FALSE;

	sdl_flags = (fullscreen?SDL_FULLSCREEN:0)| SDL_DOUBLEBUF | SDL_HWSURFACE
	    | SDL_HWPALETTE | SDL_OPENGL | SDL_RESIZABLE;
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	if ((effect[neffect].x_ratio!=2 || effect[neffect].y_ratio!=2) &&  
	    (effect[neffect].x_ratio!=1 || effect[neffect].y_ratio!=1) ) {
	    printf("Opengl support only effect with a ratio of 2x2 or 1x1\n");
	    return SDL_FALSE;
	}
	    
	/*
	  if (conf.res_x==304 && conf.res_y==224) {
	*/
	if (scale < 2) {
	    width *=effect[neffect].x_ratio;
	    height*=effect[neffect].y_ratio;
	}
	width *= scale;
	height *= scale;
/*
	} else {
	    width = conf.res_x;
	    height=conf.res_y;
	}
	
*/
	conf.res_x=width;
	conf.res_y=height;
	
	video_opengl = SDL_SetVideoMode(width, height, 16, sdl_flags);
	
	if ( video_opengl == NULL)
		return SDL_FALSE;
	
	pglClearColor(0, 0, 0, 0);
	pglClear(GL_COLOR_BUFFER_BIT);
	
	pglEnable(GL_TEXTURE_2D);
	pglViewport(0, 0, width, height);
	
	/* Linear Filter */
	
        pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	/*
	  pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	  pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	*/
	/* Texture Mode */
	pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	
		
	if (neffect == 0)
	{
		/* Texture limits */
/*
		a = (240.0/304.0);
		b = (48.0/256.0);
		
		c = (240.0/256.0);
*/
#ifdef USE_GL2
	    tex_opengl= SDL_CreateRGBSurface(SDL_SWSURFACE, 512, 256, 16, 0xF800, 0x7E0, 0x1F, 0);
#else
	    pglPixelStorei(GL_UNPACK_ROW_LENGTH, 352);
#endif
	}
	else {		
	    /* Texture limits */
	    a = ((256.0/(float)visible_area.w) - 1.0f)*effect[neffect].x_ratio/2.0;
	    b = ((512.0/(float)visible_area.w) - 1.0f)*effect[neffect].x_ratio/2.0;
	    c = (((float)visible_area.h/256.0))*effect[neffect].y_ratio/2.0;
	    d = (((float)((visible_area.w<<1)-512)/256.0))*effect[neffect].y_ratio/2.0;
	    screen = SDL_CreateRGBSurface(SDL_SWSURFACE, visible_area.w<<1,  /*visible_area.h<<1*/512, 16, 0xF800, 0x7E0, 0x1F, 0);
	    //printf("[opengl] create_screen %p\n",screen);
#ifdef USE_GL2
	    tex_opengl= SDL_CreateRGBSurface(SDL_SWSURFACE, 1024, 512, 16, 0xF800, 0x7E0, 0x1F, 0);
	    if (visible_area.w==320) {
		glrectef.x=0;
		glrectef.y=0;
		glrectef.w=320*2;
		glrectef.h=224*2;
	    } else {
		glrectef.x=0;
		glrectef.y=0;
		glrectef.w=304*2;
		glrectef.h=224*2;
	    }
#else
	    pglPixelStorei(GL_UNPACK_ROW_LENGTH, visible_area.w<<1);
#endif
	}
	
	return SDL_TRUE;
}