/* * bigPix.c * Draws a 50x50 array of big pixels, for practice in low-level graphics */ #include #include #include "lowlevel.h" /* faux framebuffer definitions */ void readInput(void); /* dimensions - each pixel is 10x10, and the window is 50x50 pixels */ static int pixelSize=10; static int numberOfPixels = 50; /* Call your triangle drawing program from here; this is the function which draws the contents of the framebuffer by coloring pixels. */ void drawContents(void) { /* The colorPixel function: int x, int y, GLubyte r, GLubyte g, GLubyte b x,y = pixel address r,g,b = pixel color */ readInput(); colorPixel(25,25,0xFF,0x00,0x00); } /* Reads in the triangle vertices and colors from stdin */ void readInput(void) { int length = 100; char* line; int items; float x,y; line = (char*) malloc(length+1); while (fgets(line,length,stdin) != NULL) { items = sscanf(line, "%f %f \n", &x, &y); if (items != 2) printf("Failed to read x and y \n"); else printf("x %f y %f\n",x,y); } } /* Called by glut when window is refreshed */ void display(void) { /* clear window */ glClear(GL_COLOR_BUFFER_BIT); /* draw current array of pixels */ drawBigPixelArray(); /* go ahead and draw, don't wait for more commands... */ glFlush(); } /* Called by main on initialization */ void init() { int size; /* Sets up the camera and it's relation to screen pixels */ glMatrixMode (GL_PROJECTION); glLoadIdentity (); size = numberOfPixels*pixelSize; glOrtho(0.0, 1.0*size, 0.0, 1.0*size, -1.0, 1.0); /* initialization of a 50x50 array of faux pixels */ initBigPixelArray(numberOfPixels,numberOfPixels,pixelSize); /* call function that draws stuff in pixel array */ drawContents(); } int main(int argc, char** argv) { /* Open a window in upper left corner of screen */ /* Calls init(), which sets up contents. */ glutInit(&argc,argv); glutInitWindowSize(numberOfPixels*pixelSize,numberOfPixels*pixelSize); glutCreateWindow("bigPix"); glutDisplayFunc(display); init(); glutMainLoop(); }