WindowHandler.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------ 00004 00005 // Last Change: 2004/05/21 00006 // Version: 0.1 00007 00008 //---------------------------------------------------------------------includes- 00009 #include "../src/WindowHandler.h" 00010 00011 //-----------------------------------------------------------------createWindow- 00012 // 00013 // This creates a new SDL window in which virtual objects can be displayed and 00014 // considered. 00015 // @param caption The caption of the window. 00016 // @pre caption != NULL 00017 // @pre pixel_format_flag_ != 0; 00018 // 00019 void WindowHandler::createWindow() 00020 { 00021 if (SDL_Init(SDL_INIT_VIDEO) < 0) 00022 { 00023 cerr << "Can't initialize SDL video: " << SDL_GetError() << endl; 00024 return; 00025 } 00026 resetupPixelFormat(); 00027 00028 main_window_ = SDL_SetVideoMode(screen_width_, screen_height_, screen_depth_, 00029 pixel_format_flag_); 00030 if (main_window_ == NULL) 00031 { 00032 cerr << "Can't create SDL window: " << SDL_GetError() << endl; 00033 quitApplication(1); 00034 } 00035 SDL_WM_SetCaption("InfoViz: Radial Tree Layout Technique", NULL); 00036 } 00037 00038 //-----------------------------------------------------------resetupPixelFormat- 00039 // 00040 // This resets the pixel format flag. 00041 // @pre pixel_format_flag_ == 0; 00042 // 00043 void WindowHandler::resetupPixelFormat() 00044 { 00045 pixel_format_flag_ != 0 ? pixel_format_flag_ = 0 : pixel_format_flag_ ; 00046 00047 pixel_format_flag_ |= SDL_OPENGL; // it's an OpenGL window 00048 pixel_format_flag_ |= SDL_HWPALETTE; // access to hardware color palette 00049 pixel_format_flag_ |= SDL_RESIZABLE; // resizable window 00050 00051 const SDL_VideoInfo *video_card_info = SDL_GetVideoInfo(); 00052 if (video_card_info == NULL) 00053 { 00054 cerr << "Can't get video card information: " << SDL_GetError() << endl; 00055 exit(pixel_format_flag_); 00056 quitApplication(1); 00057 } 00058 // try to use hardware surface (i.e. window) 00059 if (video_card_info -> hw_available) 00060 { 00061 pixel_format_flag_ |= SDL_HWSURFACE; 00062 } 00063 else 00064 { 00065 pixel_format_flag_ |= SDL_SWSURFACE; 00066 } 00067 00068 // blitting is fast copying/moving/swapping of contiguous sections of memory 00069 if (video_card_info -> blit_hw) 00070 { 00071 pixel_format_flag_ |= SDL_HWACCEL; 00072 } 00073 00074 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 00075 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, screen_depth_); 00076 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); 00077 SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 0); 00078 SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 0); 00079 SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 0); 00080 SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0); 00081 } 00082 00083 //-----------------------------------------------------initOpenGLDrawingSurface- 00084 // 00085 // This initializes the OpenGL drawing surface 00086 // 00087 void WindowHandler::initOpenGLDrawingSurface() 00088 { 00089 initOpenGL(); 00090 00091 // here comes stuff like loading models etc. 00092 } 00093 00094 //-------------------------------------------------------------------initOpenGL- 00095 // 00096 // This initializes OpenGL. 00097 // 00098 void WindowHandler::initOpenGL() 00099 { 00100 // resize OpenGL viewport 00101 screen_height_ <= 0 ? screen_height_ = 1 : screen_height_; 00102 screen_width_ <= 0 ? screen_width_ = 1 : screen_width_; 00103 00104 glViewport(0, 0, screen_width_, screen_height_); 00105 glMatrixMode(GL_PROJECTION); 00106 glLoadIdentity(); 00107 gluPerspective(45.0f, (GLfloat)screen_width_ / (GLfloat)screen_height_, 1, 00108 50.0f); 00109 glMatrixMode(GL_MODELVIEW); // select the modelview matrix 00110 glLoadIdentity(); // reset the modelview matrix 00111 } 00112 00113 //--------------------------------------------------------------resizeVideoMode- 00114 // 00115 // This resizes the video mode. 00116 // @param screen_width The screen width of the new window. 00117 // @param screen_height The screen height of the new window. 00118 // 00119 void WindowHandler::resizeVideoMode(GLuint screen_width, GLuint screen_height) 00120 { 00121 screen_width_ = screen_width; 00122 screen_height_ = screen_height; 00123 main_window_ = SDL_SetVideoMode(screen_width_, screen_height_, screen_depth_, 00124 pixel_format_flag_); 00125 initOpenGL(); 00126 if (main_window_ == NULL) 00127 { 00128 cerr << "Can't resize SDL window: " << SDL_GetError() << endl; 00129 quitApplication(1); 00130 } 00131 } 00132 00133 //-------------------------------------------------------------toggleFullScreen- 00134 // 00135 // This toggles full screen and windowed mode. 00136 // 00137 void WindowHandler::toggleFullScreen() 00138 { 00139 if (SDL_WM_ToggleFullScreen(main_window_) == 0) 00140 { 00141 cerr << "Can't toggle full screen mode: " << SDL_GetError() << endl; 00142 quitApplication(0); 00143 } 00144 } 00145 00146 // eof

Generated on Mon Jun 14 12:48:56 2004 for InfoVis by doxygen 1.3.7