00001
00004
00005
00006
00007
00008
00009
#include "../src/WindowHandler.h"
00010
00011
00012
00013
00014
00015
00016
00017
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
00039
00040
00041
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;
00048
pixel_format_flag_ |= SDL_HWPALETTE;
00049
pixel_format_flag_ |= SDL_RESIZABLE;
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
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
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
00084
00085
00086
00087 void WindowHandler::initOpenGLDrawingSurface()
00088 {
00089
initOpenGL();
00090
00091
00092 }
00093
00094
00095
00096
00097
00098 void WindowHandler::initOpenGL()
00099 {
00100
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);
00110 glLoadIdentity();
00111 }
00112
00113
00114
00115
00116
00117
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
00134
00135
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