// // Computergraphik II // Prof. Dr. Juergen Doellner // Wintersemester 2001/2002 // // Rahmenprogramm fuer Aufgabenzettel 3 // // Autoren: Florian Kirsch (kirsch@hpi.uni-potsdam.de) // Marc Nienhaus (nienhaus@hpi.uni-potsdam.de) // Juergen Doellner (doellner@hpi.uni-potsdam.de) // #include "cgraster.h" CGRaster::CGRaster(int width, int height) : width_(width), height_(height) { raster_ = new Color[width_ * height_]; clear(); } CGRaster::~CGRaster() { delete [] raster_; } int CGRaster::width() const { return(width_); } int CGRaster::height() const { return(height_); } void CGRaster::clear(const Color& c) { for(int i = 0; i < width_ * height_; ++i) { raster_[i] = c; } } Color& CGRaster::getPixel(int x, int y) const { assert(x < width_); assert(y < height_); return raster_[x + y * width_]; } void CGRaster::setPixel(int x, int y, const Color& c) { assert(x < width_); assert(y < height_); raster_[x + y * width_] = c; } void CGRaster::draw() const { int x,y; // draw pixels glColor3f(0, 0, 0); glBegin(GL_QUADS); for(y = 0; y < height(); ++y) { for(x = 0; x < width(); ++x) { const Color& c = getPixel(x,y); glColor4d(c[0], c[1], c[2], c[3]); glVertex2f(x , y); glVertex2f(x + 1, y); glVertex2f(x + 1, y + 1); glVertex2f(x , y + 1); } } glEnd(); // draw grid glColor3f(0.5, 0.5, 0.5); glBegin(GL_LINES); for(x = 0; x <= width(); ++x) { glVertex2f(x, 0); glVertex2f(x, height()); } for(y = 0; y <= height(); ++y) { glVertex2f(0, y); glVertex2f(width(), y); } glEnd(); }