-/*] Copyright (c) 2009-2010, Charles McGarvey [**************************
+/*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
**] All rights reserved.
*
-* vi:ts=4 sw=4 tw=75
-*
* Distributable under the terms and conditions of the 2-clause BSD license;
* see the file COPYING for a complete text of the license.
*
-**************************************************************************/
+*****************************************************************************/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
#include <sstream>
#include <stdexcept>
void video::set_opengl_attributes()
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,
- attributes_.color_buffer[0]);
+ attributes_.color_buffer[0]);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,
- attributes_.color_buffer[1]);
+ attributes_.color_buffer[1]);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,
- attributes_.color_buffer[2]);
+ attributes_.color_buffer[2]);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,
- attributes_.color_buffer[3]);
+ attributes_.color_buffer[3]);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,
- attributes_.frame_buffer);
+ attributes_.frame_buffer);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,
- attributes_.is_double_buffer);
+ attributes_.is_double_buffer);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,
- attributes_.depth_buffer);
+ attributes_.depth_buffer);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,
- attributes_.stencil_buffer);
+ attributes_.stencil_buffer);
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,
- attributes_.accumulator_buffer[0]);
+ attributes_.accumulator_buffer[0]);
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,
- attributes_.accumulator_buffer[1]);
+ attributes_.accumulator_buffer[1]);
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,
- attributes_.accumulator_buffer[2]);
+ attributes_.accumulator_buffer[2]);
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,
- attributes_.accumulator_buffer[3]);
+ attributes_.accumulator_buffer[3]);
SDL_GL_SetAttribute(SDL_GL_STEREO,
- attributes_.is_stereo);
+ attributes_.is_stereo);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,
- attributes_.multisample_buffers);
+ attributes_.multisample_buffers);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,
- attributes_.multisample_samples);
+ attributes_.multisample_samples);
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,
- attributes_.is_swap_control);
+ attributes_.is_swap_control);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
- attributes_.is_hardware_only);
+ attributes_.is_hardware_only);
}
-
video::~video()
{
SDL_FreeSurface(context_);
-
if (current_ == this) current_ = 0;
}
-
class video::attributes video::attributes() const
{
return attributes_;
}
-
void video::mode(const int mode[3])
{
if (mode != attributes_.mode || !context_)
if (context_) SDL_FreeSurface(context_);
context_ = SDL_SetVideoMode(mode[0], mode[1], mode[2],
- SDL_OPENGL | flags_);
+ flags_);
if (context_)
{
attributes_.mode[1] = mode[1];
attributes_.mode[2] = mode[2];
-#if !defined(linux) && !defined(__linux) && !defined(__linux__)
+#if PLATFORM_WIN32
log_info("video context recreated");
dispatcher::global().dispatch("video.newcontext");
#endif
}
}
-
void video::resize(int width, int height)
{
int mode[] = {width, height, attributes_.mode[2]};
return SDL_WM_IconifyWindow();
}
-
void video::caption(const std::string& caption)
{
caption_ = caption;
const std::string& video::caption() const
{
return caption_;
- //char* caption;
- //SDL_WM_GetCaption(&caption, 0);
- //return std::string(caption);
}
-
void video::fullscreen(bool full)
{
if (full != fullscreen() || !context_)
{
flags_ ^= SDL_FULLSCREEN;
-#if defined(linux) || defined(__linux) || defined(__linux__)
+#if PLATFORM_POSIX
if (SDL_WM_ToggleFullScreen(context_) == 0)
#endif
recreate_context();
fullscreen(!fullscreen());
}
-
void video::resizable(bool is_resizable)
{
if (is_resizable != resizable() || !context_)
resizable(!resizable());
}
-
void video::cursor_visible(bool is_cursor_visible)
{
SDL_ShowCursor(is_cursor_visible? SDL_ENABLE : SDL_DISABLE);
cursor_visible(!cursor_visible());
}
-
bool video::cursor_captured() const
{
return (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON);
cursor_captured(!cursor_captured());
}
-
void video::swap(scalar t)
{
if (show_fps_)
++fps_counter_;
}
-
SDL_GL_SwapBuffers();
}
-
int video::width() const
{
return context_->w;
return context_->h;
}
-
void video::make_current() const
{
current_ = const_cast<video*>(this);
}
else if (is_fullscreen && backend::is_initialized())
{
- SDL_Rect** modes = SDL_ListModes(NULL,
- SDL_FULLSCREEN | SDL_HWSURFACE);
+ SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
if (modes == (SDL_Rect**)0)
{