/*  $Id: opengl_window.cpp,v 1.10 2003/12/10 02:26:52 mbn Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

#include "Display/display_precomp.h"
#include "API/GL/opengl_window.h"
#include "API/Display/display_window_description.h"

#ifdef WIN32
#include "WGL/display_window_opengl.h"
#else
#include "GLX/display_window_opengl.h"
#endif

#define gl_impl ((CL_DisplayWindow_OpenGL *) impl)

/////////////////////////////////////////////////////////////////////////////
// CL_OpenGLWindow construction:

CL_OpenGLWindow::CL_OpenGLWindow() : CL_DisplayWindow()
{
}

CL_OpenGLWindow::CL_OpenGLWindow(const CL_OpenGLWindow &copy) : CL_DisplayWindow(copy)
{
}

CL_OpenGLWindow::CL_OpenGLWindow(
	const std::string &title,
	int width,
	int height,
	bool start_fullscreen,
	bool allow_resize,
	int flipping_buffers)
: CL_DisplayWindow(new CL_DisplayWindow_OpenGL)
{
	CL_DisplayWindowDescription desc;
	desc.set_title(title);
	desc.set_size(CL_Size(width, height));
	desc.set_fullscreen(start_fullscreen);
	desc.set_allow_resize(allow_resize);
	desc.set_flipping_buffers(flipping_buffers);

	gl_impl->create_window(desc);

	// Automatically map first created display window as 'CL_Display current'.
	if (CL_DisplayWindow_Generic::current == 0) CL_DisplayWindow_Generic::current = this;

	gl_impl->sig_resize(get_width(), get_height());
}

CL_OpenGLWindow::~CL_OpenGLWindow()
{
}

/////////////////////////////////////////////////////////////////////////////
// CL_OpenGLWindow attributes:

#ifdef WIN32

HGLRC CL_OpenGLWindow::get_context()
{
	return gl_impl->get_context();
}

HDC CL_OpenGLWindow::get_dc()
{
	return gl_impl->get_dc();
}

HWND CL_OpenGLWindow::get_wnd()
{
	return gl_impl->get_hwnd();
}
#else

Display *CL_OpenGLWindow::get_wnd()
{
	return gl_impl->get_hwnd();
}

#endif

/////////////////////////////////////////////////////////////////////////////
// CL_OpenGLWindow operations:
