- attempt to fix issue where sometimes the screen starts black and does not render

This commit is contained in:
Mark Vejvoda
2012-10-05 05:28:16 +00:00
parent b786387138
commit 7f271d0b51

View File

@@ -78,6 +78,65 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to set resolution: %d x %d, colorBits = %d.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,resW,resH,colorBits);
if(screen != NULL) {
SDL_FreeSurface(screen);
screen = NULL;
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
screen = SDL_SetVideoMode(resW, resH, colorBits, flags);
if(screen == 0) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
std::ostringstream msg;
msg << "Couldn't set video mode "
<< resW << "x" << resH << " (" << colorBits
<< "bpp " << stencilBits << " stencil "
<< depthBits << " depth-buffer). SDL Error is: " << SDL_GetError();
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,msg.str().c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,msg.str().c_str());
for(int i = 32; i >= 8; i-=8) {
// try different color bits
screen = SDL_SetVideoMode(resW, resH, i, flags);
if(screen != 0) {
break;
}
}
if(screen == 0) {
for(int i = 32; i >= 8; i-=8) {
// try to revert to 800x600
screen = SDL_SetVideoMode(800, 600, i, flags);
if(screen != 0) {
resW = 800;
resH = 600;
break;
}
}
}
if(screen == 0) {
for(int i = 32; i >= 8; i-=8) {
// try to revert to 640x480
screen = SDL_SetVideoMode(640, 480, i, flags);
if(screen != 0) {
resW = 640;
resH = 480;
break;
}
}
}
if(screen == 0) {
throw std::runtime_error(msg.str());
}
}
#ifndef WIN32 #ifndef WIN32
string mg_icon_file = ""; string mg_icon_file = "";
#if defined(CUSTOM_DATA_INSTALL_PATH_VALUE) #if defined(CUSTOM_DATA_INSTALL_PATH_VALUE)
@@ -138,77 +197,22 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
//printf("In [%s::%s Line: %d] icon = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,icon); //printf("In [%s::%s Line: %d] icon = %p\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,icon);
if(icon == NULL) { if(icon == NULL) {
printf("Error: %s\n", SDL_GetError()); printf("Icon Load Error #1: %s\n", SDL_GetError());
} }
if(icon != NULL) { if(icon != NULL) {
//uint32 colorkey = SDL_MapRGB(icon->format, 255, 0, 255); //uint32 colorkey = SDL_MapRGB(icon->format, 255, 0, 255);
//SDL_SetColorKey(icon, SDL_SRCCOLORKEY, colorkey); //SDL_SetColorKey(icon, SDL_SRCCOLORKEY, colorkey);
SDL_SetColorKey(icon, SDL_SRCCOLORKEY, SDL_MapRGB(icon->format, 255, 0, 255)); if(SDL_SetColorKey(icon, SDL_SRCCOLORKEY, SDL_MapRGB(icon->format, 255, 0, 255))) {
printf("Icon Load Error #2: %s\n", SDL_GetError());
}
else {
SDL_WM_SetIcon(icon, NULL); SDL_WM_SetIcon(icon, NULL);
} }
} }
}
#endif #endif
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to set resolution: %d x %d, colorBits = %d.\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,resW,resH,colorBits);
if(screen != NULL) {
SDL_FreeSurface(screen);
screen = NULL;
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
screen = SDL_SetVideoMode(resW, resH, colorBits, flags);
if(screen == 0) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
std::ostringstream msg;
msg << "Couldn't set video mode "
<< resW << "x" << resH << " (" << colorBits
<< "bpp " << stencilBits << " stencil "
<< depthBits << " depth-buffer). SDL Error is: " << SDL_GetError();
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,msg.str().c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,msg.str().c_str());
for(int i = 32; i >= 8; i-=8) {
// try different color bits
screen = SDL_SetVideoMode(resW, resH, i, flags);
if(screen != 0) {
break;
}
}
if(screen == 0) {
for(int i = 32; i >= 8; i-=8) {
// try to revert to 800x600
screen = SDL_SetVideoMode(800, 600, i, flags);
if(screen != 0) {
resW = 800;
resH = 600;
break;
}
}
}
if(screen == 0) {
for(int i = 32; i >= 8; i-=8) {
// try to revert to 640x480
screen = SDL_SetVideoMode(640, 480, i, flags);
if(screen != 0) {
resW = 640;
resH = 480;
break;
}
}
}
if(screen == 0) {
throw std::runtime_error(msg.str());
}
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_WM_GrabInput(SDL_GRAB_OFF);