bool window::setup(const int width_param, const int height_param) { width = width_param; height = height_param; if (SDL_Init(SDL_INIT_VIDEO) < 0) { std::cout << "Couldn't initialize SDL: " << SDL_GetError() << std::endl; return false; } atexit(SDL_Quit); video = SDL_GetVideoInfo(); if(video == NULL) { std::cout << "Couldn't get video information: " << SDL_GetError() << std::endl; return false; } 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 ); if(SDL_SetVideoMode(width, height, get_bits_per_pixel(), SDL_OPENGL | SDL_RESIZABLE) == 0) { std::cout << "Couldn't set video mode: " << SDL_GetError() << std::endl; return false; } setup_opengl(width, height); return true; }
void window::handle_resize(const int width_param, const int height_param) { width = width_param; height = height_param; SDL_SetVideoMode(width, height, get_bits_per_pixel(), SDL_OPENGL | SDL_RESIZABLE); glViewport(0, 0, width, height); }
//--------------------------------------------------------------------------------------- Image::Image(const Image& img) { m_bmpSize = img.m_bmpSize; m_imgSize = img.m_imgSize; m_format = img.m_format; m_error = ""; int bmpsize = m_bmpSize.width * m_bmpSize.height * get_bits_per_pixel()/8; if ((m_bmap = (unsigned char*)malloc(bmpsize)) == NULL) { LOMSE_LOG_ERROR("[Image copy constructor]: not enough memory for image buffer"); throw runtime_error("[Image copy constructor]: not enough memory for image buffer"); } memcpy(m_bmap, img.m_bmap, bmpsize); }
//--------------------------------------------------------------------------------------- Image& Image::operator=(const Image &img) { if (this != &img) { if (m_bmap) free(m_bmap); m_bmpSize = img.m_bmpSize; m_imgSize = img.m_imgSize; m_format = img.m_format; m_error = ""; int bmpsize = m_bmpSize.width * m_bmpSize.height * get_bits_per_pixel()/8; if ((m_bmap = (unsigned char*)malloc(bmpsize)) == NULL) { LOMSE_LOG_ERROR("[Image::operator=]: not enough memory for image buffer"); throw runtime_error("[Image::operator=]: not enough memory for image buffer"); } memcpy(m_bmap, img.m_bmap, bmpsize); } return *this; }