本文整理汇总了C++中SDL_VideoModeOK函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_VideoModeOK函数的具体用法?C++ SDL_VideoModeOK怎么用?C++ SDL_VideoModeOK使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_VideoModeOK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resize
static rfbBool resize(rfbClient* client) {
static char first=TRUE;
#ifdef SDL_ASYNCBLIT
int flags=SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
#else
int flags=SDL_HWSURFACE|SDL_HWACCEL;
#endif
int width=client->width,height=client->height,
depth=client->format.bitsPerPixel;
client->updateRect.x = client->updateRect.y = 0;
client->updateRect.w = width; client->updateRect.h = height;
rfbBool okay=SDL_VideoModeOK(width,height,depth,flags);
if(!okay)
for(depth=24;!okay && depth>4;depth/=2)
okay=SDL_VideoModeOK(width,height,depth,flags);
if(okay) {
SDL_Surface* sdl=SDL_SetVideoMode(width,height,depth,flags);
rfbClientSetClientData(client, SDL_Init, sdl);
client->width = sdl->pitch / (depth / 8);
client->frameBuffer=sdl->pixels;
if(first || depth!=client->format.bitsPerPixel) {
first=FALSE;
client->format.bitsPerPixel=depth;
client->format.redShift=sdl->format->Rshift;
client->format.greenShift=sdl->format->Gshift;
client->format.blueShift=sdl->format->Bshift;
client->format.redMax=sdl->format->Rmask>>client->format.redShift;
client->format.greenMax=sdl->format->Gmask>>client->format.greenShift;
client->format.blueMax=sdl->format->Bmask>>client->format.blueShift;
SetFormatAndEncodings(client);
}
} else {
示例2: IMG_Load
Image* RenderBackendSDL::createMainScreen(unsigned int width, unsigned int height, unsigned char bitsPerPixel, bool fs, const std::string& title, const std::string& icon) {
Uint32 flags = 0;
if (fs) {
flags |= SDL_FULLSCREEN;
}
if(icon != "") {
SDL_Surface *img = IMG_Load(icon.c_str());
if(img != NULL) {
SDL_WM_SetIcon(img, 0);
}
}
SDL_Surface* screen = NULL;
if( 0 == bitsPerPixel ) {
/// autodetect best mode
unsigned char possibleBitsPerPixel[] = {16, 24, 32, 0};
int i = 0;
while( true ) {
bitsPerPixel = possibleBitsPerPixel[i];
if( !bitsPerPixel ) {
// Last try, sometimes VideoModeOK seems to lie.
// Try bpp=0
screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
if( !screen ) {
throw SDLException("Videomode not available");
}
break;
}
bitsPerPixel = SDL_VideoModeOK(width, height, bitsPerPixel, flags);
if ( bitsPerPixel ) {
screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
if( screen ) {
break;
}
}
++i;
}
} else {
if ( !SDL_VideoModeOK(width, height, bitsPerPixel, flags) ) {
throw SDLException("Videomode not available");
}
screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
}
FL_LOG(_log, LMsg("RenderBackendSDL")
<< "Videomode " << width << "x" << height
<< " at " << int(screen->format->BitsPerPixel) << " bpp");
SDL_WM_SetCaption(title.c_str(), NULL);
if (!screen) {
throw SDLException(SDL_GetError());
}
m_screen = new SDLImage(screen);
return m_screen;
}
示例3: create_and_open_screen
int create_and_open_screen(int sizex, int sizey, int bpp, int mode)
{
static bool first = true;
static bool dofree = false;
#ifndef WIN32
set_sdl_env();
#endif
if (dofree == true)
{
dofree = false;
SDL_FreeSurface(gfx->buff);
}
if (first == true)
{
if (!(gfx = (t_gfx*)malloc(sizeof(*gfx))))
{
printf("Out of memory.\n");
exit(42);
}
gfx->videoinfo = (SDL_VideoInfo *)SDL_GetVideoInfo();
first = false;
}
gfx->win = (t_display*)xmalloc(sizeof(*(gfx->win)));
#ifdef GRAPHICS_DEBUG
fprintf(fd_log, "Checking mode %dx%[email protected]%dbpp.\n", sizex, sizey, bpp);
#endif
gfx->bpp = SDL_VideoModeOK(sizex, sizey, bpp, mode);
if(!gfx->bpp)
{
#ifdef GRAPHICS_DEBUG
fprintf(fd_log, "Mode not available, trying another..\n");
#endif
gfx->bpp = SDL_VideoModeOK(sizex, sizey, bpp, SDL_ANYFORMAT);
if (!gfx->bpp)
return (-1);
if (!(gfx->main = SDL_SetVideoMode(sizex, sizey, bpp, mode | SDL_GLSDL)))
return (-1);
}
else if (!(gfx->main = SDL_SetVideoMode(sizex, sizey, bpp, mode | SDL_GLSDL)))
return (-1);
gfx->win->sdlMainScreen = gfx->main;
gfx->win->text = NULL;
SDL_WM_SetCaption("Freewar", "fw.ico");
gfx->buff = xSDL_DisplayFormatAlpha(gfx->main);
init_gfx();
if (init_fonts())
return (-1);
dofree = true;
return (0);
}
示例4: wm_fullscreen
/*
static int wm_fullscreen(int action, Display *disp, Window *win) {
#endif
XEvent xev;
xev.xclient.type = ClientMessage;
xev.xclient.serial = 0;
xev.xclient.send_event = True;
xev.xclient.message_type = XInternAtom( disp,
"_NET_WM_STATE", False );
xev.xclient.window = win;
xev.xclient.format = 32;
xev.xclient.data.1[0] = action;
xev.xclient.data.1[1] = XInternAtom( disp,
"_NET_WM_STATE_FULLSCREEN",False );
xev.xclient.data.1[2] = 0;
xev.xclient.data.1[3] = 0;
xev.xclient.data.1[4] = 0;
if( !XSendEvent( disp, DefaultRootWindow( disp ), False,
SubstructureRedirectMask |
SubstructureNotifyMask, &xev ) )
{
veejay_msg(0, "WM Fullscreen state failed");
return 0;
}
return 1;
}
*/
static void vj_sdl_move( vj_sdl *vjsdl , int display_wid, int display_hei, int scaled_width, int scaled_height, int x, int y )
{
//@ sw_scale_width is misleading ; it lets SDL use the BES
if (scaled_width)
vjsdl->sw_scale_width = scaled_width;
if (scaled_height)
vjsdl->sw_scale_height = scaled_height;
int my_bpp = SDL_VideoModeOK( display_wid, display_hei,24, vjsdl->flags[1] );
if(!my_bpp)
{
veejay_msg(VEEJAY_MSG_DEBUG, "Requested depth not supported");
return;
}
vjsdl->screen = SDL_SetVideoMode( display_wid, display_hei,my_bpp,vjsdl->flags[1]);
vjsdl->rectangle.x = x;
vjsdl->rectangle.y = y;
vjsdl->rectangle.w = scaled_width;
vjsdl->rectangle.h = scaled_height;
veejay_msg(VEEJAY_MSG_INFO, "Changed video window to size %d x %d (%dx%d+%dx%d)", display_wid, display_hei,
scaled_width,scaled_height,x,y);
}
示例5: setup
void setup(){
SDL_Surface *imagenCargada;
int bpp,i;
if(SDL_Init (SDL_INIT_VIDEO) < 0) {
fprintf(stderr,"No se pudo inicializar el sistema de video\n"
"El error devuelto fue %s\n",SDL_GetError());
exit(1);
}
bpp = SDL_VideoModeOK (WIDTH_SCREEN,HEIGHT_SCREEN, 16, 0);
if(bpp == 0){
fprintf(stderr,"Error: No se pudo establecer el video\n");
exit (1);
}
screen = SDL_SetVideoMode(WIDTH_SCREEN, HEIGHT_SCREEN, bpp, 0);
for(i = 0; i < TOTAL_IMAGENES ; i++){
imagenCargada = IMG_Load (imagesNames[i]);
if(imagenCargada == NULL){
fprintf(stderr,"Error al cargar : %s\n",SDL_GetError());
exit(1);
}
else{
SDL_SetColorKey (imagenCargada, SDL_SRCCOLORKEY,0xff00ff); // Establecer transparencia
images[i] = imagenCargada;
}
}
}
示例6: isDisplayModeAvailable
bool SDLDraw::isDisplayModeAvailable(int width, int height, int bpp)
{
if(SDL_VideoModeOK(width, height, bpp, 0 /*SDL_FULLSCREEN | SDL_DOUBLEBUF | SDL_HWSURFACE*/))
return true;
return false;
}
示例7: vj_sdl_resize
void vj_sdl_resize( vj_sdl *vjsdl , int scaled_width, int scaled_height, int fs )
{
//@ sw_scale_width is misleading ; it lets SDL use the BES
if (scaled_width)
vjsdl->sw_scale_width = scaled_width;
if (scaled_height)
vjsdl->sw_scale_height = scaled_height;
int my_bpp = SDL_VideoModeOK( vjsdl->sw_scale_width, vjsdl->sw_scale_height,24,
vjsdl->flags[fs] );
if(!my_bpp)
{
veejay_msg(VEEJAY_MSG_DEBUG, "Requested depth not supported");
return;
}
vjsdl->screen = SDL_SetVideoMode( vjsdl->sw_scale_width, vjsdl->sw_scale_height,my_bpp,
vjsdl->flags[fs]);
vjsdl->rectangle.x = 0;
vjsdl->rectangle.y = 0;
vjsdl->rectangle.w = scaled_width;
vjsdl->rectangle.h = scaled_height;
veejay_msg(VEEJAY_MSG_INFO, "Changed video window to size %d x %d",
vjsdl->sw_scale_width,vjsdl->sw_scale_height);
}
示例8: find_resolution
static void find_resolution() {
SDL_Rect **modes;
int i,bestw,besth,wantedw,wantedh;
wantedw=TCOD_ctx.fullscreen_width>TCOD_ctx.root->w*TCOD_ctx.font_width?TCOD_ctx.fullscreen_width:TCOD_ctx.root->w*TCOD_ctx.font_width;
wantedh=TCOD_ctx.fullscreen_height>TCOD_ctx.root->h*TCOD_ctx.font_height?TCOD_ctx.fullscreen_height:TCOD_ctx.root->h*TCOD_ctx.font_height;
TCOD_ctx.actual_fullscreen_width=wantedw;
TCOD_ctx.actual_fullscreen_height=wantedh;
modes=SDL_ListModes(NULL, SDL_FULLSCREEN);
bestw=99999;
besth=99999;
if(modes != (SDL_Rect **)0 && modes != (SDL_Rect **)-1){
for(i=0;modes[i];++i) {
if (modes[i]->w >= wantedw && modes[i]->w <= bestw
&& modes[i]->h >= wantedh && modes[i]->h <= besth
&& SDL_VideoModeOK(modes[i]->w, modes[i]->h, 32, SDL_FULLSCREEN)) {
bestw=modes[i]->w;
besth=modes[i]->h;
}
}
}
if ( bestw != 99999) {
TCOD_ctx.actual_fullscreen_width=bestw;
TCOD_ctx.actual_fullscreen_height=besth;
}
}
示例9: find_resolution
static void find_resolution() {
SDL_Rect **modes;
int i,bestw,besth,wantedw,wantedh;
wantedw=fullscreen_width>consoleWidth*fontWidth?fullscreen_width:consoleWidth*fontWidth;
wantedh=fullscreen_height>consoleHeight*fontHeight?fullscreen_height:consoleHeight*fontHeight;
actual_fullscreen_width=wantedw;
actual_fullscreen_height=wantedh;
modes=SDL_ListModes(NULL, SDL_FULLSCREEN);
bestw=99999;
besth=99999;
if(modes != (SDL_Rect **)0 && modes != (SDL_Rect **)-1){
for(i=0;modes[i];++i) {
if (modes[i]->w >= wantedw && modes[i]->w <= bestw
&& modes[i]->h >= wantedh && modes[i]->h <= besth
&& SDL_VideoModeOK(modes[i]->w, modes[i]->h, 32, SDL_FULLSCREEN)) {
bestw=modes[i]->w;
besth=modes[i]->h;
}
}
}
if ( bestw != 99999) {
actual_fullscreen_width=bestw;
actual_fullscreen_height=besth;
}
//printf ("resolution : %dx%d =>%dx%d\n",wantedw,wantedh,bestw,besth);
}
示例10: SDL_WM_SetCaption
/** Constructor.
* @param width width of image
* @param height height of image
* @param title window title
*/
ImageDisplay::ImageDisplay(unsigned int width, unsigned int height, const char *title)
{
SDLKeeper::init(SDL_INIT_VIDEO);
if (title)
SDL_WM_SetCaption(title, NULL);
_width = width;
_height = height;
int bpp = SDL_VideoModeOK(_width, _height, 16, SDL_ANYFORMAT);
_surface = SDL_SetVideoMode(width, height, bpp, /* flags */ SDL_HWSURFACE | SDL_ANYFORMAT);
if (!_surface) {
throw Exception("SDL: cannot create surface");
}
// SDL_UYVY_OVERLAY
_overlay = SDL_CreateYUVOverlay(width, height, SDL_UYVY_OVERLAY, _surface);
if (!_overlay) {
throw Exception("Cannot create overlay");
}
_rect = new SDL_Rect;
_rect->x = 0;
_rect->y = 0;
_rect->w = _width;
_rect->h = _height;
}
示例11: build_video_mode_array
void build_video_mode_array()
{
int i;
int flags;
if (full_screen)
flags=SDL_OPENGL|SDL_FULLSCREEN;
else
flags=SDL_OPENGL;
for(i = 0; i < video_modes_count; i++)
{
video_modes[i].flags.selected = 0;
video_modes[i].flags.supported = 0;
if(bpp == video_modes[i].bpp
#ifdef WINDOWS
|| full_screen
#endif
)
{
if (SDL_VideoModeOK(video_modes[i].width, video_modes[i].height, video_modes[i].bpp, flags))
video_modes[i].flags.supported = 1;
}
}
if (video_mode > 0)
video_modes[video_mode-1].flags.selected=1;
}
示例12: gl_createWindow
/**
* @brief Creates the OpenGL window.
*
* @return 0 on success.
*/
static int gl_createWindow( unsigned int flags )
{
int depth;
/* Test the setup - aim for 32. */
gl_screen.depth = 32;
depth = SDL_VideoModeOK( SCREEN_W, SCREEN_H, gl_screen.depth, flags);
if (depth == 0)
WARN("Video Mode %dx%d @ %d bpp not supported"
" going to try to create it anyways...",
SCREEN_W, SCREEN_H, gl_screen.depth );
if (depth != gl_screen.depth)
DEBUG("Depth %d bpp unavailable, will use %d bpp", gl_screen.depth, depth);
gl_screen.depth = depth;
/* Actually creating the screen. */
if (SDL_SetVideoMode( SCREEN_W, SCREEN_H, gl_screen.depth, flags)==NULL) {
/* Try again possibly disabling FSAA. */
if (conf.fsaa > 1) {
LOG("Unable to create OpenGL window: Trying without FSAA.");
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
}
if (SDL_SetVideoMode( SCREEN_W, SCREEN_H, gl_screen.depth, flags)==NULL) {
ERR("Unable to create OpenGL window: %s", SDL_GetError());
return -1;
}
}
gl_screen.rw = SCREEN_W;
gl_screen.rh = SCREEN_H;
gl_activated = 1; /* Opengl is now activated. */
return 0;
}
示例13: can_init_scaler
int can_init_scaler( unsigned int new_scaler, bool fullscreen )
{
if (new_scaler >= scalers_count)
return false;
int w = scalers[new_scaler].width,
h = scalers[new_scaler].height;
int flags = SDL_SWSURFACE | SDL_HWPALETTE | (fullscreen ? SDL_FULLSCREEN : 0);
// test each bitdepth
for (uint bpp = 32; bpp > 0; bpp -= 8)
{
uint temp_bpp = SDL_VideoModeOK(w, h, bpp, flags);
if ((temp_bpp == 32 && scalers[new_scaler].scaler32) ||
(temp_bpp == 16 && scalers[new_scaler].scaler16) ||
(temp_bpp == 8 && scalers[new_scaler].scaler8 ))
{
return temp_bpp;
}
else if (temp_bpp == 24 && scalers[new_scaler].scaler32)
{
// scalers don't support 24 bpp because it's a pain
// so let SDL handle the conversion
return 32;
}
}
return 0;
}
示例14: OglSdlSurface
bool OglSdlSurface()
{
Uint32 surfaceFlags;
if (NULL != vidSurface)
{
SDL_FreeSurface(vidSurface);
vidSurface = NULL;
#ifdef VOODOOSAFESWITCHING
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
#endif
}
if (cv_fullscreen.value)
surfaceFlags = SDL_OPENGL|SDL_FULLSCREEN;
else
surfaceFlags = SDL_OPENGL;
// We want at least 1 bit (???) for R, G, and B, and at least 16 bits for depth buffer.
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 1);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 1);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
int cbpp = SDL_VideoModeOK(vid.width, vid.height, vid.BitsPerPixel, surfaceFlags);
if (cbpp < 16)
return false;
if ((vidSurface = SDL_SetVideoMode(vid.width, vid.height, cbpp, surfaceFlags)) == NULL)
return false;
CONS_Printf("HWRend::Startup(): %dx%d %d bits\n", vid.width, vid.height, cbpp);
return true;
}
示例15: VID_ValidMode
/*
================
VID_ValidMode
================
*/
static qboolean VID_ValidMode (int width, int height, int bpp, qboolean fullscreen)
{
Uint32 flags = DEFAULT_SDL_FLAGS;
if (width < 320)
return false;
if (height < 200)
return false;
if (fullscreen)
flags |= SDL_FULLSCREEN;
bpp = SDL_VideoModeOK(width, height, bpp, flags);
switch (bpp)
{
case 16:
case 24:
case 32:
break;
default:
return false;
}
return true;
}