39 #include "GLUT/glut.h"
43 #include <GL/freeglut_ext.h>
48 const int GLUT_WHEEL_SCROLL_UP = 3;
49 const int GLUT_WHEEL_SCROLL_DOWN = 4;
64 glutInit(ac, (
char**)av);
65 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
73 if (BaseWindow::_activeWindow)
74 BaseWindow::_activeWindow->reshape(
Vector2i(x, y));
79 if (BaseWindow::_activeWindow)
81 BaseWindow::_activeWindow->display();
87 if (BaseWindow::_activeWindow)
88 BaseWindow::_activeWindow->keypress(key,
Vector2i(x, y));
92 if (BaseWindow::_activeWindow)
93 BaseWindow::_activeWindow->specialkey(key,
Vector2i(x, y));
98 if (BaseWindow::_activeWindow)
99 BaseWindow::_activeWindow->idle();
103 if (BaseWindow::_activeWindow)
104 BaseWindow::_activeWindow->motion(
Vector2i(x, y));
109 if (BaseWindow::_activeWindow)
110 BaseWindow::_activeWindow->mouseButton(whichButton, released,
Vector2i(x, y));
115 if (BaseWindow::_activeWindow)
116 BaseWindow::_activeWindow->passiveMotion(
Vector2i(x, y));
123 BaseWindow* BaseWindow::_activeWindow =
nullptr;
127 , _lastMousePos(-1, -1)
128 , _currMousePos(-1, -1)
129 , _lastButtonState(0)
130 , _currButtonState(0)
132 , _frameBufferMode(frameBufferMode)
134 , _windowSize(-1, -1)
135 , _displayHelp(false)
140 CORE_INFO(
"Motion speed :" << motionSpeed);
178 if (button == GLUT_WHEEL_SCROLL_UP || button == GLUT_WHEEL_SCROLL_DOWN)
183 const auto delta = (button == GLUT_WHEEL_SCROLL_UP) ? 1 : -1;
184 manipulator.wheel(pos, delta);
238 _activeWindow =
this;
251 glutReshapeWindow(windowSize.x, windowSize.y);
265 if (fb.numAccumFrames() < maxAccumFrames)
270 GLenum format = GL_RGBA;
283 GLenum type = GL_FLOAT;
284 GLvoid* buffer =
nullptr;
288 type = GL_UNSIGNED_BYTE;
300 format = GL_LUMINANCE;
304 glClearColor(0.f, 0.f, 0.f, 1.f);
305 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
311 const auto time = std::chrono::steady_clock::now();
312 const uint64_t millisecondsElapsed = std::chrono::duration_cast<std::chrono::milliseconds>(time -
_chrono).count();
322 for (
const auto& value : keyHandler.help())
323 help += value +
"\n";
338 glClearColor(0.f, 0.f, 0.f, 1.f);
339 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
358 glutSetWindowTitle(title);
363 glutInitWindowSize(width, height);
365 _activeWindow =
this;
386 _setHint(
"My mind won't fit on a server somewhere I could never afford");
389 _setHint(
"You can't download the sun. You'll never download me");
403 _setHint(kh.getKeyboardShortcutDescription(key));
443 std::bind(&BaseWindow::_toggleFrameBuffer,
this));
444 keyHandler.registerKeyboardShortcut(
'n',
"Next renderer type", std::bind(&BaseWindow::_toggleRendererType,
this));
445 keyHandler.registerKeyboardShortcut(
'l',
"Toggle head light", std::bind(&BaseWindow::_toggleHeadLight,
this));
453 const unsigned char* msg =
reinterpret_cast<const unsigned char*
>(text.c_str());
454 const auto font = GLUT_BITMAP_HELVETICA_18;
455 const float normalizeTextLength =
456 static_cast<float>(glutBitmapLength(font, msg)) /
static_cast<float>(
_windowSize.x);
457 const float normalizeTextHeight =
static_cast<float>(glutBitmapHeight(font)) /
static_cast<float>(
_windowSize.y);
458 glRasterPos2f(x - normalizeTextLength, y - normalizeTextHeight);
459 glutBitmapString(font, msg);
460 glRasterPos2f(-1.f, -1.f);
464 void BaseWindow::_toggleFrameBuffer()
467 mode = (mode + 1) % 2;
470 const auto& engineName = ap.getEngine();
472 mode = (mode + 1) % 2;
476 auto& frameBuffer = engine.getFrameBuffer();
479 const auto& rp = engine.getParametersManager().getRenderingParameters();
480 if (rp.getToneMapperExposure() > 0.f)
481 _setHint(
"Post processing: AI Denoiser + Tone mapper");
483 _setHint(
"Post processing: AI Denoiser");
493 void BaseWindow::_toggleRendererType()
495 ++_currentRendererTypeIndex;
496 _currentRendererTypeIndex = _currentRendererTypeIndex % _rendererTypes.size();
497 const auto rendererType = _rendererTypes[_currentRendererTypeIndex];
501 _setHint(
"Renderer: [" + rendererType +
"]");
504 void BaseWindow::_toggleHeadLight()
508 std::string hint =
"Head light: [";
509 hint += (renderer.getHeadLight() ?
"ON" :
"OFF");
518 _chrono = std::chrono::steady_clock::now();
virtual void dragRight(const Vector2i &to, const Vector2i &from)=0
float getMotionSpeed() const
void setWindowSize(const Vector2ui &size)
const Vector2ui getWindowSize() const
u_int64_t _currButtonState
friend void glut3dPassiveMouseFunc(int x, int y)
friend void glut3dMouseFunc(int whichButton, int released, int x, int y)
void _renderBitmapString(float x, float y, const std::string &text)
virtual void reshape(const Vector2i &newSize)
BaseWindow(Core &core, FrameBufferMode frameBufferMode=FrameBufferMode::COLOR_I8)
virtual void keypress(char key, const Vector2f &where)
FrameBufferMode _frameBufferMode
void _setTitle(const char *title)
friend void glut3dReshape(int x, int y)
std::chrono::time_point< std::chrono::steady_clock > _chrono
friend void glut3dIdle(void)
virtual void motion(const Vector2i &pos)
RenderOutput _renderOutput
void create(const char *title, size_t width, size_t height)
u_int64_t _lastButtonState
Vector2ui _windowPosition
virtual void passiveMotion(const Vector2i &pos)
void drawPixels(const int *framebuffer)
friend void glut3dSpecial(int key, int x, int y)
virtual void mouseButton(int button, bool released, const Vector2i &pos)
virtual void specialkey(int key, const Vector2f &where)
friend void glut3dMotionFunc(int x, int y)
friend void glut3dKeyboard(unsigned char key, int x, int y)
void _setHint(const std::string &message, const uint64_t milliseconds=3000)
virtual void _registerKeyboardShortcuts()
friend void glut3dDisplay(void)
virtual void forceRedraw()
PLATFORM_API void setTarget(const Vector3d &target)
Sets the camera target.
PLATFORM_API Engine & getEngine()
PLATFORM_API void commitAndRender(const RenderInput &renderInput, RenderOutput &renderOutput)
PLATFORM_API AbstractManipulator & getCameraManipulator()
PLATFORM_API ParametersManager & getParametersManager()
PLATFORM_API KeyboardHandler & getKeyboardHandler()
PLATFORM_API bool commit()
PLATFORM_API FrameBuffer & getFrameBuffer()
Returns the frame buffer.
PLATFORM_API const auto & getParametersManager() const
Returns the parameter manager.
PLATFORM_API Renderer & getRenderer()
Returns the renderer.
virtual PLATFORM_API void commit()
Commits changes to the engine. This includes scene modifications, camera modifications and renderer m...
PLATFORM_API const strings & getRendererTypes() const
Returns all renderer types.
PLATFORM_API const Camera & getCamera() const
Returns the camera.
virtual PLATFORM_API void clear()
Clear the framebuffer.
void handle(const SpecialKey key)
Handles a special key.
void handleKeyboardShortcut(const unsigned char key)
Handles a keyboard shortcut.
void registerKeyboardShortcut(const unsigned char key, const std::string &description, std::function< void()> functor)
Registers a keyboard shortcut.
PLATFORM_API ApplicationParameters & getApplicationParameters()
PLATFORM_API RenderingParameters & getRenderingParameters()
void setCurrentType(const std::string &type)
PLATFORM_API size_t getMaxAccumFrames() const
virtual PickResult pick(const Vector2f &)
Pick method This method is used to pick a point on the scene and returns PickResult struct with hit b...
PLATFORM_API void setHeadLight(const bool value)
void initGLUT(int *ac, const char **av)
dedicated namespace for 3D glut viewer widget
void glut3dKeyboard(unsigned char key, int x, int y)
glm::vec< 2, int32_t > Vector2i
void glut3dMotionFunc(int x, int y)
void glut3dReshape(int x, int y)
void glut3dPassiveMouseFunc(int x, int y)
void glut3dSpecial(int key, int x, int y)
void glut3dMouseFunc(int whichButton, int released, int x, int y)
glm::vec< 2, uint32_t > Vector2ui
FrameBufferFormat colorBufferFormat