diff options
author | Stijn Buys <ingar@osirion.org> | 2007-10-20 10:02:51 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2007-10-20 10:02:51 +0000 |
commit | 3866f2b33313d891347f454537843befd295b78f (patch) | |
tree | ba748f4bf021605cc8e1488e7e14a4085f81a9ae /src/client/video.cc |
Initial import.
Diffstat (limited to 'src/client/video.cc')
-rw-r--r-- | src/client/video.cc | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/client/video.cc b/src/client/video.cc new file mode 100644 index 0000000..eb4297e --- /dev/null +++ b/src/client/video.cc @@ -0,0 +1,109 @@ +/* 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 +*/ + +// SDL headers +#include <SDL/SDL.h> + +// C++ headers +#include <iostream> + +// project headers +#include "gl/osiriongl.h" +#include "view.h" + + +namespace video +{ +int width = 0; +int height = 0; +bool initialized = false; +float ratio = 1; + +void reset() +{ + ratio = (float) width / (float) height; + + // Our shading model--Gouraud (smooth). + gl::shademodel(GL_SMOOTH); + + // Culling + gl::cullface( GL_BACK ); + gl::frontface(GL_CCW ); + gl::enable( GL_CULL_FACE ); + + gl::depthmask(GL_TRUE); // Depth buffer writing + gl::enable(GL_DEPTH_TEST); + + // Set the clear color + gl::clearcolor( 0, 0, 0, 0 ); + + // Setup our viewport. + gl::viewport(0, 0, width, height ); + + view::reset(); +} + +void init() +{ + if (initialized) { + return; + } + + int bpp = 0; + int flags = 0; + + if( SDL_Init(SDL_INIT_VIDEO) < 0 ) { + std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl; + return; + } + + const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo(); + if( !sdl_videoinfo) { + std::cerr << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl; + return; + } + + width = 800; + height = 600; + 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_DOUBLEBUFFER, 1 ); + + flags = SDL_OPENGL | SDL_FULLSCREEN; + + if(!SDL_SetVideoMode(width, height, bpp, flags )) { + std::cerr << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl; + return; + } + + gl::init(); + + initialized = true; + view::init(); + + reset(); + return; +} + +void draw(float elapsed) +{ + view::draw(elapsed); +} + +void shutdown() +{ + view::shutdown(); + gl::shutdown(); + + initialized = false; + width = 0; + height = 0; +} + +} // namespace video |