Lab 05: October 16, 2018
Overview
Today's lab is to manually set the colour of each pixel in a raster. We will do this by defining an
array of pixel colours, set each pixel to the colour intended and pass this array of colours to OpenGL
to render for us.
Tasks
In order to get familiar with how to set the pixel colour, we will render stripes and checkerboard patterns.
Using pixel coordinates (x, y) and linear indexing: int bufferInd = y*SCREENWIDTH+x;
We can create vertical bands in the image using the simple algorithm:
int xband = x % (2*bandwidth);
if( xband < bandwidth ) gsPixelBuffer[bufferInd] = WHITE;
else gsPixelBuffer[bufferInd] = BLACK;
We can create a checkerboard pattern in the image using the simple algorithm:
int xband = ((x % (2*bandwidth)) < bandwidth)?1:0;
int yband = ((y % (2*bandwidth)) < bandwidth)?1:0;
int mag = 255*( xband^yband );
gsPixelBuffer[x,y] = CRGB(mag, mag, mag);
Note: You must hit 'r' to tell the screen to refresh the pixels.
Code Files
Lab05.cpp
makefile
colour.h
mathvector.h
References
OpenGL: glDrawPixels