#ifdef _WINDOWS
#include "glwinnt.h"
#else
#ifndef _JL_GLWIN_H_
#define _JL_GLWIN_H_

#include <iostream.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <GL/glx.h>
#include <GL/gl.h>

#include "jllib_include.h"
#include "jlstring.h"

#define DEFAULT_X 400
#define DEFAULT_Y 400

class GLWin {

	private:
		Display		*_dpy;
		Window		_win;
		GLXContext	_cx;
		Bool		_db, _z;

		JLString	_name;
		int			_x, _y;

	public:
		GLWin();
		GLWin(int, int, const JLString&);
		GLWin(const GLWin&);
		~GLWin();

		GLWin& SetName(const JLString &s) { _name = s; return *this; }
		GLWin& DoubleBuffer() { _db = True; return *this; }
		GLWin& ZBuffer() { _z = True; return *this; }
		GLWin& SetSize(int x, int y);

		int x() { return _x; }
		int y() { return _y; }

		Display* GetDisplay() { return _dpy; }

		GLWin& Open(int additional_events_mask=0);
		GLWin& Close();

		void MakeCurrent() { glXMakeCurrent(_dpy, _win, _cx); }
		void SwapBuffers() { if (_db) glXSwapBuffers(_dpy, _win); }

		void Clear(float r, float g, float b);
		void Clear(long c=0);

		int EventPending() { return XPending(_dpy); }
		void NextEvent(XEvent &event) { XNextEvent(_dpy, &event); }
		char GetAscii(XEvent &event) {
				return XKeycodeToKeysym(_dpy, event.xkey.keycode, 0)
					- XK_a + 'a';
			}

		friend ostream& operator<<(ostream&, const GLWin&);
};

#endif
#endif
