Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
softwarerenderer.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2012,2013,2022 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 
44 #ifndef SOFTWARERENDERER_HPP
45 #define SOFTWARERENDERER_HPP 1
46 
47 
48 #include <cairo.h>
49 #include <gtk/gtk.h>
50 #include "renderer.hpp"
51 
52 
60 class SoftwareRenderer : public Renderer {
61 
62  GtkWidget *_darea;
63  cairo_surface_t *_surface;
64  unsigned char *_buf;
65  int _width;
66  int _height;
67  int _stride;
68 
69  double *_zbuf;
70 
71  Vec3D _material_diffuse_color;
72  Vec3D _material_ambient_color;
73  Vec3D _color;
74 
75  Transformation _modelview;
76  Transformation _totalmatrix;
77  Transformation _normalmatrix;
78 
79  void swap( int &x0, int &y0, double &z0,
80  int &x1, int &y1, double &z1 );
81 
82  void set_pixel( int i, int j, const Vec3D &color );
83  void clear( const Vec3D &color );
84  void flat_2d_triangle( int x0, int y0, double z0,
85  int x1, int y1, double z1,
86  int x2, int y2, double z2,
87  const Vec3D &color );
88  void line_2d( int x0, int y0, double z0,
89  int x1, int y1, double z1,
90  const Vec3D &color );
91 
92 public:
93 
96  SoftwareRenderer( GtkWidget *darea );
97 
100  SoftwareRenderer( cairo_surface_t *surface );
101 
104  virtual ~SoftwareRenderer();
105 
106  virtual void start_rendering( void );
107  virtual void end_rendering( cairo_t *cairo );
108 
109  virtual void set_material_diffuse_color( Vec3D color );
110  virtual void set_material_ambient_color( Vec3D color );
111  virtual void set_color( Vec3D color );
112 
113  virtual void disable_lighting( void );
114  virtual void enable_lighting( void );
115 
116  virtual void enable_view_settings( void );
117 
118  virtual void flat_triangle( const Vec3D &x0,
119  const Vec3D &x1,
120  const Vec3D &x2,
121  const Vec3D &n );
122  virtual void shaded_triangle( const Vec3D &x0, const Vec3D &c0,
123  const Vec3D &x1, const Vec3D &c1,
124  const Vec3D &x2, const Vec3D &c2,
125  const Vec3D &n );
126  virtual void line( const Vec3D &x0,
127  const Vec3D &x1 );
128 };
129 
130 
131 #endif
3D renderer base class.
Definition: renderer.hpp:56
Software 3D z-buffer renderer.
Definition: softwarerenderer.hpp:60
SoftwareRenderer(GtkWidget *darea)
Constructor for rendering to drawing area.
Definition: softwarerenderer.cpp:49
virtual ~SoftwareRenderer()
Destructor.
Definition: softwarerenderer.cpp:71
Transformation for homogenous three dimensional space.
Definition: transformation.hpp:70
Three dimensional vector.
Definition: vec3d.hpp:58
3D renderer base class


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.