1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
if ( SDL_InitSubSystem(SDL_INIT_VIDEO)== -1 )
{
std::cout << "SDL_VIDEO have failed on initialisation" << std::endl ;
}
std::string WindowsName = "Demo openGL" ;
bool FullScreen = Application::Instance().m_Settings.m_FullScreen ;
unsigned int ColorBits = Application::Instance().m_Settings.m_ColorBits ;
unsigned int ScreenWidth = Application::Instance().m_Settings.m_ScreenWidth ;
unsigned int ScreenHeight = Application::Instance().m_Settings.m_ScreenHeight ;
// Setting up some parameters
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
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_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, ColorBits );
SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, ColorBits );
// Center the windows on the screnn
_putenv("SDL_VIDEO_WINDOW_POS=center");
// Name the windows and give it an icon
SDL_WM_SetCaption(WindowsName.c_str(),WindowsName.c_str());
// SDL_VIDEO flags
int VideoFlags = SDL_OPENGL | SDL_ANYFORMAT ;
if ( FullScreen )
VideoFlags |= SDL_FULLSCREEN ;
// Creating the ScreenSurface
m_ScreenSurface = SDL_SetVideoMode( ScreenWidth, ScreenHeight, ColorBits, VideoFlags );
if ( !m_ScreenSurface )
{
std::cout << "SDL_VIDEO have failed creating the ScreenSurface" << std::endl ;
}
// OpenGl init settings
glClearColor(0,0,0,1);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glViewport(0,0,ScreenWidth,ScreenHeight);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0,(float) ScreenWidth/ScreenHeight,0.1,100.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
// can we use AA ?
if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) == -1)
{
std::cout << "Cant Init SDL_GL_MULTISAMPLEBUFFERS to 1" << std::endl ;
}
if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8) == -1)
{
std::cout << "Cant Init SDL_GL_MULTISAMPLEBUFFERS to 8" << std::endl ;
}
std::cout << "RenderTask :: Init :: OK " << std::endl ; |
Partager