1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000,2001 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
43 #include <OpenSG/OSGGLUT.h>
44 #include <OpenSG/OSGMatrixUtility.h>
47 #include "TestWindow.h"
49 // This is ultra-ugly, but GLUT gives you no alternative
53 TestWindow::TestWindow(void) :
54 _width(-1), _height(-1), _scene(OSG::NullFC
), _window(OSG::NullFC
), _ssm(NULL
),
55 _open(false), _left(0), _right(1), _top(1), _bottom(0),
56 _near(0.1), _far(100), _fov(1), _beacon(OSG::NullFC
),
61 TestWindow::~TestWindow()
64 glutDestroyWindow(_winid
);
65 if(_window
!= OSG::NullFC
)
71 void TestWindow::setFullscreen(void)
79 _width
= glutGet(GLUT_SCREEN_WIDTH
);
80 _height
= glutGet(GLUT_SCREEN_HEIGHT
);
90 void TestWindow::setSize(OSG::UInt16 width
, OSG::UInt16 height
)
97 glutReshapeWindow(width
, height
);
106 void TestWindow::setViewport(OSG::Real32 left
, OSG::Real32 right
,
107 OSG::Real32 bottom
, OSG::Real32 top
)
117 void TestWindow::setCamera(OSG::Matrix mat
)
119 // OSG::beginEditCP(_beacon);
120 _beacon
->setMatrix(mat
);
121 // OSG::endEditCP(_beacon);
124 void TestWindow::showAll(void)
132 void TestWindow::setNearFar(OSG::Real32 n
, OSG::Real32 f
)
134 // OSG::beginEditCP(getCamera());
135 getCamera()->setNear(n
);
136 getCamera()->setFar(f
);
137 // OSG::endEditCP(getCamera());
140 void TestWindow::setFov(OSG::Real32 fov
)
142 // OSG::beginEditCP(getCamera());
143 getCamera()->setFov(fov
);
144 // OSG::endEditCP(getCamera());
147 void TestWindow::redraw(void)
151 if(!_ssm
->getUseTraversalAction())
152 _window
->render(dynamic_cast<OSG::RenderAction
*>(_ssm
->getAction()));
153 #ifdef OSG_CLEANED_RENDERACTION
155 _window
->render(_ssm
->getRenderTraversalAction());
159 OSG::ImagePtr
TestWindow::snapshot(void)
163 OSG::ViewportPtr port
= _ssm
->getWindow()->getPort(0);
165 // OSG::beginEditCP(port);
166 port
->addForeground(_grabber
);
167 // OSG::endEditCP(port);
169 OSG::ImagePtr img
= OSG::Image::create();
170 // OSG::beginEditCP(img);
171 img
->setPixelFormat(OSG::Image::OSG_RGB_PF
);
172 // OSG::endEditCP(img);
174 // OSG::beginEditCP(_grabber);
175 _grabber
->setImage(img
);
176 // OSG::endEditCP(_grabber);
180 // OSG::beginEditCP(port);
181 port
->removeFromForegrounds(port
->getForegrounds().size()-1);
182 // OSG::endEditCP(port);
187 void TestWindow::finish(void)
192 glReadPixels(0, 0, 1, 1, GL_RGB
, GL_UNSIGNED_BYTE
, &dummy
);
195 void TestWindow::setCamera(OSG::Real32 fromx
, OSG::Real32 fromy
, OSG::Real32 fromz
,
196 OSG::Real32 atx
, OSG::Real32 aty
, OSG::Real32 atz
,
197 OSG::Real32 upx
, OSG::Real32 upy
, OSG::Real32 upz
)
201 OSG::MatrixLookAt(m
, fromx
, fromy
, fromz
,
207 static void display(void)
209 // Make sure the window is really open...
210 glClear(GL_COLOR_BUFFER_BIT
);
215 glReadPixels(0, 0, 1, 1, GL_RGB
, GL_UNSIGNED_BYTE
, &dummy
);
218 static void idle(void)
223 void TestWindow::open(void)
225 static bool inited
= false;
233 char *argv
[2]={"OpenSG", "Benchmarks"};
235 glutInit(&argc
, argv
);
236 glutInitDisplayMode(GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
240 glutInitWindowPosition(0,0);
242 glutInitWindowSize(_width
, _height
);
244 _winid
= glutCreateWindow("OpenSG Benchmark");
249 _width
= glutGet(GLUT_SCREEN_WIDTH
);
250 _height
= glutGet(GLUT_SCREEN_HEIGHT
);
253 glutDisplayFunc(display
);
258 _window
->setId(_winid
);
267 void TestWindow::close(void)
269 glutDestroyWindow(_window
->getId());
273 void TestWindow::update(void)
275 if(_window
== OSG::NullFC
)
276 _window
= OSG::GLUTWindow::create();
278 if(_grabber
== OSG::NullFC
)
280 _grabber
= OSG::GrabForeground::create();
281 // OSG::beginEditCP(_grabber);
282 _grabber
->setAutoResize(true);
283 _grabber
->setActive(true);
284 // OSG::endEditCP(_grabber);
288 _ssm
= new OSG::SimpleSceneManager
;
290 _ssm
->setWindow(_window
);
292 _ssm
->setRoot(_scene
);
294 _beacon
= OSG::cast_dynamic
<OSG::TransformPtr
>(
295 getCamera()->getBeacon()->getCore());
297 _ssm
->resize(_width
, _height
);
299 for(int i
= 0; i
< _ssm
->getWindow()->getPort().size(); ++i
)
301 OSG::ViewportPtr port
= _ssm
->getWindow()->getPort(i
);
303 // OSG::beginEditCP(port);
304 port
->setLeft(_left
);
305 port
->setRight(_right
);
306 port
->setBottom(_bottom
);
308 // OSG::endEditCP(port);