Visual Computing Library
Loading...
Searching...
No Matches
viewer_drawer.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_OPENGL2_DRAWERS_VIEWER_DRAWER_H
24#define VCL_OPENGL2_DRAWERS_VIEWER_DRAWER_H
25
26#include <vclib/render/drawers/abstract_viewer_drawer.h>
27#include <vclib/render/read_buffer_types.h>
28
29#include <memory>
30
31#ifdef __APPLE__
32#include <OpenGL/gl.h>
33#else
34#ifdef _WIN32
35#include <windows.h>
36#endif
37#include <GL/gl.h>
38#endif
39
40namespace vcl {
41
42template<typename DerivedRenderApp>
43class ViewerDrawerOpenGL2 : public AbstractViewerDrawer<DerivedRenderApp>
44{
46 using DTB = ParentViewer::DTB;
47
48public:
49 ViewerDrawerOpenGL2(uint width = 1024, uint height = 768) :
50 ParentViewer(width, height)
51 {
52 }
53
55 const std::shared_ptr<DrawableObjectVector>& v,
56 uint width = 1024,
57 uint height = 768) : ViewerDrawerOpenGL2(width, height)
58 {
59 ParentViewer::setDrawableObjectVector(v);
60 }
61
62 void onInit(uint viewId) override
63 {
64 ParentViewer::onInit(viewId);
70
71 float lightAmbient[] = {.2f, .2f, .2f, 1.0f};
72 float lightDiffuse[] = {.5f, .5f, .5f, 1.0f};
73
76
77 if (ParentViewer::mDrawList) {
78 for (auto& obj : *(ParentViewer::mDrawList)) {
79 obj->init();
80 }
81 }
82 }
83
84 void onDraw(uint viewId) override { onDrawContent(viewId); }
85
86 void onDrawContent(uint) override
87 {
89
90 auto tmp = DTB::light().direction();
91 vcl::Point4f lPos(tmp.x(), tmp.y(), tmp.z(), 0.0f);
92
95 glMultMatrixf(DTB::projectionMatrix().data());
99 glMultMatrixf(DTB::viewMatrix().data());
100
101 for (auto& obj : *(ParentViewer::mDrawList))
102 obj->draw();
103 }
104
105 // events
106 void onResize(unsigned int width, unsigned int height) override
107 {
108 DTB::resizeViewer(width, height);
109 }
110
111 void onMouseDoubleClick(
112 MouseButton::Enum button,
113 double x,
114 double y,
115 const KeyModifiers& modifiers) override
116 {
117 ParentViewer::readRequest(button, x, y, modifiers);
118 }
119
120 void toggleAxisVisibility() override
121 {
122 // todo
123 }
124
125 void toggleTrackBallVisibility() override
126 {
127 // todo
128 }
129};
130
131} // namespace vcl
132
133#endif // VCL_OPENGL2_DRAWERS_VIEWER_DRAWER_H
The AbstractViewerDrawer class is a base class for all viewer drawers implementations.
Definition abstract_viewer_drawer.h:49
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Definition viewer_drawer.h:44