Mondschein Engine  0.3.0
visual.cpp
1 /* Mondschein Engine is a fast, powerful, and easy-to-use 3D realtime rendering engine.
2  *
3  * Copyright (C) 2009-2013 by Andreas Amereller
4  * E-Mail: andreas.amereller.dev@googlemail.com
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "glut/visual.h"
22 #ifdef FREEGLUT
23 #include <GL/freeglut_ext.h>
24 #else
25 #include <GL/glut.h>
26 #endif
27 
28 using namespace mondschein;
29 using namespace display;
30 
31 GLUT_Visual::GLUT_Visual() : Visual(), renderer::Context(), id(0)
32 {
33  return;
34 }
35 
36 GLUT_Visual::GLUT_Visual(const visual_attribs_t &_dsp,const renderer::context_attribs_t &_c,renderer::Renderer_p _r) :
37  Visual(_dsp,renderer::Context_p()), renderer::Context(_c,_r), id(0)
38 {
39  return;
40 }
41 
42 GLUT_Visual::~GLUT_Visual()
43 {
44  if (id>0) glutDestroyWindow(id);
45  return;
46 }
47 
49 {
51  renderer::context_attribs_t c=renderer::Context::get_data();
52  glutInitWindowSize(dsp.width,dsp.height);
53  uint32 mode=0;
54  if (c.doublebuffer) mode|= GLUT_DOUBLE;
55  if (c.depth_buffer_size>0) mode |= GLUT_DEPTH;
56  if (c.stencil_buffer_size>0) mode |= GLUT_STENCIL;
57  if (c.color_depth.dot(c.color_depth)>0) mode |= GLUT_RGBA;
58  if (c.accum_depth.dot(c.accum_depth)>0) mode |= GLUT_ACCUM;
59  glutInitDisplayMode(mode);
60  id=glutCreateWindow("Mondschein Engine GLUT rendering window");
61  return;
62 }
63 
65 {
66  if (id=0) glutDestroyWindow(id);
67  return;
68 }
69 
71 {
72  glutSwapBuffers();
73  return;
74 }