/* video.cc This file is part of the Osirion project and is distributed under the terms and conditions of the GNU General Public License version 2 */ #include "client/client.h" #include "render/render.h" #include "sys/sys.h" #include using namespace render; namespace client { namespace video { const int defaultwidth = 1024; const int defaultheight = 768; int width = 0; int height = 0; float aspect = 1; void reset() { // recalculate the video aspect aspect = (float) width / (float) height; // settup our viewport. gl::viewport(0, 0, width, height ); // reset the view view::reset(); } bool init() { con_print << "Initializing video..." << std::endl; int bpp = 0; int flags = 0; if( SDL_Init(SDL_INIT_VIDEO) < 0 ) { std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl; return false; } const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo(); if( !sdl_videoinfo) { std::cerr << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl; return false; } width = 1024; height = 768; bpp = sdl_videoinfo->vfmt->BitsPerPixel; 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_ALPHA_SIZE, 2); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); flags = SDL_OPENGL | SDL_FULLSCREEN; if(!SDL_SetVideoMode(width, height, bpp, flags )) { std::cerr << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl; return false; } aspect = (float) width / (float) height; con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; render::init(); view::init(); video::reset(); return true; } void frame(float seconds) { // render a client frame view::frame(seconds); SDL_GL_SwapBuffers(); } void shutdown() { con_print << "Shutting down video..." << std::endl; view::shutdown(); render::shutdown(); width = 0; height = 0; } } // namespace video } // namespace client