Graphite  Version 3
An experimental 3D geometry processing program
render_area.h
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 #ifndef H_SKIN_IMGUI_RENDER_AREA_H
38 #define H_SKIN_IMGUI_RENDER_AREA_H
39 
43 #include <OGF/gom/types/node.h>
44 
45 #include <geogram/image/color.h>
46 
47 struct GLUPContext;
48 
49 namespace OGF {
50 
56  gom_class SKIN_IMGUI_API RenderArea : public Object {
57  public:
58 
65 
69  ~RenderArea() override;
70 
79  void resize(index_t w, index_t h, index_t fb_w, index_t fb_h);
80 
86  bool needs_to_redraw() const {
87  return dirty_;
88  }
89 
90 
91  gom_slots:
92 
97  void draw();
98 
103  void update();
104 
109 
114 
127  void snapshot(
128  const std::string& filename, bool make_current = true,
129  bool with_gui = false
130  );
131 
137 
152  Memory::pointer ptr,
153  Image::ColorEncoding color_encoding,
154  Image::ComponentEncoding component_encoding,
155  index_t width, index_t height
156  );
157 
158  gom_properties:
163  index_t get_width() const {
164  return width_;
165  }
166 
171  index_t get_height() const {
172  return height_;
173  }
174 
180  return frame_buffer_width_;
181  }
182 
188  return frame_buffer_height_;
189  }
190 
196  void set_projection_matrix(const mat4& value);
197 
203  const mat4& get_projection_matrix() const;
204 
210  void set_viewing_matrix(const mat4& value);
211 
217  const mat4& get_viewing_matrix() const;
218 
223  void set_background_color_1(const Color& value);
224 
230 
237  void set_background_color_2(const Color& value);
238 
245 
254  void set_background_image(const std::string& value);
255 
261  const std::string& get_background_image() const;
262 
270  void set_lighting_matrix(const mat4& value);
271 
277  const mat4& get_lighting_matrix() const;
278 
284 
289  std::string get_gpu_information() const;
290 
295  std::string get_gpu_extensions() const;
296 
306  const std::string& get_clipping_config() const {
307  return clipping_config_;
308  }
309 
320  void set_clipping_config(const std::string& clipping_config) {
321  clipping_config_ = clipping_config;
322  update_clipping_config();
323  }
324 
325  gom_signals:
330  void redraw_request(RenderingContext* rendering_context=nullptr);
331 
340  RenderingContext* rendering_context, int width, int height
341  );
342 
355  RenderingContext* rendering_context,
356  const vec2& point_ndc, const vec2& point_wc,
357  int button, bool control, bool shift
358  );
359 
379  RenderingContext* rendering_context,
380  const vec2& point_ndc, const vec2& point_wc,
381  const vec2& delta_ndc, double delta_x_ndc, double delta_y_ndc,
382  const vec2& delta_wc,
383  int button, bool control, bool shift
384  );
385 
397  void mouse_up(
398  RenderingContext* rendering_context,
399  const vec2& point_ndc, const vec2& point_wc,
400  int button, bool control, bool shift
401  );
402 
409  void key_down(const std::string& value);
410 
417  void key_up(const std::string& value);
418 
424  void button_down(int value);
425 
431  void button_up(int value);
432 
439  void dropped_file(const std::string& value);
440 
441  public:
442  void mouse_button_callback(int button, int action, int mods);
443  void scroll_callback(double xoffset, double yoffset);
444  void cursor_pos_callback(double xf, double yf);
445  void drop_callback(int nb, const char** p);
446  void char_callback(unsigned int c);
447  void key_callback(int key, int scancode, int action, int mods);
448 
449  protected:
450 
455 
459  void GL_terminate();
460  void update_clipping_config();
461 
462  private:
463  RenderingContext_var rendering_context_;
464  index_t width_;
465  index_t height_;
466  index_t frame_buffer_width_;
467  index_t frame_buffer_height_;
468  std::string clipping_config_;
469 
470  index_t button_down_;
471  bool control_is_down_;
472  bool shift_is_down_;
473  vec2 last_point_dc_;
474  vec2 last_point_ndc_;
475  vec2 last_point_wc_;
476  Color background_color_;
477  Color background_color_2_;
478  mat4 viewing_matrix_;
479  mat4 lighting_matrix_;
480  std::string background_image_;
481  GLUPContext* glup_context_;
482  bool dirty_;
483  };
484 
486 
487 }
488 
489 #endif
ComponentEncoding
Indicates the datatype used to encode each component of the colors.
Definition: image.h:74
ColorEncoding
Indicates how colors are encoded within the image.
Definition: image.h:66
Base class for all objects in the GOM system.
Definition: object.h:65
Implementation of RenderArea using ImGui.
Definition: render_area.h:56
RenderArea(index_t w, index_t h, index_t fb_w, index_t fb_h)
RenderArea constructor.
void resize(index_t w, index_t h, index_t fb_w, index_t fb_h)
Resizes this RenderArea.
void GL_terminate()
Deallocates OpenGL and GLUP objects.
void set_background_image(const std::string &value)
Sets the background image.
void set_projection_matrix(const mat4 &value)
Sets the projection matrix.
void mouse_down(RenderingContext *rendering_context, const vec2 &point_ndc, const vec2 &point_wc, int button, bool control, bool shift)
A signal that is triggered each time a mouse button is pushed.
void update_background_image_from_data(Memory::pointer ptr, Image::ColorEncoding color_encoding, Image::ComponentEncoding component_encoding, index_t width, index_t height)
Updates the background image from raw image data.
const Color & get_background_color_1() const
Gets the background color.
void set_background_color_1(const Color &value)
Sets the primary background color.
void key_up(const std::string &value)
A signal that is triggered each time a key is released.
void update()
Invalidates the memorized frame so that it will be updated on the next call to draw().
void mouse_move(RenderingContext *rendering_context, const vec2 &point_ndc, const vec2 &point_wc, const vec2 &delta_ndc, double delta_x_ndc, double delta_y_ndc, const vec2 &delta_wc, int button, bool control, bool shift)
A signal that is triggered when the mouse is dragged with a pushed button.
void snapshot(const std::string &filename, bool make_current=true, bool with_gui=false)
Saves a snapshot of this rendering area to an image file.
void update_memorized_frame()
Re-generates the memorized frame.
void GL_initialize()
Initializes OpenGL and GLUP objects.
const std::string & get_background_image() const
Gets the background image.
const mat4 & get_lighting_matrix() const
Gets the lighting matrix.
index_t get_frame_buffer_height() const
Gets the height of the window.
Definition: render_area.h:187
void key_down(const std::string &value)
A signal that is triggered each time a key is pushed.
void button_down(int value)
A signal that is triggered each time a mouse button is pressed.
const mat4 & get_viewing_matrix() const
Gets the viewing matrix.
RenderingContext * get_rendering_context() const
Gets the rendering context.
void mouse_up(RenderingContext *rendering_context, const vec2 &point_ndc, const vec2 &point_wc, int button, bool control, bool shift)
A signal that is triggered each time a mouse button is released.
void update_view_parameters()
Call this function if perspective mode is changed.
const mat4 & get_projection_matrix() const
Gets the projection matrix.
void dropped_file(const std::string &value)
A signal that is triggered whenever a file is drag-dropped into this RenderArea.
void set_lighting_matrix(const mat4 &value)
Sets the lighting matrix.
bool needs_to_redraw() const
Tests whether the window needs to be redrawn.
Definition: render_area.h:86
void set_clipping_config(const std::string &clipping_config)
Sets the current clipping configuration.
Definition: render_area.h:320
std::string get_gpu_information() const
Gets the GPU information.
index_t get_frame_buffer_width() const
Gets the width of the window.
Definition: render_area.h:179
void set_background_color_2(const Color &value)
Sets the secondary background color.
void draw_memorized_frame()
Draws the latest memorized frame.
void button_up(int value)
A signal that is triggered each time a mouse button is released.
const Color & get_background_color_2() const
Gets the secondary background color.
const std::string & get_clipping_config() const
Gets the current clipping configuration.
Definition: render_area.h:306
~RenderArea() override
RenderArea destructor.
std::string get_gpu_extensions() const
Gets GPU extensions.
void set_viewing_matrix(const mat4 &value)
Sets the viewing matrix.
index_t get_height() const
Gets the height of the window.
Definition: render_area.h:171
void resize_request(RenderingContext *rendering_context, int width, int height)
A signal that is triggered each time the render area is resized.
Helper class for OpenGL context management.
Color types.
byte * pointer
Pointer to unsigned byte(s)
Definition: memory.h:104
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
The base class for all composite objects in the GOM system.
Transformation of user input between the screen and the 3D space.
Helper class for OpenGL context management.
Definitions common to all include files in the skin_imgui library.