本文整理汇总了C++中SDL_GL_GetAttribute函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GL_GetAttribute函数的具体用法?C++ SDL_GL_GetAttribute怎么用?C++ SDL_GL_GetAttribute使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_GL_GetAttribute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( int argc, char *argv[ ] )
{
SDL_Window *window;
if( SDL_Init( SDL_INIT_VIDEO ) == -1 )
{
printf( "Can't init SDL: %s\n", SDL_GetError( ) );
return EXIT_FAILURE;
}
if( SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) == -1)
{
printf( "Can't set attribute DOUBLE BUFFER : %s\n", SDL_GetError( ) );
return EXIT_FAILURE;
}
atexit( SDL_Quit );
SDL_Surface *surface;
window = SDL_CreateWindow("Ma fenêtre de jeu", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );
SDL_GLContext *glcontext;
glcontext = SDL_GL_CreateContext(window);
int nValue;
if( SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &nValue) < 0)
{
printf("Echec de recuperation du parametre SDL_GL_DOUBLEBUFFER : %s\n", SDL_GetError());
return (EXIT_FAILURE);
}
// assurons nous que le mode "double buffer" est bien actif
if(nValue != 1)
{
printf("Erreur : SDL_GL_DOUBLEBUFFER inactif : %d\n", nValue);
return (EXIT_FAILURE);
}
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &nValue);
printf("Depth %d\n", nValue);
surface = SDL_GetWindowSurface(window);
if( surface == NULL )
{
printf( "Can't set video mode: %s\n", SDL_GetError( ) );
return EXIT_FAILURE;
}
opengl_init();
// Main loop
SDL_Event event;
while(1)
{
opengl_clear(window);
// Check for messages
if (SDL_PollEvent(&event))
{
// Check for the quit message
switch (event.type)
{
case SDL_QUIT:
SDL_Quit();
return EXIT_SUCCESS;// Quit the program
break;
case SDL_KEYUP:
case SDL_KEYDOWN:
//printf("keydown %d\n", event.key.keysym.sym);
switch(event.key.keysym.sym)
{
case SDLK_DOWN:
t_y += (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
printf("y = %f\n", t_y);
break;
case SDLK_UP:
t_y -= (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
printf("y = %f\n", t_y);
break;
case SDLK_LEFT:
t_x += (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
printf("y = %f\n", t_x);
break;
case SDLK_RIGHT:
t_x -= (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
printf("x = %f\n", t_x);
break;
case SDLK_PAGEUP:
t_z += (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
printf("z = %f\n", t_z);
break;
case SDLK_PAGEDOWN:
t_z -= (event.type == SDL_KEYDOWN ? SPEED_RATE : 0);
printf("z = %f\n", t_z);
break;
case SDLK_ESCAPE:
SDL_Quit();
return EXIT_SUCCESS;// Quit the program
break;
}
//printf("speed %f\n", rotationspeed);
//.........这里部分代码省略.........
示例2: mprintf
std::unique_ptr<os::OpenGLContext> SDLGraphicsOperations::createOpenGLContext(const os::OpenGLContextAttributes& attrs,
uint32_t width,
uint32_t height) {
mprintf((" Initializing SDL video...\n"));
#ifdef SCP_UNIX
// Slight hack to make Mesa advertise S3TC support without libtxc_dxtn
setenv("force_s3tc_enable", "true", 1);
#endif
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
Error(LOCATION, "Couldn't init SDL video: %s", SDL_GetError());
return nullptr;
}
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, attrs.red_size);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, attrs.green_size);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, attrs.blue_size);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, attrs.depth_size);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, attrs.stencil_size);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (attrs.multi_samples == 0) ? 0 : 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, attrs.multi_samples);
mprintf((" Requested SDL Video values = R: %d, G: %d, B: %d, depth: %d, stencil: %d, double-buffer: %d, FSAA: %d\n",
attrs.red_size, attrs.green_size, attrs.blue_size, attrs.depth_size, attrs.stencil_size, 1, attrs.multi_samples));
uint32_t windowflags = SDL_WINDOW_OPENGL;
if (Cmdline_fullscreen_window) {
windowflags |= SDL_WINDOW_BORDERLESS;
}
uint display = os_config_read_uint("Video", "Display", 0);
SDL_Window* window =
SDL_CreateWindow(Osreg_title, SDL_WINDOWPOS_CENTERED_DISPLAY(display), SDL_WINDOWPOS_CENTERED_DISPLAY(display),
width, height, windowflags);
if (window == nullptr) {
Error(LOCATION, "Could not create window: %s\n", SDL_GetError());
return nullptr;
}
os_set_window(window);
auto ctx = SDL_GL_CreateContext(os_get_window());
if (ctx == nullptr) {
Error(LOCATION, "Could not create OpenGL Context: %s\n", SDL_GetError());
return nullptr;
}
int r, g, b, depth, stencil, db, fsaa_samples;
SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r);
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g);
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b);
SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth);
SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &db);
SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil);
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &fsaa_samples);
mprintf((" Actual SDL Video values = R: %d, G: %d, B: %d, depth: %d, stencil: %d, double-buffer: %d, FSAA: %d\n",
r, g, b, depth, stencil, db, fsaa_samples));
return std::unique_ptr<os::OpenGLContext>(new SDLOpenGLContext(ctx));
}
示例3: main
int main( int argc, char **argv )
{
MemStartCheck();
{ char* test = new char[16]; delete [] test; }
SDL_Surface *surface = 0;
// SDL initialization steps.
if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK ) < 0 )
{
fprintf( stderr, "SDL initialization failed: %s\n", SDL_GetError( ) );
exit( 1 );
}
SDL_EnableKeyRepeat( 0, 0 );
SDL_EnableUNICODE( 1 );
const SDL_version* sversion = SDL_Linked_Version();
GLOUTPUT(( "SDL: major %d minor %d patch %d\n", sversion->major, sversion->minor, sversion->patch ));
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
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);
if ( multisample ) {
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 );
SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, multisample );
}
int videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
if ( fullscreen )
videoFlags |= SDL_FULLSCREEN;
else
videoFlags |= SDL_RESIZABLE;
#ifdef TEST_ROTATION
screenWidth = SCREEN_WIDTH;
screenHeight = SCREEN_HEIGHT;
#else
screenWidth = SCREEN_HEIGHT;
screenHeight = SCREEN_WIDTH;
#endif
if ( argc == 3 ) {
screenWidth = atoi( argv[1] );
screenHeight = atoi( argv[2] );
if ( screenWidth <= 0 ) screenWidth = IPOD_SCREEN_WIDTH;
if ( screenHeight <= 0 ) screenHeight = IPOD_SCREEN_HEIGHT;
}
// Note that our output surface is rotated from the iPod.
//surface = SDL_SetVideoMode( IPOD_SCREEN_HEIGHT, IPOD_SCREEN_WIDTH, 32, videoFlags );
surface = SDL_SetVideoMode( screenWidth, screenHeight, 32, videoFlags );
GLASSERT( surface );
int stencil = 0;
int depth = 0;
SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &stencil );
glGetIntegerv( GL_DEPTH_BITS, &depth );
GLOUTPUT(( "SDL surface created. w=%d h=%d bpp=%d stencil=%d depthBits=%d\n",
surface->w, surface->h, surface->format->BitsPerPixel, stencil, depth ));
/* Verify there is a surface */
if ( !surface ) {
fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
exit( 1 );
}
SDL_JoystickEventState(SDL_ENABLE);
SDL_Joystick* joystick = SDL_JoystickOpen(0);
if ( joystick ) {
GLOUTPUT(( "Joystick '%s' open.\n", SDL_JoystickName(0) ));
}
int r = glewInit();
GLASSERT( r == GL_NO_ERROR );
// Calling this seems to confuse my ATI driver and cause lag / event back up?
//#ifdef TEST_FULLSPEED
// wglSwapIntervalEXT( 0 ); // vsync
//#else
// wglSwapIntervalEXT( 1 ); // vsync
//#endif
const unsigned char* vendor = glGetString( GL_VENDOR );
const unsigned char* renderer = glGetString( GL_RENDERER );
const unsigned char* version = glGetString( GL_VERSION );
GLOUTPUT(( "OpenGL vendor: '%s' Renderer: '%s' Version: '%s'\n", vendor, renderer, version ));
Audio_Init();
bool done = false;
bool zooming = false;
SDL_Event event;
float yRotation = 45.0f;
//.........这里部分代码省略.........
示例4: SDL_GL_SetSwapInterval
void CRenderManager::InitGL()
{
// VSYNC OFF
SDL_GL_SetSwapInterval(0);
ogl_LoadFunctions();
// DEBUG OPENGL... not ready yet
//if (InitGLDebugFunctions()) CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_VIDEO,"OpenGL Error Checking: ENABLED");
int l_red, l_green, l_blue, l_alpha;
SDL_GL_GetAttribute(SDL_GL_RED_SIZE,&l_red);
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE,&l_green);
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE,&l_blue);
SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE,&l_alpha);
CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_VIDEO,"Framebuffer Bytes Info-> R:%d G:%d B:%d: A:%d",l_red, l_green, l_blue, l_alpha);
char *l_vendor = (char*) glGetString(GL_VENDOR);
char *l_renderer =(char*) glGetString(GL_RENDERER);
char *l_version = (char*)glGetString(GL_VERSION);
char *l_glsl = (char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_VIDEO,"Renderer: %s", l_renderer);
CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_VIDEO,"Vendor: %s", l_vendor);
CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_VIDEO,"Version: %s", l_version);
CCoreEngine::Instance().GetLogManager().LogOutput( LOG_INFO, LOGSUB_VIDEO,"GLSL: %s", l_glsl);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// TODO: Set antialiasing/multisampling
/*glEnable( GL_MULTISAMPLE );
glEnable( GL_LINE_SMOOTH );
glEnable( GL_POLYGON_SMOOTH );
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
*/
/*set our viewing volume. */
glViewport( 0, 0, m_Window->GetWidth(), m_Window->GetHeight());
/* Set our perspective */
/*
* ________ (width,height)
* | |
* | |
* | |
* |________|
* (0,0)
*
*/
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0, (GLfloat) m_Window->GetWidth(), 0, (GLfloat) m_Window->GetHeight(), -1000, 1000);
/* Make sure we're chaning the model view and not the projection */
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
}
示例5: info
bool fxwt::init_graphics(GraphicsInitParameters *gparams) {
info("Initializing SDL");
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE) == -1) {
error("%s: Could not initialize SDL library.", __func__);
return false;
}
if(!gparams->fullscreen) {
const SDL_VideoInfo *vid_inf = SDL_GetVideoInfo();
gparams->bpp = vid_inf->vfmt->BitsPerPixel;
}
info("Trying to set video mode %dx%dx%d, d:%d s:%d %s", gparams->x, gparams->y, gparams->bpp, gparams->depth_bits, gparams->stencil_bits, gparams->fullscreen ? "fullscreen" : "windowed");
int rbits, gbits, bbits;
switch(gparams->bpp) {
case 32:
rbits = gbits = bbits = 8;
break;
case 16:
rbits = bbits = 5;
gbits = 6;
break;
default:
error("%s: Tried to set unsupported pixel format: %d bpp", __func__, gparams->bpp);
return false;
}
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rbits);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, gbits);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, bbits);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, gparams->depth_bits);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, gparams->stencil_bits);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
unsigned long flags = SDL_OPENGL;
if(gparams->fullscreen) flags |= SDL_FULLSCREEN;
if(!SDL_SetVideoMode(gparams->x, gparams->y, gparams->bpp, flags)) {
if(gparams->depth_bits == 32) gparams->depth_bits = 24;
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, gparams->depth_bits);
if(!SDL_SetVideoMode(gparams->x, gparams->y, gparams->bpp, flags)) {
error("%s: Could not set requested video mode", __func__);
}
}
// now check the actual video mode we got
int arbits, agbits, abbits, azbits, astencilbits;
SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &arbits);
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &agbits);
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &abbits);
SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &azbits);
SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &astencilbits);
info("Initialized video mode:");
info(" bpp: %d (%d%d%d)", arbits + agbits + abbits, arbits, agbits, abbits);
info("zbuffer: %d", azbits);
info("stencil: %d", astencilbits);
/* if the dont_care_flags does not contain DONT_CARE_BPP and our color bits
* does not match, we should return failure, however we test against
* the difference allowing a +/-1 difference in order to allow for 16bpp
* formats of either 565 or 555 and consider them equal.
*/
if(!(gparams->dont_care_flags & DONT_CARE_BPP) && abs(arbits - rbits) > 1 && abs(agbits - gbits) > 1 && abs(abbits - bbits) > 1) {
error("%s: Could not set requested exact bpp mode", __func__);
return false;
}
// now if we don't have DONT_CARE_DEPTH in the dont_care_flags check for
// exact depth buffer format, however consider 24 and 32 bit the same
if(!(gparams->dont_care_flags & DONT_CARE_DEPTH) && azbits != gparams->depth_bits) {
if(!((gparams->depth_bits == 32 && azbits == 24) || (gparams->depth_bits == 24 && azbits == 32))) {
error("%s: Could not set requested exact zbuffer depth", __func__);
return false;
}
}
// if we don't have DONT_CARE_STENCIL make sure we have the stencil format
// that was asked.
if(!(gparams->dont_care_flags & DONT_CARE_STENCIL) && astencilbits != gparams->stencil_bits) {
error("%s: Could not set exact stencil format", __func__);
return false;
}
return true;
}
示例6: closeOverlay
//.........这里部分代码省略.........
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
setAntialiasing(true);
_screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
}
// If 16-bit without alpha and with antialiasing didn't work, try without antialiasing
if (!_screen && _opengl && _antialiasing) {
warning("Couldn't create 16-bit visual with AA, trying 16-bit without AA");
setAntialiasing(false);
_screen = SDL_SetVideoMode(screenW, screenH, 0, sdlflags);
}
#endif
if (!_screen) {
warning("Error: %s", SDL_GetError());
g_system->quit();
}
#ifdef USE_OPENGL
if (_opengl) {
int glflag;
const GLubyte *str;
// apply atribute again for sure based on SDL docs
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
str = glGetString(GL_VENDOR);
debug("INFO: OpenGL Vendor: %s", str);
str = glGetString(GL_RENDERER);
debug("INFO: OpenGL Renderer: %s", str);
str = glGetString(GL_VERSION);
debug("INFO: OpenGL Version: %s", str);
SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &glflag);
debug("INFO: OpenGL Red bits: %d", glflag);
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &glflag);
debug("INFO: OpenGL Green bits: %d", glflag);
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &glflag);
debug("INFO: OpenGL Blue bits: %d", glflag);
SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &glflag);
debug("INFO: OpenGL Alpha bits: %d", glflag);
SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &glflag);
debug("INFO: OpenGL Z buffer depth bits: %d", glflag);
SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &glflag);
debug("INFO: OpenGL Double Buffer: %d", glflag);
SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &glflag);
debug("INFO: OpenGL Stencil buffer bits: %d", glflag);
#ifdef USE_GLEW
debug("INFO: GLEW Version: %s", glewGetString(GLEW_VERSION));
GLenum err = glewInit();
if (err != GLEW_OK) {
warning("Error: %s", glewGetErrorString(err));
g_system->quit();
}
#endif
#ifdef USE_OPENGL_SHADERS
debug("INFO: GLSL version: %s", glGetString(GL_SHADING_LANGUAGE_VERSION));
const GLfloat vertices[] = {
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 1.0,
};
示例7: main
int
main(int argc, char *argv[])
{
int fsaa, accel;
int value;
int i, done;
SDL_DisplayMode mode;
SDL_Event event;
Uint32 then, now, frames;
int status;
/* Initialize parameters */
fsaa = 0;
accel = 0;
/* Initialize test framework */
state = CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
int consumed;
consumed = CommonArg(state, i);
if (consumed == 0) {
if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
++fsaa;
consumed = 1;
} else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
++accel;
consumed = 1;
} else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
i++;
if (!argv[i]) {
consumed = -1;
} else {
depth = SDL_atoi(argv[i]);
consumed = 1;
}
} else {
consumed = -1;
}
}
if (consumed < 0) {
fprintf(stderr, "Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
CommonUsage(state));
quit(1);
}
i += consumed;
}
/* Set OpenGL parameters */
state->window_flags |= SDL_WINDOW_OPENGL;
state->gl_red_size = 5;
state->gl_green_size = 5;
state->gl_blue_size = 5;
state->gl_depth_size = depth;
if (fsaa) {
state->gl_multisamplebuffers=1;
state->gl_multisamplesamples=fsaa;
}
if (accel) {
state->gl_accelerated=1;
}
if (!CommonInit(state)) {
quit(2);
}
context = SDL_calloc(state->num_windows, sizeof(context));
if (context == NULL) {
fprintf(stderr, "Out of memory!\n");
quit(2);
}
/* Create OpenGL ES contexts */
for (i = 0; i < state->num_windows; i++) {
context[i] = SDL_GL_CreateContext(state->windows[i]);
if (!context[i]) {
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2);
}
}
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1);
} else {
SDL_GL_SetSwapInterval(0);
}
SDL_GetCurrentDisplayMode(&mode);
printf("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
printf("\n");
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");
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
if (!status) {
//.........这里部分代码省略.........
示例8: SDL_GetError
//.........这里部分代码省略.........
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
//undo the local config for the aa, so it's sent back as off
config.antialiasing = 0;
//try again
snow_gl_context = SDL_GL_CreateContext(window);
if(!snow_gl_context) {
snow::log(1, "/ snow / failed to create GL context without AA (window id %d): %s\n", id, SDL_GetError() );
//if that fails, we try and run a diagnostic test
//against no stencil / depth buffer, so we can log more useful information
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0 );
snow_gl_context = SDL_GL_CreateContext(window);
//if this succeeds we can at least log that there was a misconfigured depth/stencil buffer
if(snow_gl_context) {
snow::log(1, "/ snow / diagnostic test with no stencil/depth passed, meaning your stencil/depth bit combo is invalid (requested stencil:%d, depth:%d)\n",
config.stencil_bits, config.depth_bits );
} else {
snow::log(1, "/ snow / diagnostic test with no stencil/depth failed as well %s\n", SDL_GetError() );
}
on_created( false );
return;
}
}
//if we end up with a context
if(snow_gl_context) {
//update the window config flags to what
//SDL has actually given us in return
int actual_aa = config.antialiasing;
int actual_depth = config.depth_bits;
int actual_stencil = config.stencil_bits;
int actual_red = config.red_bits;
int actual_blue = config.blue_bits;
int actual_green = config.green_bits;
int actual_alpha = config.alpha_bits;
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &actual_aa);
SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &actual_red);
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &actual_green);
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &actual_blue);
SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &actual_alpha);
SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &actual_depth);
SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &actual_stencil);
config.antialiasing = actual_aa;
config.red_bits = actual_red;
config.green_bits = actual_green;
config.blue_bits = actual_blue;
config.alpha_bits = actual_alpha;
config.depth_bits = actual_depth;
config.stencil_bits = actual_stencil;
snow::render::set_context_attributes(
actual_red, actual_green, actual_blue, actual_alpha,
actual_depth, actual_stencil, actual_aa
);
snow::log(2, "/ snow / success in creating GL context for window %d\n", id);
}
#ifdef NATIVE_TOOLKIT_GLEW
int err = glewInit();
if(err != 0) {
snow::log(1, "/ snow / failed to init glew?! %s\n", glewGetErrorString(err));
on_created( false );
return;
} else {
snow::log(2, "/ snow / GLEW init ok");
}
#endif //NATIVE_TOOLKIT_GLEW
} //!snow_gl_context
//on iOS we need to intercept the loop
#ifdef IPHONE
snow::log(1, "/ snow / requesting main loop for iOS");
SDL_iPhoneSetAnimationCallback(window, 1, snow::core::loop, NULL);
#endif //IPHONE
#ifdef HX_WINDOWS
snow::platform::window::load_icon( window );
#endif
on_created( true );
} //WindowSDL2::create
示例9: arx_assert
bool SDL2Window::initialize() {
arx_assert(!m_displayModes.empty());
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
#if ARX_PLATFORM == ARX_PLATFORM_WIN32
// Used on Windows to prevent software opengl fallback.
// The linux situation:
// Causes SDL to require visuals without caveats.
// On linux some drivers only supply multisample capable GLX Visuals
// with a GLX_NON_CONFORMANT_VISUAL_EXT caveat.
// see: https://www.opengl.org/registry/specs/EXT/visual_rating.txt
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
#endif
// TODO EGL and core profile are not supported yet
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
if(gldebug::isEnabled()) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
}
int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;
Uint32 windowFlags = getSDLFlagsForMode(m_size, m_fullscreen);
windowFlags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
for(int msaa = m_maxMSAALevel; msaa > 0; msaa--) {
bool lastTry = (msaa == 1);
// Cleanup context and window from previous tries
if(m_glcontext) {
SDL_GL_DeleteContext(m_glcontext);
m_glcontext = NULL;
}
if(m_window) {
SDL_DestroyWindow(m_window);
m_window = NULL;
}
SDL_ClearError();
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, msaa > 1 ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa > 1 ? msaa : 0);
m_window = SDL_CreateWindow(m_title.c_str(), x, y, m_size.x, m_size.y, windowFlags);
if(!m_window) {
if(lastTry) {
LogError << "Could not create window: " << SDL_GetError();
return false;
}
continue;
}
m_glcontext = SDL_GL_CreateContext(m_window);
if(!m_glcontext) {
if(lastTry) {
LogError << "Could not create GL context: " << SDL_GetError();
return false;
}
continue;
}
// Verify that the MSAA setting matches what was requested
int msaaEnabled, msaaValue;
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &msaaEnabled);
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msaaValue);
if(!lastTry) {
if(!msaaEnabled || msaaValue < msaa) {
continue;
}
}
if(msaaEnabled) {
m_MSAALevel = msaaValue;
} else {
m_MSAALevel = 0;
}
// Verify that we actually got an accelerated context
(void)glGetError(); // clear error flags
GLint texunits = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &texunits);
if(glGetError() != GL_NO_ERROR || texunits < GLint(m_minTextureUnits)) {
if(lastTry) {
LogError << "Not enough GL texture units available: have " << texunits
<< ", need at least " << m_minTextureUnits;
return false;
}
continue;
}
// All good
const char * system = "(unknown)";
{
ARX_SDL_SysWMinfo info;
info.version.major = 2;
info.version.minor = 0;
info.version.patch = 4;
//.........这里部分代码省略.........
示例10: GLimp_InitGraphics
static qboolean
GLimp_InitGraphics(qboolean fullscreen)
{
int flags;
/* Just toggle fullscreen if that's all that has been changed */
if (surface && (surface->w == vid.width) && (surface->h == vid.height)) {
int isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
if (fullscreen != isfullscreen)
SDL_WM_ToggleFullScreen(surface);
isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
if (fullscreen == isfullscreen)
return true;
}
srandom(getpid());
/* free resources in use */
if (surface)
SDL_FreeSurface(surface);
/* let the sound and input subsystems know about the new window */
ri.Vid_NewWindow(vid.width, vid.height);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (use_stencil)
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);
flags = SDL_OPENGL;
if (fullscreen)
flags |= SDL_FULLSCREEN;
SetSDLIcon(); /* currently uses q2icon.xbm data */
if ((surface = SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL) {
Sys_Error("(SDLGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
return false;
}
/* stencilbuffer shadows */
if (use_stencil) {
int stencil_bits;
have_stencil = false;
if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits)) {
ri.Con_Printf(PRINT_ALL, "I: got %d bits of stencil\n",
stencil_bits);
if (stencil_bits >= 1) {
have_stencil = true;
}
}
}
SDL_WM_SetCaption(QUDOS_VERSION, QUDOS_VERSION);
SDL_ShowCursor(0);
X11_active = true;
SetSDLGamma();
return true;
}
示例11: RunGLTest
//.........这里部分代码省略.........
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);
if (fsaa) {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
}
if (accel) {
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
}
if (SDL_SetVideoMode(w, h, bpp, video_flags) == NULL) {
fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
SDL_Quit();
exit(1);
}
if (sync) {
SDL_GL_SetSwapInterval(1);
} else {
SDL_GL_SetSwapInterval(0);
}
printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
printf("\n");
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");
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);
if (fsaa) {
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
}
if (accel) {
SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
}
if (sync) {
printf("Buffer swap interval: requested 1, got %d\n",
SDL_GL_GetSwapInterval());
}
/* Set the window manager title bar */
SDL_WM_SetCaption("SDL GL test", "testgl");
/* Set the gamma for the window */
if (gamma != 0.0) {
SDL_SetGamma(gamma, gamma, gamma);
}
示例12: SDL_GL_SetAttribute
WindowSDL::WindowSDL(const Graphics::Settings &vs, const std::string &name)
{
Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
if (vs.fullscreen) winFlags |= SDL_WINDOW_FULLSCREEN;
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, vs.requestedSamples ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, vs.requestedSamples);
// attempt sequence is:
// 1- requested mode
m_window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, vs.width, vs.height, winFlags);
// 2- requested mode with no anti-aliasing (skipped if no AA was requested anyway)
if (!m_window && vs.requestedSamples) {
fprintf(stderr, "Failed to set video mode. (%s). Re-trying without multisampling.\n", SDL_GetError());
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
m_window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, vs.width, vs.height, winFlags);
}
// 3- requested mode with 16 bit depth buffer
if (!m_window) {
fprintf(stderr, "Failed to set video mode. (%s). Re-trying with 16-bit depth buffer\n", SDL_GetError());
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, vs.requestedSamples ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, vs.requestedSamples);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
m_window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, vs.width, vs.height, winFlags);
}
// 4- requested mode with 16-bit depth buffer and no anti-aliasing
// (skipped if no AA was requested anyway)
if (!m_window && vs.requestedSamples) {
fprintf(stderr, "Failed to set video mode. (%s). Re-trying with 16-bit depth buffer and no multisampling\n", SDL_GetError());
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
m_window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, vs.width, vs.height, winFlags);
}
// 5- abort!
if (!m_window) {
OS::Error("Failed to set video mode: %s", SDL_GetError());
}
m_glContext = SDL_GL_CreateContext(m_window);
int bpp;
Uint32 rmask, gmask, bmask, amask;
SDL_PixelFormatEnumToMasks(SDL_GetWindowPixelFormat(m_window), &bpp, &rmask, &gmask, &bmask, &amask);
switch (bpp) {
case 16:
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
break;
case 24:
case 32:
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);
break;
default:
fprintf(stderr, "Invalid pixel depth: %d bpp\n", bpp);
// this valuable is not reliable if antialiasing vs are overridden by
// nvidia/ati/whatever vs
int actualSamples = 0;
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &actualSamples);
if (vs.requestedSamples != actualSamples)
fprintf(stderr, "Requested AA mode: %dx, actual: %dx\n", vs.requestedSamples, actualSamples);
}
SDLSurfacePtr surface = LoadSurfaceFromFile(vs.iconFile);
if (surface)
SDL_SetWindowIcon(m_window, surface.Get());
SDL_SetWindowTitle(m_window, vs.title);
}
示例13: I_UpdateVideoMode
void I_UpdateVideoMode(void)
{
int init_flags;
int i;
video_mode_t mode;
lprintf(LO_INFO, "I_UpdateVideoMode: %dx%d (%s)\n", SCREENWIDTH, SCREENHEIGHT, desired_fullscreen ? "fullscreen" : "nofullscreen");
mode = I_GetModeFromString(default_videomode);
if ((i=M_CheckParm("-vidmode")) && i<myargc-1) {
mode = I_GetModeFromString(myargv[i+1]);
}
V_InitMode(mode);
V_DestroyUnusedTrueColorPalettes();
V_FreeScreens();
I_SetRes();
// Initialize SDL with this graphics mode
if (V_GetMode() == VID_MODEGL) {
init_flags = SDL_OPENGL;
} else {
if (use_doublebuffer)
init_flags = SDL_DOUBLEBUF;
else
init_flags = SDL_SWSURFACE;
#ifndef _DEBUG
init_flags |= SDL_HWPALETTE;
#endif
}
if ( desired_fullscreen )
init_flags |= SDL_FULLSCREEN;
if (V_GetMode() == VID_MODEGL) {
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, gl_colorbuffer_bits );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, gl_depthbuffer_bits );
screen = SDL_SetVideoMode(SCREENWIDTH, SCREENHEIGHT, gl_colorbuffer_bits, init_flags);
} else {
screen = SDL_SetVideoMode(SCREENWIDTH, SCREENHEIGHT, V_GetNumPixelBits(), init_flags);
}
if(screen == NULL) {
I_Error("Couldn't set %dx%d video mode [%s]", SCREENWIDTH, SCREENHEIGHT, SDL_GetError());
}
lprintf(LO_INFO, "I_UpdateVideoMode: 0x%x, %s, %s\n", init_flags, screen->pixels ? "SDL buffer" : "own buffer", SDL_MUSTLOCK(screen) ? "lock-and-copy": "direct access");
// Get the info needed to render to the display
if (!SDL_MUSTLOCK(screen))
{
screens[0].not_on_heap = true;
screens[0].data = (unsigned char *) (screen->pixels);
screens[0].byte_pitch = screen->pitch;
screens[0].short_pitch = screen->pitch / V_GetModePixelDepth(VID_MODE16);
screens[0].int_pitch = screen->pitch / V_GetModePixelDepth(VID_MODE32);
}
else
{
screens[0].not_on_heap = false;
}
V_AllocScreens();
// Hide pointer while over this window
SDL_ShowCursor(0);
I_PrepareMouse(1);
R_InitBuffer(SCREENWIDTH, SCREENHEIGHT);
if (V_GetMode() == VID_MODEGL) {
int temp;
lprintf(LO_INFO,"SDL OpenGL PixelFormat:\n");
SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &temp );
lprintf(LO_INFO," SDL_GL_RED_SIZE: %i\n",temp);
SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &temp );
lprintf(LO_INFO," SDL_GL_GREEN_SIZE: %i\n",temp);
SDL_GL_GetAttribute( SDL_GL_BLUE_SIZE, &temp );
lprintf(LO_INFO," SDL_GL_BLUE_SIZE: %i\n",temp);
SDL_GL_GetAttribute( SDL_GL_STENCIL_SIZE, &temp );
lprintf(LO_INFO," SDL_GL_STENCIL_SIZE: %i\n",temp);
SDL_GL_GetAttribute( SDL_GL_ACCUM_RED_SIZE, &temp );
lprintf(LO_INFO," SDL_GL_ACCUM_RED_SIZE: %i\n",temp);
SDL_GL_GetAttribute( SDL_GL_ACCUM_GREEN_SIZE, &temp );
lprintf(LO_INFO," SDL_GL_ACCUM_GREEN_SIZE: %i\n",temp);
SDL_GL_GetAttribute( SDL_GL_ACCUM_BLUE_SIZE, &temp );
lprintf(LO_INFO," SDL_GL_ACCUM_BLUE_SIZE: %i\n",temp);
SDL_GL_GetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, &temp );
//.........这里部分代码省略.........
示例14: 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
printf("mustlock=%i\n", SDL_MUSTLOCK(s));
*bppp=bpp;
char * x= (char*)malloc(20);
if(x&&SDL_VideoDriverName(x,20))
printf("Current SDL video driver is %s.\n",x);
//#endif
return s;
}
示例15: VID_SDL_Init
//.........这里部分代码省略.........
}
} else {
if (vid_win_borderless.integer > 0) {
flags |= SDL_WINDOW_BORDERLESS;
}
}
#ifdef __APPLE__
SDL_SetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, "0");
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
#endif
VID_SDL_InitSubSystem();
VID_SDL_GL_SetupAttributes();
VID_SetupModeList();
VID_SetupResolution();
if (r_fullscreen.integer == 0) {
int displayNumber = VID_DisplayNumber(false);
int xpos = vid_xpos.integer;
int ypos = vid_ypos.integer;
VID_AbsolutePositionFromRelative(&xpos, &ypos, &displayNumber);
sdl_window = SDL_CreateWindow(WINDOW_CLASS_NAME, xpos, ypos, glConfig.vidWidth, glConfig.vidHeight, flags);
} else {
int windowWidth = glConfig.vidWidth;
int windowHeight = glConfig.vidHeight;
int windowX = SDL_WINDOWPOS_CENTERED;
int windowY = SDL_WINDOWPOS_CENTERED;
int displayNumber = VID_DisplayNumber(true);
SDL_Rect bounds;
if (SDL_GetDisplayBounds(displayNumber, &bounds) == 0)
{
windowX = bounds.x;
windowY = bounds.y;
windowWidth = bounds.w;
windowHeight = bounds.h;
}
else
{
Com_Printf("Couldn't determine bounds of display #%d, defaulting to main display\n", displayNumber);
}
sdl_window = SDL_CreateWindow(WINDOW_CLASS_NAME, windowX, windowY, windowWidth, windowHeight, flags);
}
if (r_fullscreen.integer > 0 && vid_usedesktopres.integer != 1) {
int index;
index = VID_GetCurrentModeIndex();
/* FIXME: Make a pre-check if the values render a valid video mode before attempting to switch (when vid_usedesktopres != 1) !! */
if (index < 0) {
Com_Printf("Couldn't find a matching video mode for the selected values, check video settings!\n");
} else {
if (SDL_SetWindowDisplayMode(sdl_window, &modelist[index]) != 0) {
Com_Printf("sdl error: %s\n", SDL_GetError());
}
}
if (SDL_SetWindowFullscreen(sdl_window, SDL_WINDOW_FULLSCREEN) < 0) {
Com_Printf("Failed to change to fullscreen mode\n");
}
}
if (VID_SetWindowIcon(sdl_window) < 0) {
Com_Printf("Failed to set window icon");
}
SDL_SetWindowMinimumSize(sdl_window, 320, 240);
sdl_context = SDL_GL_CreateContext(sdl_window);
if (!sdl_context) {
Com_Printf("Couldn't create OpenGL context: %s\n", SDL_GetError());
return;
}
v_gamma.modified = true;
r_swapInterval.modified = true;
SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r);
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g);
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b);
SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &a);
glConfig.colorBits = r+g+b+a;
SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &glConfig.depthBits);
SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &glConfig.stencilBits);
glConfig.vendor_string = glGetString(GL_VENDOR);
glConfig.renderer_string = glGetString(GL_RENDERER);
glConfig.version_string = glGetString(GL_VERSION);
glConfig.extensions_string = glGetString(GL_EXTENSIONS);
glConfig.initialized = true;
}