Visual Computing Library  devel
Loading...
Searching...
No Matches
viewer_drawer_opengl2.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_OPENGL2_H
24#define VCL_OPENGL2_DRAWERS_VIEWER_DRAWER_OPENGL2_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 ViewProjEventDrawer>
43class ViewerDrawerOpenGL2 : public AbstractViewerDrawer<ViewProjEventDrawer>
44{
46
47public:
48 ViewerDrawerOpenGL2(uint width = 1024, uint height = 768) :
49 ParentViewer(width, height)
50 {
51 }
52
54 const std::shared_ptr<DrawableObjectVector>& v,
55 uint width = 1024,
56 uint height = 768) : ViewerDrawerOpenGL2(width, height)
57 {
58 ParentViewer::setDrawableObjectVector(v);
59 }
60
61 void onInit(uint viewId) override
62 {
63 ParentViewer::onInit(viewId);
69
70 float lightAmbient[] = {.2f, .2f, .2f, 1.0f};
71 float lightDiffuse[] = {.5f, .5f, .5f, 1.0f};
72
75
76 if (ParentViewer::mDrawList) {
77 for (auto& obj : *(ParentViewer::mDrawList)) {
78 obj->init();
79 }
80 }
81 }
82
83 void onDraw(uint viewId) override { onDrawContent(viewId); }
84
85 void onDrawContent(uint) override
86 {
88
89 auto tmp = ParentViewer::light().direction();
90 vcl::Point4f lPos(tmp.x(), tmp.y(), tmp.z(), 0.0f);
91
94 glMultMatrixf(ParentViewer::projectionMatrix().data());
98 glMultMatrixf(ParentViewer::viewMatrix().data());
99
100 for (auto& obj : *(ParentViewer::mDrawList))
101 obj->draw();
102 }
103
104 // events
105 void onMouseDoubleClick(
106 MouseButton::Enum button,
107 double x,
108 double y,
109 const KeyModifiers& modifiers) override
110 {
111 ParentViewer::readDepthRequest(x, y);
112 }
113};
114
115} // namespace vcl
116
117#endif // VCL_OPENGL2_DRAWERS_VIEWER_DRAWER_OPENGL2_H
The AbstractViewerDrawer class is a base class for all viewer drawers implementations.
Definition abstract_viewer_drawer.h:46
A class representing a box in N-dimensional space.
Definition box.h:46
Definition viewer_drawer_opengl2.h:44