本文整理汇总了C++中SDL_GetVideoInfo函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetVideoInfo函数的具体用法?C++ SDL_GetVideoInfo怎么用?C++ SDL_GetVideoInfo使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_GetVideoInfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
visualiserWin::visualiserWin(int argc, char* argv[])
{
// Set the local members to default values.
this->desiredFrameRate = 0;
this->shouldVsync = true;
this->currentVis = NULL;
this->shouldCloseWindow = false;
this->width = 800;
this->height = 600;
bool fullscreen = false;
MPDMode = false;
mpdError = false;
char opt;
// Parse the options. Note, we don't check the default
// case as there may be other options that are specified
// for other parts of the program (such as visualisers).
opterr = 0;
while((opt = getopt(argc, argv, "s:fm:")) != -1)
{
switch(opt)
{
case 's': // Window Size.
{
char* tok = strtok(optarg, "x");
if(!tok)
throw(argException("Window size not formatted properly."));
// TODO: Use strtol as it has error checking.
width = atoi(tok);
tok = strtok(NULL, "x");
if(!tok)
throw(argException("Window size not formatted properly."));
height = atoi(tok);
break;
}
case 'f': // Fullscreen.
fullscreen = true;
break;
case 'm':
MPDFile = optarg;
MPDMode = true;
break;
}
}
// If fullscreen is set, detect the resolution.
if(fullscreen)
{
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
width = videoInfo->current_w;
height = videoInfo->current_h;
}
// Set the OpenGL attributes
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
if(shouldVsync)
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
// Create the DSP manmager
dspman = new DSPManager();
// Create the window
if(fullscreen)
drawContext = SDL_SetVideoMode(width, height, 0,
SDL_FULLSCREEN | SDL_OPENGL);
else
drawContext = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
if(drawContext == NULL)
throw(SDLException());
// also initialise the standard event handlers.
initialiseStockEventHandlers();
}
示例2: InitSDL
bool InitSDL(char* winName, int width, int height, int bpp, bool vsync, bool fscreen)
{
gLog.OutPut("\n[Initializing Video Settings]\n");
#ifdef USE_SDL2
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) < 0)
#else
const SDL_VideoInfo* info = NULL;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) < 0 || !(info = SDL_GetVideoInfo()))
#endif
{
gLog.OutPut("\n[Failed to initialize Video Settings]\n");
return false;
}
#ifdef USE_SDL2
int flags = SDL_WINDOW_OPENGL | (fscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:0);
#else
int flags = SDL_OPENGL | (fscreen?SDL_FULLSCREEN:0);
SDL_WM_SetIcon(SDL_LoadBMP("icon1.bmp"), NULL);
#endif
/* SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
// SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
*/
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 0);
#ifdef USE_SDL2
glWindow = SDL_CreateWindow("Prototype", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
if(!glWindow)
{
SDL_Quit();
return false;
}
glContext = SDL_GL_CreateContext(glWindow);
if(!glContext)
{
SDL_Quit();
return false;
}
SDL_SetWindowIcon(glWindow, SDL_LoadBMP("icon1.bmp"));
GetWindowSizeSDL2(width, height);
#else
if(SDL_SetVideoMode(width, height, bpp, flags) == 0)
{
SDL_Quit();
return false;
}
#endif
stringstream(str);
str << "Resolution Set: " << width << "x" << height << "x" << bpp << endl;
gLog.OutPut(str.str());
/* if(!vsync)
{
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT==NULL)
PostQuitMessage(0);
wglSwapIntervalEXT(0);
gLog.OutPut("Vsync Disabled.\n");
}
else
{
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT==NULL)
PostQuitMessage(0);
wglSwapIntervalEXT(1);
gLog.OutPut("Vsync Enabled.\n");
}
*/ SDL_ShowCursor(0);
#ifdef USE_SDL2
SDL_SetWindowTitle(glWindow, winName);
#else
SDL_WM_SetCaption(winName, NULL);
#endif
gLog.OutPut("Complete...\n\n");
return true;
}
示例3: jiveL_initSDL
static int jiveL_initSDL(lua_State *L) {
const SDL_VideoInfo *video_info;
#ifndef JIVE_NO_DISPLAY
JiveSurface *srf, *splash;
Uint16 splash_w, splash_h;
bool fullscreen = false;
char splashfile[32] = "jive/splash.png";
#endif
/* logging */
log_ui_draw = LOG_CATEGORY_GET("squeezeplay.ui.draw");
log_ui = LOG_CATEGORY_GET("squeezeplay.ui");
/* linux fbcon does not need a mouse */
SDL_putenv("SDL_NOMOUSE=1");
#ifdef JIVE_NO_DISPLAY
# define JIVE_SDL_FEATURES (SDL_INIT_EVENTLOOP)
#else
# define JIVE_SDL_FEATURES (SDL_INIT_VIDEO)
#endif
/* initialise SDL */
if (SDL_Init(JIVE_SDL_FEATURES) < 0) {
LOG_ERROR(log_ui_draw, "SDL_Init(V|T|A): %s\n", SDL_GetError());
SDL_Quit();
exit(-1);
}
/* report video info */
if ((video_info = SDL_GetVideoInfo())) {
LOG_INFO(log_ui_draw, "%d,%d %d bits/pixel %d bytes/pixel [R<<%d G<<%d B<<%d]", video_info->current_w, video_info->current_h, video_info->vfmt->BitsPerPixel, video_info->vfmt->BytesPerPixel, video_info->vfmt->Rshift, video_info->vfmt->Gshift, video_info->vfmt->Bshift);
LOG_INFO(log_ui_draw, "Hardware acceleration %s available", video_info->hw_available?"is":"is not");
LOG_INFO(log_ui_draw, "Window Manager %s available", video_info->wm_available?"is":"is not");
}
/* Register callback for additional events (used for multimedia keys)*/
SDL_EventState(SDL_SYSWMEVENT,SDL_ENABLE);
SDL_SetEventFilter(filter_events);
// Secific magic for windows|linux|macos
platform_init(L);
#ifndef JIVE_NO_DISPLAY
/* open window */
SDL_WM_SetCaption("SqueezePlay", "SqueezePlay");
SDL_ShowCursor(SDL_DISABLE);
SDL_EnableKeyRepeat (100, 100);
SDL_EnableUNICODE(1);
#ifdef SCREEN_ROTATION_ENABLED
screen_w = video_info->current_h;
screen_h = video_info->current_w;
#else
screen_w = video_info->current_w;
screen_h = video_info->current_h;
#endif
screen_bpp = video_info->vfmt->BitsPerPixel;
if (video_info->wm_available) {
/* desktop build */
JiveSurface *icon;
/* load the icon */
icon = jive_surface_load_image("jive/app.png");
if (icon) {
jive_surface_set_wm_icon(icon);
jive_surface_free(icon);
}
splash = jive_surface_load_image(splashfile);
if (splash) {
jive_surface_get_size(splash, &splash_w, &splash_h);
screen_w = splash_w;
screen_h = splash_h;
}
} else {
/* product build and full screen...*/
sprintf(splashfile, "jive/splash%dx%d.png", screen_w, screen_h);
splash = jive_surface_load_image(splashfile);
if(!splash) {
sprintf(splashfile,"jive/splash.png");
splash = jive_surface_load_image(splashfile);
}
if (splash) {
jive_surface_get_size(splash, &splash_w, &splash_h);
}
fullscreen = true;
}
srf = jive_surface_set_video_mode(screen_w, screen_h, screen_bpp, fullscreen);
if (!srf) {
LOG_ERROR(log_ui_draw, "Video mode not supported: %dx%d\n", screen_w, screen_h);
SDL_Quit();
//.........这里部分代码省略.........
示例4: main
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
fprintf(stderr, "Couldn't init SDL!\n");
atexit(SDL_Quit);
// Get the current desktop width & height
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
// TODO: get this from config file.
s_config = new Config(false, false, 768/2, 1024/2);
Config& config = *s_config;
config.title = "glyphblaster test";
// msaa
if (config.msaa)
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, config.msaaSamples);
}
SDL_Surface* screen;
if (config.fullscreen)
{
int width = videoInfo->current_w;
int height = videoInfo->current_h;
int bpp = videoInfo->vfmt->BitsPerPixel;
screen = SDL_SetVideoMode(width, height, bpp,
SDL_HWSURFACE | SDL_OPENGL | SDL_FULLSCREEN);
}
else
{
screen = SDL_SetVideoMode(config.width, config.height, 32, SDL_HWSURFACE | SDL_OPENGL);
}
SDL_WM_SetCaption(config.title.c_str(), config.title.c_str());
if (!screen)
fprintf(stderr, "Couldn't create SDL screen!\n");
// clear to white
Vector4f clearColor(0, 0, 0, 1);
glClearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapBuffers();
// create the context
GB_ERROR err;
GB_Context* gb;
err = GB_ContextMake(512, 3, GB_TEXTURE_FORMAT_ALPHA, &gb);
if (err != GB_ERROR_NONE) {
fprintf(stderr, "GB_Init Error %d\n", err);
exit(1);
}
// load lorem.txt
int fd = open("utf8-test.txt", O_RDONLY);
if (fd < 0) {
fprintf(stderr, "open failed\n");
exit(1);
}
struct stat s;
if (fstat(fd, &s) < 0) {
fprintf(stderr, "fstat failed\n errno = %d\n", errno);
exit(1);
}
const uint8_t* lorem = (uint8_t*)mmap(0, s.st_size + 1, PROT_READ, MAP_PRIVATE, fd, 0);
if (lorem < 0) {
fprintf(stderr, "mmap failed\n errno = %d\n", errno);
exit(1);
}
// we are lazy, don't unmap the file.
// create a font
GB_Font* mainFont = NULL;
//err = GB_FontMake(gb, "Droid-Sans/DroidSans.ttf", 20, GB_RENDER_NORMAL, GB_HINT_FORCE_AUTO, &mainFont);
//err = GB_FontMake(gb, "Arial.ttf", 48, GB_RENDER_NORMAL, GB_HINT_DEFAULT, &mainFont);
//err = GB_FontMake(gb, "Ayuthaya.ttf", 16, GB_RENDER_NORMAL, GB_HINT_DEFAULT, &mainFont);
err = GB_FontMake(gb, "dejavu-fonts-ttf-2.33/ttf/DejaVuSans.ttf", 10, GB_RENDER_NORMAL, GB_HINT_DEFAULT, &mainFont);
//err = GB_FontMake(gb, "Zar/XB Zar.ttf", 48, GB_RENDER_NORMAL, GB_HINT_DEFAULT, &mainFont);
//err = GB_FontMake(gb, "Times New Roman.ttf", 20, GB_RENDER_NORMAL, GB_HINT_FORCE_AUTO, &mainFont);
if (err != GB_ERROR_NONE) {
fprintf(stderr, "GB_MakeFont Error %s\n", GB_ErrorToString(err));
exit(1);
}
GB_Font* arabicFont = NULL;
/*
// create an arabic font
err = GB_FontMake(gb, "Zar/XB Zar.ttf", 48, &arabicFont);
if (err != GB_ERROR_NONE) {
fprintf(stderr, "GB_MakeFont Error %s\n", GB_ErrorToString(err));
exit(1);
}
*/
// create a text
uint32_t origin[2] = {0, 0};
//.........这里部分代码省略.........
示例5: scrnmng_create
BOOL scrnmng_create(int width, int height) {
char s[256];
const SDL_VideoInfo *vinfo;
SDL_Surface *surface;
SDL_PixelFormat *fmt;
BOOL r;
if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
fprintf(stderr, "Error: SDL_Init: %s\n", SDL_GetError());
return(FAILURE);
}
SDL_WM_SetCaption(app_name, app_name);
vinfo = SDL_GetVideoInfo();
if (vinfo == NULL) {
fprintf(stderr, "Error: SDL_GetVideoInfo: %s\n", SDL_GetError());
return(FAILURE);
}
SDL_VideoDriverName(s, sizeof(s));
surface = SDL_SetVideoMode(width, height, vinfo->vfmt->BitsPerPixel,
SDL_HWSURFACE | SDL_ANYFORMAT | SDL_DOUBLEBUF | SDL_FULLSCREEN);
if (surface == NULL) {
fprintf(stderr, "Error: SDL_SetVideoMode: %s\n", SDL_GetError());
return(FAILURE);
}
r = FALSE;
fmt = surface->format;
#if defined(SUPPORT_8BPP)
if (fmt->BitsPerPixel == 8) {
r = TRUE;
}
#endif
#if defined(SUPPORT_16BPP)
if ((fmt->BitsPerPixel == 16) && (fmt->Rmask == 0xf800) &&
(fmt->Gmask == 0x07e0) && (fmt->Bmask == 0x001f)) {
r = TRUE;
}
#endif
#if defined(SUPPORT_24BPP)
if (fmt->BitsPerPixel == 24) {
r = TRUE;
}
#endif
#if defined(SUPPORT_32BPP)
if (fmt->BitsPerPixel == 32) {
r = TRUE;
}
#endif
#if defined(SCREEN_BPP)
if (fmt->BitsPerPixel != SCREEN_BPP) {
r = FALSE;
}
#endif
if (r) {
scrnmng.enable = TRUE;
scrnmng.width = width;
scrnmng.height = height;
scrnmng.bpp = fmt->BitsPerPixel;
return(SUCCESS);
}
else {
fprintf(stderr, "Error: Bad screen mode");
return(FAILURE);
}
}
示例6: SDL_VERSION_ATLEAST
void SDLAppDisplay::toggleFullscreen() {
int width = this->width;
int height = this->height;
if(!fullscreen) {
//save windowed width and height
windowed_width = width;
windowed_height = height;
int fullscreen_width = desktop_width;
int fullscreen_height = desktop_height;
float aspect_ratio = fullscreen_width / (float) fullscreen_height;
// if the aspect ratio suggests the person is using multiple monitors
// find a supported resolution with a lower aspect ratio with the same
// fullscreen height
#if SDL_VERSION_ATLEAST(1,3,0)
// TODO: do something with the 1.3 API here
#else
if(aspect_ratio >= 2.5) {
SDL_Rect** modes = SDL_ListModes(0, SDLFlags(true));
if(modes != (SDL_Rect**)0 && modes != (SDL_Rect**)-1) {
for (int i=0; modes[i]; i++) {
if(modes[i]->h == fullscreen_height && (modes[i]->w/(float)modes[i]->h) < 2.5) {
fullscreen_width = modes[i]->w;
break;
}
}
}
}
#endif
width = fullscreen_width;
height = fullscreen_height;
} else {
//switch back to window dimensions, if known
if(windowed_width != 0) {
width = windowed_width;
height = windowed_height;
}
}
fullscreen = !fullscreen;
setVideoMode(width, height, fullscreen);
int resized_width, resized_height;
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_GetWindowSize(sdl_window, &resized_width, &resized_height);
#else
const SDL_VideoInfo* display_info = SDL_GetVideoInfo();
resized_width = display_info->current_w;
resized_height = display_info->current_h;
#endif
//set viewport to match what we ended up on
glViewport(0, 0, resized_width, resized_height);
this->width = resized_width;
this->height = resized_height;
}
示例7: main
int
main(int argc, char *argv[])
{
const SDL_VideoInfo *info;
int i, d, n;
const char *driver;
SDL_DisplayMode mode;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
int nmodes;
/* Print available video drivers */
n = SDL_GetNumVideoDrivers();
if (n == 0) {
printf("No built-in video drivers\n");
} else {
printf("Built-in video drivers:");
for (i = 0; i < n; ++i) {
if (i > 0) {
printf(",");
}
printf(" %s", SDL_GetVideoDriver(i));
}
printf("\n");
}
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
driver = SDL_GetCurrentVideoDriver();
if (driver) {
printf("Video driver: %s\n", driver);
}
printf("Number of displays: %d\n", SDL_GetNumVideoDisplays());
for (d = 0; d < SDL_GetNumVideoDisplays(); ++d) {
printf("Display %d:\n", d);
SDL_SelectVideoDisplay(d);
SDL_GetDesktopDisplayMode(&mode);
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask,
&Amask);
printf(" Current mode: %dx%[email protected]%dHz, %d bits-per-pixel\n", mode.w,
mode.h, mode.refresh_rate, bpp);
if (Rmask || Gmask || Bmask) {
printf(" Red Mask = 0x%.8x\n", Rmask);
printf(" Green Mask = 0x%.8x\n", Gmask);
printf(" Blue Mask = 0x%.8x\n", Bmask);
if (Amask)
printf(" Alpha Mask = 0x%.8x\n", Amask);
}
/* Print available fullscreen video modes */
nmodes = SDL_GetNumDisplayModes();
if (nmodes == 0) {
printf("No available fullscreen video modes\n");
} else {
printf(" Fullscreen video modes:\n");
for (i = 0; i < nmodes; ++i) {
SDL_GetDisplayMode(i, &mode);
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
&Gmask, &Bmask, &Amask);
printf(" Mode %d: %dx%[email protected]%dHz, %d bits-per-pixel\n", i,
mode.w, mode.h, mode.refresh_rate, bpp);
if (Rmask || Gmask || Bmask) {
printf(" Red Mask = 0x%.8x\n", Rmask);
printf(" Green Mask = 0x%.8x\n", Gmask);
printf(" Blue Mask = 0x%.8x\n", Bmask);
if (Amask)
printf(" Alpha Mask = 0x%.8x\n", Amask);
}
}
}
}
info = SDL_GetVideoInfo();
if (info->wm_available) {
printf("A window manager is available\n");
}
if (info->hw_available) {
printf("Hardware surfaces are available (%dK video memory)\n",
info->video_mem);
}
if (info->blit_hw) {
printf("Copy blits between hardware surfaces are accelerated\n");
}
if (info->blit_hw_CC) {
printf("Colorkey blits between hardware surfaces are accelerated\n");
}
if (info->blit_hw_A) {
printf("Alpha blits between hardware surfaces are accelerated\n");
}
if (info->blit_sw) {
printf
("Copy blits from software surfaces to hardware surfaces are accelerated\n");
}
if (info->blit_sw_CC) {
printf
("Colorkey blits from software surfaces to hardware surfaces are accelerated\n");
}
//.........这里部分代码省略.........
示例8: assert
void OSystem_SDL::initBackend() {
// Check if backend has not been initialized
assert(!_inited);
#if SDL_VERSION_ATLEAST(2, 0, 0)
const char *sdlDriverName = SDL_GetCurrentVideoDriver();
#else
const int maxNameLen = 20;
char sdlDriverName[maxNameLen];
sdlDriverName[0] = '\0';
SDL_VideoDriverName(sdlDriverName, maxNameLen);
#endif
// Using printf rather than debug() here as debug()/logging
// is not active by this point.
debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName);
// Create the default event source, in case a custom backend
// manager didn't provide one yet.
if (_eventSource == 0)
_eventSource = new SdlEventSource();
#ifdef USE_OPENGL
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_DisplayMode displayMode;
if (!SDL_GetDesktopDisplayMode(0, &displayMode)) {
_desktopWidth = displayMode.w;
_desktopHeight = displayMode.h;
}
#else
// Query the desktop resolution. We simply hope nothing tried to change
// the resolution so far.
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo && videoInfo->current_w > 0 && videoInfo->current_h > 0) {
_desktopWidth = videoInfo->current_w;
_desktopHeight = videoInfo->current_h;
}
#endif
#endif
if (_graphicsManager == 0) {
#ifdef USE_OPENGL
// Setup a list with both SDL and OpenGL graphics modes. We only do
// this whenever the subclass did not already set up an graphics
// manager yet. This is because we don't know the type of the graphics
// manager of the subclass, thus we cannot easily switch between the
// OpenGL one and the set up one. It also is to be expected that the
// subclass does not want any switching of graphics managers anyway.
setupGraphicsModes();
if (ConfMan.hasKey("gfx_mode")) {
// If the gfx_mode is from OpenGL, create the OpenGL graphics manager
Common::String gfxMode(ConfMan.get("gfx_mode"));
for (uint i = _firstGLMode; i < _graphicsModeIds.size(); ++i) {
if (!scumm_stricmp(_graphicsModes[i].name, gfxMode.c_str())) {
_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource, _window);
_graphicsMode = i;
break;
}
}
}
#endif
if (_graphicsManager == 0) {
_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource, _window);
}
}
if (_savefileManager == 0)
_savefileManager = new DefaultSaveFileManager();
if (_mixerManager == 0) {
_mixerManager = new SdlMixerManager();
// Setup and start mixer
_mixerManager->init();
}
#ifdef ENABLE_EVENTRECORDER
g_eventRec.registerMixerManager(_mixerManager);
g_eventRec.registerTimerManager(new SdlTimerManager());
#else
if (_timerManager == 0)
_timerManager = new SdlTimerManager();
#endif
_audiocdManager = createAudioCDManager();
// Setup a custom program icon.
_window->setupIcon();
_inited = true;
ModularBackend::initBackend();
// We have to initialize the graphics manager before the event manager
// so the virtual keyboard can be initialized, but we have to add the
// graphics manager as an event observer after initializing the event
// manager.
dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager();
}
示例9: TRanrotBGenerator
SDL_Surface *initialization(int flags)
{
const SDL_VideoInfo* info = 0;
int bpp = 0;
SDL_Surface *screen;
rg = new TRanrotBGenerator(0);
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Initializing SDL\n");
#endif
if (SDL_Init(SDL_INIT_VIDEO | (sound ? SDL_INIT_AUDIO : 0) | SDL_INIT_JOYSTICK | SDL_INIT_EVENTTHREAD) < 0) {
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Video initialization failed: %s\n", SDL_GetError());
#endif
return 0;
}
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("SDL initialized\n");
#endif
info = SDL_GetVideoInfo();
if (!info) {
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Video query failed: %s\n", SDL_GetError());
#endif
return 0;
}
if (fullscreen) {
bpp = COLOUR_DEPTH;
} else {
bpp = info->vfmt->BitsPerPixel;
}
desktopW = info->current_w;
desktopH = info->current_h;
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Setting OpenGL attributes\n");
#endif
#ifndef HAVE_GLES
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#endif
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("OpenGL attributes set\n");
#endif
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Initializing video mode\n");
#endif
#ifdef HAVE_GLES
fullscreen = true;
flags = SDL_FULLSCREEN;
#else
flags = SDL_OPENGL | flags;
#endif
screen = SDL_SetVideoMode((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y, bpp, flags);
if (screen == 0) {
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Video mode set failed: %s\n", SDL_GetError());
#endif
return 0;
}
#ifdef HAVE_GLES
EGL_Open((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y);
#endif
#ifdef F1SPIRIT_DEBUG_MESSAGES
output_debug_message("Video mode initialized\n");
#endif
calcMinMax((fullscreen)?desktopW:SCREEN_X, (fullscreen)?desktopH:SCREEN_Y);
SDL_WM_SetCaption(application_name, 0);
SDL_WM_SetIcon(SDL_LoadBMP("graphics/f1sicon.bmp"), NULL);
SDL_ShowCursor(SDL_DISABLE);
if (sound) {
//.........这里部分代码省略.........
示例10: initsystem
//
// initsystem() -- init SDL systems
//
int initsystem(void)
{
const SDL_VideoInfo *vid;
const SDL_version *linked = SDL_Linked_Version();
SDL_version compiled;
char drvname[32];
SDL_VERSION(&compiled);
initprintf("Initialising SDL system interface "
"(compiled with SDL version %d.%d.%d, DLL version %d.%d.%d)\n",
linked->major, linked->minor, linked->patch,
compiled.major, compiled.minor, compiled.patch);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER
#ifdef NOSDLPARACHUTE
| SDL_INIT_NOPARACHUTE
#endif
)) {
initprintf("Initialisation failed! (%s)\n", SDL_GetError());
return -1;
}
atexit(uninitsystem);
frameplace = 0;
lockcount = 0;
#ifdef USE_OPENGL
if (loadgldriver(getenv("BUILD_GLDRV"))) {
#if MEGAWANG
initprintf("Failed loading OpenGL driver. Exiting...\n");
return 1;
#else
initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n");
nogl = 1;
#endif
}
#endif
#if !MEGAWANG
#ifndef __APPLE__
{
SDL_Surface *icon;
//icon = loadtarga("icon.tga");
icon = loadappicon();
if (icon) {
SDL_WM_SetIcon(icon, 0);
SDL_FreeSurface(icon);
}
}
#endif
#endif
if (SDL_VideoDriverName(drvname, 32))
initprintf("Using \"%s\" video driver\n", drvname);
// dump a quick summary of the graphics hardware
#ifdef DEBUGGINGAIDS
vid = SDL_GetVideoInfo();
initprintf("Video device information:\n");
initprintf(" Can create hardware surfaces? %s\n", (vid->hw_available)?"Yes":"No");
initprintf(" Window manager available? %s\n", (vid->wm_available)?"Yes":"No");
initprintf(" Accelerated hardware blits? %s\n", (vid->blit_hw)?"Yes":"No");
initprintf(" Accelerated hardware colourkey blits? %s\n", (vid->blit_hw_CC)?"Yes":"No");
initprintf(" Accelerated hardware alpha blits? %s\n", (vid->blit_hw_A)?"Yes":"No");
initprintf(" Accelerated software blits? %s\n", (vid->blit_sw)?"Yes":"No");
initprintf(" Accelerated software colourkey blits? %s\n", (vid->blit_sw_CC)?"Yes":"No");
initprintf(" Accelerated software alpha blits? %s\n", (vid->blit_sw_A)?"Yes":"No");
initprintf(" Accelerated colour fills? %s\n", (vid->blit_fill)?"Yes":"No");
initprintf(" Total video memory: %dKB\n", vid->video_mem);
#endif
return 0;
}
示例11: render_window
void render_window()
{
game_config = GetGameConfig();
game_levels = GetGameLevels();
game_levels_count = GetGameLevelsCount();
arguments = GetArguments();
user_set = GetUserSettings();
int start_level = get_start_level();
save_dir_full = GetSaveDir();
cache_dir_full = GetCacheDir();
can_cache = (save_dir_full && cache_dir_full);
//------------------------------------------------------------------------------
ApplyArguments();
const SDL_VideoInfo *video_info = SDL_GetVideoInfo();
if (user_set->geom_x > 0 && user_set->geom_y > 0)
{
disp_x = user_set->geom_x;
disp_y = user_set->geom_y;
}
else
{
disp_x = video_info->current_w;
disp_y = video_info->current_h;
}
int probe_bpp = (user_set->bpp == 0 ? video_info->vfmt->BitsPerPixel : user_set->bpp);
disp_bpp = (probe_bpp == 32 ? probe_bpp : 16);
bool rot = TransformGeom();
//------------------------------------------------------------------------------
#define BTN_SPACE_KOEF 4.5
int btn_side = disp_y / 7;
int btn_space = btn_side / BTN_SPACE_KOEF;
int btns_padded_width = btn_side * 4 + btn_space * 5;
if (btns_padded_width > disp_x)
{
//btn_side = ( wnd_w - 5 * ( btn_side / BTN_SPACE_KOEF ) ) / 4
btn_side = (int)(disp_x / (4 + 5 / BTN_SPACE_KOEF));
btn_space = btn_side / BTN_SPACE_KOEF;
}
int btns_width = btn_side * 4 + btn_space * 3;
int font_height = btn_side / 3;
int font_padding = font_height / 2;
//-- font and labels -----------------------------------------------------------
TTF_Font *font = TTF_OpenFont(DEFAULT_FONT_FILE, font_height);
if (!font)
{
log_error("Can't load font '%s'. Exiting.", DEFAULT_FONT_FILE);
return;
}
SDL_Surface *levelTextSurface = NULL;
SDL_Rect levelTextLocation;
levelTextLocation.y = font_padding;
SDL_Color fontColor = {0};
#ifndef RGBSWAP
fontColor.r = 231;
fontColor.g = 190;
fontColor.b = 114;
#else
//--enable-rgb-swap
fontColor.r = 114;
fontColor.g = 190;
fontColor.b = 231;
#endif
/* Window initialization */
ingame = true;
Uint32 sdl_flags = SDL_SWSURFACE;
if (user_set->fullscreen_mode != FULLSCREEN_NONE)
sdl_flags |= SDL_FULLSCREEN;
SDL_Surface *disp = SDL_SetVideoMode(disp_x, disp_y, disp_bpp, sdl_flags);
if (disp == NULL)
{
log_error("Can't set video mode %dx%dx%dbpp. Exiting.", disp_x, disp_y, disp_bpp);
return;
}
screen = disp;
SDL_Surface *gui_surface = disp;
SDL_WM_SetCaption("Mokomaze", "Mokomaze");
/* Draw loading screen */
SDL_Color whiteColor = {0};
whiteColor.r = whiteColor.g = whiteColor.b = 255;
SDL_Surface *titleSurface = TTF_RenderText_Blended(font, "Loading...", whiteColor);
SDL_Rect title_rect;
title_rect.x = (disp_x - titleSurface->w) / 2;
title_rect.y = (disp_y - titleSurface->h) / 2;
title_rect.w = titleSurface->w;
title_rect.h = titleSurface->h;
SDL_BlitSurface(titleSurface, NULL, screen, &title_rect);
SDL_UpdateRect(screen, title_rect.x, title_rect.y, title_rect.w, title_rect.h);
SDL_FreeSurface(titleSurface);
//.........这里部分代码省略.........
示例12: fprintf
SDL_Surface *initsdl(int *w,int *h,int *bppp,Uint32 flags)
{
// SDL_INIT_EVENTTHREAD
if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
exit( 1 );
}
SDL_Surface *s;
static int bpp=0;
Uint32 video_flags;
video_flags = flags;
int rgb_size[3]={0,0,0};
printf("yoyoyo\n");
if (flags& SDL_OPENGL)
{
/*
if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
bpp = 8;
} else {
bpp = 16; // More doesn't seem to work
}*/
bpp=SDL_GetVideoInfo()->vfmt->BitsPerPixel;
switch (bpp) {
case 8:
rgb_size[0] = 3;
rgb_size[1] = 3;
rgb_size[2] = 2;
break;
case 15:
case 16:
rgb_size[0] = 5;
rgb_size[1] = 5;
rgb_size[2] = 5;
break;
default:
rgb_size[0] = 8;
rgb_size[1] = 8;
rgb_size[2] = 8;
break;
}
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
}
video_flags|=(SDL_RESIZABLE|SDL_ANYFORMAT|SDL_DOUBLEBUF);
s= SDL_SetVideoMode( *w, *h, bpp, video_flags );
if (s == NULL ) {
fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
SDL_Quit();
exit(1);
}
#ifdef chaos
printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
printf("\n");
#ifdef GL
printf( "Vendor : %s\n", glGetString( GL_VENDOR ) );
printf( "Renderer : %s\n", glGetString( GL_RENDERER ) );
printf( "Version : %s\n", glGetString( GL_VERSION ) );
printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
printf("\n");
int value;
SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &value );
printf( "SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0],value);
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &value );
printf( "SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1],value);
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &value );
printf( "SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2],value);
SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &value );
printf( "SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value );
SDL_GL_GetAttribute( SDL_GL_DOUBLEBUFFER, &value );
printf( "SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value );
#endif
#endif
printf("mustlock=%i\n", SDL_MUSTLOCK(s));
const SDL_VideoInfo* m = SDL_GetVideoInfo();
*w=m->current_w;
*h=m->current_h;
*bppp=bpp;
char * x= (char*)malloc(20);
if(x&&SDL_VideoDriverName(x,20))
printf("Current SDL video driver is %s.\n",x);
printf("%i x %i\n",*w,*h);
return s;
}
示例13: GraphicsInit
/***************************
GraphicsInit: Initializes the graphic system
****************************/
void GraphicsInit(void)
{
const SDL_VideoInfo* video_info = SDL_GetVideoInfo();
Uint32 surface_mode = 0;
DEBUGCODE
{ fprintf(stderr, "Entering GraphicsInit()\n"); };
//Set application's icon:
seticon();
//Set caption:
SDL_WM_SetCaption("Tux Typing", "TuxType");
if (video_info->hw_available)
{
surface_mode = SDL_HWSURFACE;
LOG("HW mode\n");
}
else
{
surface_mode = SDL_SWSURFACE;
LOG("SW mode\n");
}
// Determine the current resolution: this will be used as the
// fullscreen resolution, if the user wants fullscreen.
DEBUGCODE
{
fprintf(stderr, "Current resolution: w %d, h %d.\n",
video_info->current_w, video_info->current_h);
}
/* For fullscreen, we try to use current resolution from OS: */
fs_res_x = video_info->current_w;
fs_res_y = video_info->current_h;
if (settings.fullscreen == 1)
{
screen = SDL_SetVideoMode(fs_res_x, fs_res_y, BPP, SDL_FULLSCREEN | surface_mode);
if (screen == NULL)
{
fprintf(stderr,
"\nWarning: I could not open the display in fullscreen mode.\n"
"The Simple DirectMedia error that occured was:\n"
"%s\n\n", SDL_GetError());
settings.fullscreen = 0;
}
}
/* Either fullscreen not requested, or couldn't get fullscreen in SDL: */
if (settings.fullscreen == 0)
{
screen = SDL_SetVideoMode(RES_X, RES_Y, BPP, surface_mode);
}
/* Failed to get a usable screen - must bail out! */
if (screen == NULL)
{
fprintf(stderr,
"\nError: I could not open the display.\n"
"The Simple DirectMedia error that occured was:\n"
"%s\n\n", SDL_GetError());
exit(2);
}
InitBlitQueue();
DEBUGCODE
{
video_info = SDL_GetVideoInfo();
fprintf(stderr, "-SDL VidMode successfully set to %ix%ix%i\n",
video_info->current_w,
video_info->current_h,
video_info->vfmt->BitsPerPixel);
}
LOG( "GraphicsInit():END\n" );
}
示例14: PAL_MouseEventFilter
/**
* Handle mouse events.
*
* @param[in] lpEvent - pointer to the event.
* @return None
*/
static VOID PAL_MouseEventFilter(const SDL_Event *lpEvent)
{
#ifdef PAL_HAS_MOUSE
static short hitTest = 0; // Double click detect;
const SDL_VideoInfo *vi;
double screenWidth, gridWidth;
double screenHeight, gridHeight;
double mx, my;
double thumbx;
double thumby;
INT gridIndex;
BOOL isLeftMouseDBClick = FALSE;
BOOL isLeftMouseClick = FALSE;
BOOL isRightMouseClick = FALSE;
static INT lastReleaseButtonTime, lastPressButtonTime, betweenTime;
static INT lastPressx = 0;
static INT lastPressy = 0;
static INT lastReleasex = 0;
static INT lastReleasey = 0;
if (lpEvent->type!= SDL_MOUSEBUTTONDOWN && lpEvent->type != SDL_MOUSEBUTTONUP)
return;
vi = SDL_GetVideoInfo();
screenWidth = vi->current_w;
screenHeight = vi->current_h;
gridWidth = screenWidth / 3;
gridHeight = screenHeight / 3;
mx = lpEvent->button.x;
my = lpEvent->button.y;
thumbx = ceil(mx / gridWidth);
thumby = floor(my / gridHeight);
gridIndex = thumbx + thumby * 3 - 1;
switch (lpEvent->type)
{
case SDL_MOUSEBUTTONDOWN:
lastPressButtonTime = SDL_GetTicks();
lastPressx = lpEvent->button.x;
lastPressy = lpEvent->button.y;
switch (gridIndex)
{
case 2:
g_InputState.prevdir = g_InputState.dir;
g_InputState.dir = kDirNorth;
break;
case 6:
g_InputState.prevdir = g_InputState.dir;
g_InputState.dir = kDirSouth;
break;
case 0:
g_InputState.prevdir = g_InputState.dir;
g_InputState.dir = kDirWest;
break;
case 8:
g_InputState.prevdir = g_InputState.dir;
g_InputState.dir = kDirEast;
break;
case 1:
//g_InputState.prevdir = g_InputState.dir;
//g_InputState.dir = kDirNorth;
g_InputState.dwKeyPress |= kKeyUp;
break;
case 7:
//g_InputState.prevdir = g_InputState.dir;
//g_InputState.dir = kDirSouth;
g_InputState.dwKeyPress |= kKeyDown;
break;
case 3:
//g_InputState.prevdir = g_InputState.dir;
//g_InputState.dir = kDirWest;
g_InputState.dwKeyPress |= kKeyLeft;
break;
case 5:
//g_InputState.prevdir = g_InputState.dir;
//g_InputState.dir = kDirEast;
g_InputState.dwKeyPress |= kKeyRight;
break;
}
break;
case SDL_MOUSEBUTTONUP:
lastReleaseButtonTime = SDL_GetTicks();
lastReleasex = lpEvent->button.x;
lastReleasey = lpEvent->button.y;
hitTest ++;
if (abs(lastPressx - lastReleasex) < 25 &&
abs(lastPressy - lastReleasey) < 25)
{
betweenTime = lastReleaseButtonTime - lastPressButtonTime;
if (betweenTime >500)
{
isRightMouseClick = TRUE;
}
//.........这里部分代码省略.........
示例15: init_video
void init_video()
{
char str[400];
int rgb_size[3];
setup_video_mode(full_screen, video_mode);
/* Detect the display depth */
if(!bpp)
{
if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 )
{
bpp = 8;
}
else
if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 16 )
{
bpp = 16; /* More doesn't seem to work */
}
else bpp=32;
}
//adjust the video mode accordingly
if (video_mode == 0)
{
//do nothing
} else if(bpp==16) {
if(!(video_mode%2))
video_mode-=1;
} else {
if(video_mode%2)
video_mode+=1;
}
/* Initialize the display */
switch (bpp) {
case 8:
rgb_size[0] = 2;
rgb_size[1] = 3;
rgb_size[2] = 3;
break;
case 15:
case 16:
rgb_size[0] = 5;
rgb_size[1] = 5;
rgb_size[2] = 5;
break;
default:
rgb_size[0] = 8;
rgb_size[1] = 8;
rgb_size[2] = 8;
break;
}
// Mac OS X will always use 8-8-8-8 ARGB for 32-bit screens and 5-5-5 RGB for 16-bit screens
#ifndef OSX
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
#endif
#ifdef OSX
// enable V-SYNC
SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 1 );
#endif
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
#ifdef FSAA
if (fsaa > 1)
{
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
glDisable(GL_MULTISAMPLE);
}
#endif /* FSAA */
check_gl_mode();
#ifdef OTHER_LIFE
SDL_WM_SetIcon(SDL_LoadBMP("ol_icon.bmp"), NULL);
#else
SDL_WM_SetIcon(SDL_LoadBMP("icon.bmp"), NULL);
#endif
/* Set the window manager title bar */
#ifdef FSAA
if (fsaa > 1)
{
if (!SDL_SetVideoMode(window_width, window_height, bpp, flags))
{
safe_snprintf(str, sizeof(str), "Can't use fsaa mode x%d, disabling it.", fsaa);
LOG_TO_CONSOLE(c_yellow1, str);
LOG_WARNING("%s\n", str);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
fsaa = 0;
}
}
#endif /* FSAA */
//try to find a stencil buffer (it doesn't always work on Linux)
if(!SDL_SetVideoMode(window_width, window_height, bpp, flags))
//.........这里部分代码省略.........