⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_video.c

📁 Simple DirectMedia Layer - Simple DirectMedia Layer 是一个跨平台的多媒体库设计用来提供快速图形framebuffer和音频驱动。应用MPEG为软件
💻 C
📖 第 1 页 / 共 4 页
字号:
		case SDL_GL_STEREO:			video->gl_config.stereo = value;			break;		default:			SDL_SetError("Unknown OpenGL attribute");			retval = -1;			break;	}	return(retval);}/* Retrieve an attribute value from the windowing system. */int SDL_GL_GetAttribute(SDL_GLattr attr, int* value){	int retval = -1;	SDL_VideoDevice* video = current_video;	SDL_VideoDevice* this = current_video;	if ( video->GL_GetAttribute ) {		retval = this->GL_GetAttribute(this, attr, value);	} else {		*value = 0;		SDL_SetError("GL_GetAttribute not supported");	}	return retval;}/* Perform a GL buffer swap on the current GL context */void SDL_GL_SwapBuffers(void){	SDL_VideoDevice *video = current_video;	SDL_VideoDevice *this = current_video;	if ( video->screen->flags & SDL_OPENGL ) {		video->GL_SwapBuffers(this);	} else {		SDL_SetError("OpenGL video mode has not been set");	}}/* Update rects with locking */void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects){	SDL_GL_Lock(); 	SDL_GL_UpdateRects(numrects, rects);	SDL_GL_Unlock();}/* Update rects without state setting and changing (the caller is responsible for it) */void SDL_GL_UpdateRects(int numrects, SDL_Rect *rects){#ifdef HAVE_OPENGL	SDL_VideoDevice *this = current_video;	SDL_Rect update, tmp;	int x, y, i;	for ( i = 0; i < numrects; i++ )	{		tmp.y = rects[i].y;		tmp.h = rects[i].h;		for ( y = 0; y <= rects[i].h / 256; y++ )		{			tmp.x = rects[i].x;			tmp.w = rects[i].w;			for ( x = 0; x <= rects[i].w / 256; x++ )			{				update.x = tmp.x;				update.y = tmp.y;				update.w = tmp.w;				update.h = tmp.h;				if ( update.w > 256 )					update.w = 256;				if ( update.h > 256 )					update.h = 256;							this->glFlush();				this->glTexSubImage2D( 					GL_TEXTURE_2D, 					0, 					0, 					0, 					update.w, 					update.h, 					this->is_32bit? GL_RGBA : GL_RGB,#ifdef GL_VERSION_1_2					this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5,#else					GL_UNSIGNED_BYTE,#endif					(Uint8 *)this->screen->pixels + 						this->screen->format->BytesPerPixel * update.x + 						update.y * this->screen->pitch );					this->glFlush();				/*				* Note the parens around the function name:				* This is because some OpenGL implementations define glTexCoord etc 				* as macros, and we don't want them expanded here.				*/				this->glBegin(GL_TRIANGLE_STRIP);					(this->glTexCoord2f)( 0.0, 0.0 );						(this->glVertex2i)( update.x, update.y );					(this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 );						(this->glVertex2i)( update.x + update.w, update.y );					(this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) );					(this->glVertex2i)( update.x, update.y + update.h );					(this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) );						(this->glVertex2i)( update.x + update.w	, update.y + update.h );				this->glEnd();								tmp.x += 256;				tmp.w -= 256;			}			tmp.y += 256;			tmp.h -= 256;		}	}#endif}/* Lock == save current state */void SDL_GL_Lock(){#ifdef HAVE_OPENGL	lock_count--;	if (lock_count==-1)	{		SDL_VideoDevice *this = current_video;		this->glPushAttrib( GL_ALL_ATTRIB_BITS );	/* TODO: narrow range of what is saved */#ifdef GL_CLIENT_PIXEL_STORE_BIT		this->glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );#endif		this->glEnable(GL_TEXTURE_2D);		this->glEnable(GL_BLEND);		this->glDisable(GL_FOG);		this->glDisable(GL_ALPHA_TEST);		this->glDisable(GL_DEPTH_TEST);		this->glDisable(GL_SCISSOR_TEST);			this->glDisable(GL_STENCIL_TEST);		this->glDisable(GL_CULL_FACE);		this->glBindTexture( GL_TEXTURE_2D, this->texture );		this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );		this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );		this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );		this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );		this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );		this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel );		this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);		(this->glColor4f)(1.0, 1.0, 1.0, 1.0);		/* Solaris workaround */		this->glViewport(0, 0, this->screen->w, this->screen->h);		this->glMatrixMode(GL_PROJECTION);		this->glPushMatrix();		this->glLoadIdentity();		this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0);		this->glMatrixMode(GL_MODELVIEW);		this->glPushMatrix();		this->glLoadIdentity();	}#endif}/* Unlock == restore saved state */void SDL_GL_Unlock(){#ifdef HAVE_OPENGL	lock_count++;	if (lock_count==0)	{		SDL_VideoDevice *this = current_video;		this->glPopMatrix();		this->glMatrixMode(GL_PROJECTION);		this->glPopMatrix();		this->glPopClientAttrib();		this->glPopAttrib();	}#endif}/* * Sets/Gets the title and icon text of the display window, if any. */void SDL_WM_SetCaption (const char *title, const char *icon){	SDL_VideoDevice *video = current_video;	SDL_VideoDevice *this  = current_video;	if ( video ) {		if ( title ) {			if ( video->wm_title ) {				free(video->wm_title);			}			video->wm_title = (char *)malloc(strlen(title)+1);			if ( video->wm_title != NULL ) {				strcpy(video->wm_title, title);			}		}		if ( icon ) {			if ( video->wm_icon ) {				free(video->wm_icon);			}			video->wm_icon = (char *)malloc(strlen(icon)+1);			if ( video->wm_icon != NULL ) {				strcpy(video->wm_icon, icon);			}		}		if ( (title || icon) && (video->SetCaption != NULL) ) {			video->SetCaption(this, video->wm_title,video->wm_icon);		}	}}void SDL_WM_GetCaption (char **title, char **icon){	SDL_VideoDevice *video = current_video;	if ( video ) {		if ( title ) {			*title = video->wm_title;		}		if ( icon ) {			*icon = video->wm_icon;		}	}}/* Utility function used by SDL_WM_SetIcon() */static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask){	int x, y;	Uint32 colorkey;#define SET_MASKBIT(icon, x, y, mask) \	mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8)))	colorkey = icon->format->colorkey;	switch (icon->format->BytesPerPixel) {		case 1: { Uint8 *pixels;			for ( y=0; y<icon->h; ++y ) {				pixels = (Uint8 *)icon->pixels + y*icon->pitch;				for ( x=0; x<icon->w; ++x ) {					if ( *pixels++ == colorkey ) {						SET_MASKBIT(icon, x, y, mask);					}				}			}		}		break;		case 2: { Uint16 *pixels;			for ( y=0; y<icon->h; ++y ) {				pixels = (Uint16 *)icon->pixels +				                   y*icon->pitch/2;				for ( x=0; x<icon->w; ++x ) {					if ( *pixels++ == colorkey ) {						SET_MASKBIT(icon, x, y, mask);					}				}			}		}		break;		case 4: { Uint32 *pixels;			for ( y=0; y<icon->h; ++y ) {				pixels = (Uint32 *)icon->pixels +				                   y*icon->pitch/4;				for ( x=0; x<icon->w; ++x ) {					if ( *pixels++ == colorkey ) {						SET_MASKBIT(icon, x, y, mask);					}				}			}		}		break;	}}/* * Sets the window manager icon for the display window. */void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask){	SDL_VideoDevice *video = current_video;	SDL_VideoDevice *this  = current_video;	if ( icon && video->SetIcon ) {		/* Generate a mask if necessary, and create the icon! */		if ( mask == NULL ) {			int mask_len = icon->h*(icon->w+7)/8;			mask = (Uint8 *)malloc(mask_len);			if ( mask == NULL ) {				return;			}			memset(mask, ~0, mask_len);			if ( icon->flags & SDL_SRCCOLORKEY ) {				CreateMaskFromColorKey(icon, mask);			}			video->SetIcon(video, icon, mask);			free(mask);		} else {			video->SetIcon(this, icon, mask);		}	}}/* * Grab or ungrab the keyboard and mouse input. * This function returns the final grab mode after calling the * driver dependent function. */static SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode){	SDL_VideoDevice *video = current_video;	SDL_VideoDevice *this  = current_video;	/* Only do something if we have support for grabs */	if ( video->GrabInput == NULL ) {		return(video->input_grab);	}	/* If the final grab mode if off, only then do we actually grab */#ifdef DEBUG_GRAB  printf("SDL_WM_GrabInputRaw(%d) ... ", mode);#endif	if ( mode == SDL_GRAB_OFF ) {		if ( video->input_grab != SDL_GRAB_OFF ) {			mode = video->GrabInput(this, mode);		}	} else {		if ( video->input_grab == SDL_GRAB_OFF ) {			mode = video->GrabInput(this, mode);		}	}	if ( mode != video->input_grab ) {		video->input_grab = mode;		if ( video->CheckMouseMode ) {			video->CheckMouseMode(this);		}	}#ifdef DEBUG_GRAB  printf("Final mode %d\n", video->input_grab);#endif	/* Return the final grab state */	if ( mode >= SDL_GRAB_FULLSCREEN ) {		mode -= SDL_GRAB_FULLSCREEN;	}	return(mode);}SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode){	SDL_VideoDevice *video = current_video;	/* If the video isn't initialized yet, we can't do anything */	if ( ! video ) {		return SDL_GRAB_OFF;	}	/* Return the current mode on query */	if ( mode == SDL_GRAB_QUERY ) {		mode = video->input_grab;		if ( mode >= SDL_GRAB_FULLSCREEN ) {			mode -= SDL_GRAB_FULLSCREEN;		}		return(mode);	}#ifdef DEBUG_GRAB  printf("SDL_WM_GrabInput(%d) ... ", mode);#endif	/* If the video surface is fullscreen, we always grab */	if ( mode >= SDL_GRAB_FULLSCREEN ) {		mode -= SDL_GRAB_FULLSCREEN;	}	if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {		mode += SDL_GRAB_FULLSCREEN;	}	return(SDL_WM_GrabInputRaw(mode));}static SDL_GrabMode SDL_WM_GrabInputOff(void){	SDL_GrabMode mode;	/* First query the current grab state */	mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);	/* Now explicitly turn off input grab */	SDL_WM_GrabInputRaw(SDL_GRAB_OFF);	/* Return the old state */	return(mode);}/* * Iconify the window in window managed environments. * A successful iconification will result in an SDL_APPACTIVE loss event. */int SDL_WM_IconifyWindow(void){	SDL_VideoDevice *video = current_video;	SDL_VideoDevice *this  = current_video;	int retval;	retval = 0;	if ( video->IconifyWindow ) {		retval = video->IconifyWindow(this);	}	return(retval);}/* * Toggle fullscreen mode */int SDL_WM_ToggleFullScreen(SDL_Surface *surface){	SDL_VideoDevice *video = current_video;	SDL_VideoDevice *this  = current_video;	int toggled;	toggled = 0;	if ( SDL_PublicSurface && (surface == SDL_PublicSurface) &&	     video->ToggleFullScreen ) {		if ( surface->flags & SDL_FULLSCREEN ) {			toggled = video->ToggleFullScreen(this, 0);			if ( toggled ) {				SDL_VideoSurface->flags &= ~SDL_FULLSCREEN;				SDL_PublicSurface->flags &= ~SDL_FULLSCREEN;			}		} else {			toggled = video->ToggleFullScreen(this, 1);			if ( toggled ) {				SDL_VideoSurface->flags |= SDL_FULLSCREEN;				SDL_PublicSurface->flags |= SDL_FULLSCREEN;			}		}		/* Double-check the grab state inside SDL_WM_GrabInput() */		if ( toggled ) {			SDL_WM_GrabInput(video->input_grab);		}	}	return(toggled);}/* * Get some platform dependent window manager information */int SDL_GetWMInfo (SDL_SysWMinfo *info){	SDL_VideoDevice *video = current_video;	SDL_VideoDevice *this  = current_video;	if ( video && video->GetWMInfo ) {		return(video->GetWMInfo(this, info));	} else {		return(0);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -