// // renderer.h // // New and improved renderer // // Copyright (C) J. Belson 1999.11.22 // // $Author: jon $ : $Date: 2003/10/11 18:11:00 $ // #ifndef _RENDERER_H_ #define _RENDERER_H_ #include "fcolour.h" #include "light.h" #include "point2d.h" #include "progress.h" #include "settings.h" #include "triangle3d.h" #include "types.h" #include "zbuffer.h" /** * Renders triangles to the screen */ class renderer { private: int haze_r, haze_g, haze_b; float haze_intensity; // Atmospheric haze colour fcolour haze; // Colour of current polygon fcolour col; // Get extents of triangle 'idx' void get_extents(int idx, float* x1, float* x2, float* y1, float* y2); protected: static const int MAX_HEIGHT = 2048; int width, height; int bytes_per_row; progress* prog; // Normal vector of current triangle vector3d norm; bool kludge_texture; // Sun light_source light; fcolour ambient; float ambient_intensity; float direct_intensity; unsigned long int* gfx; // Only render polygons whose left edges are // between these horizontal limits int left_border, right_border; // Terrain data const triangle3d* tri3d; const point2d* pnt2d; const vector3d* vec3d; int num_tri; unsigned long* fb; zbuffer* zb; // Rendering options bool lighting; bool fog; bool blend; unsigned long int col32; // Edge tables float table_start[MAX_HEIGHT], table_end[MAX_HEIGHT]; float depth_start[MAX_HEIGHT], depth_end[MAX_HEIGHT]; settings* my_settings; // Render horizontal line in required fashion virtual void render_scanline(int y); void apply_haze(uint8* r, uint8* g, uint8* b, float depth); void apply_haze(fcolour& col, float depth); // Return true if triangle 'idx' should be rendered bool check_extents(int idx); public: renderer(int left, int range, progress* p = 0); // Turn on/off render options void set_blend(bool b); void set_fog(bool b); void set_lighting(bool b); // Set light source vector void set_light(const vector3d& l); void set_light_colour(fcolour& col); void set_light_ambient(fcolour& col); // Pass data for render virtual void setup( const triangle3d* t3d, const point2d* p2d, const vector3d* v3d, int num_tri, unsigned long* fbuf, int bpr, int width, int height, zbuffer* zb = 0); // Start the actual rendering void do_render(void); // Clear buffer to black void clear(void); }; #endif // _RENDERER_H_