rasterize.h
3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* \file rasterize.h
*
* \brief Methoden um auf ein Canvas zu zeichnen
*
* Der rasterizer stellt Methoden zur verfügung um auf ein canvas zu
* zeichnen. Darunter den Canvas zu leeren, Punkt, Linie, Polygon
* (gefüllt und ungefüllt) und Polyeder zeichnen und die Farbe
* eines bestimmten Punktes im Zeichenpuffer ermitteln.
* Diese Klasse ist abstrakt. Ein Rasterizer wird immer von einem
* Canvas erzeugt werden, damit man einen zu diesem Canvas passenden
* Rasteriser hat. Implementiert ist ein Software-Rasterizer zum zeichnen
* auf ein X11 oder X11-shm Canvas.
*
* \author Georg Steffers <georg@steffers.org>
*
* \date 04.12.2003
*
* \version ..2002 (Georg Steffers): erste funktionierende Implementation
* \version 04.12.2003 (Georg Steffers): beginn der Dokumentation via doxygen
*/
/*
* Copyright (C)2003 Georg Steffers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __rasterizer_h__
#define __rasterizer_h__
#include "canvas_imps/canvas_imp.h"
#include "geometry/polygon.h"
#include "geometry/polyeder.h"
class rasterizer {
protected:
unsigned x_size;
unsigned y_size;
canvas_imp* sinfo;
vertex_list screen_p_vl;
polygon screen_p;
double** zbuf;
public:
rasterizer(unsigned = 0, unsigned = 0, canvas_imp* = NULL);
virtual void clear_buffer(void) const=0;
virtual void draw_point(unsigned x, unsigned y,
unsigned long col) const=0;
virtual void line(double, double, double, double,
unsigned long) const=0;
virtual void draw_polygon_flat(const polygon&, unsigned long) const=0;
virtual void draw_polygon_wire(const polygon&, unsigned long) const=0;
virtual void draw_polyeder_wire(const polyeder&, unsigned long) const=0;
unsigned long get_color(unsigned red, unsigned green, unsigned blue) {
return sinfo->ext_to_native(red, green, blue);
}
virtual unsigned get_x_size(void) const { return x_size; }
virtual unsigned get_y_size(void) const { return y_size; }
};
class sw_rasterizer : public rasterizer {
private:
unsigned char* adr_of_point(unsigned, unsigned) const;
void draw_point_at_paddress(unsigned char**, unsigned long) const;
public:
sw_rasterizer(unsigned xs, unsigned ys, canvas_imp* ci) :
rasterizer(xs, ys, ci) {}
void clear_buffer(void) const;
void draw_point(unsigned x, unsigned y, unsigned long col) const;
void line(double, double, double, double, unsigned long) const;
void draw_polygon_flat(const polygon&, unsigned long) const;
void draw_polygon_wire(const polygon&, unsigned long) const;
void draw_polyeder_wire(const polyeder&, unsigned long) const;
};
#endif // __rasterize_h__