/******************************************************************/ /* Pixel operations, Project 6, CS345 */ /******************************************************************/ #include #include #include #include #include #include #include #include #include "lowlevel.h" /* constants */ #define RED 0 /* offset to red byte */ #define GREEN 1 /* offset to green byte */ #define BLUE 2 /* offset to blue byte */ /* local data */ /* pointer to image */ GLubyte* canvas; void initCanvas(int w, int h) { int i; /* get memory */ canvas = (GLubyte*) malloc(w*h*3*sizeof(GLubyte)); /* clear it */ for (i=0; i= width) || (y < 0) || (y >= height)) return; canvas[3*width*(y)+3*(x)+RED] = r*255; canvas[3*width*(y)+3*(x)+GREEN] = g*255; canvas[3*width*(y)+3*(x)+BLUE] = b*255; } /* draw the canvas array on the screen */ void flushCanvas() { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glRasterPos3f(0.0,0.0,0.0); glDrawPixels(width,height,GL_RGB,GL_UNSIGNED_BYTE,canvas); }