This is old C++ code originally intended to be a playground for 3D math.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

96 lines
3.5 KiB

/**
* \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__