2d graphics

A bit of a long question but id be greatful if someone could point me in the right direction.

I have the following code which produces a 64x64 checkerboard grid:

#include <stdlib.h>
#include <GL/glut.h>

#define checkImageWidth 512 //64
#define checkImageHeight 512 //64
GLubyte checkImage[checkImageHeight][checkImageWidth][3];

void makeCheckImage(void)
int i,j,c;

for (i = 0; i< checkImageHeight; i++) {
for (j = 0; j< checkImageWidth; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;

void myinit(void)
glClearColor(0.0, 0.0, 0.0, 0.0) ;
glShadeModel(GL_FLAT) ;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

void display(void)
glutSwapBuffers() ;
glDrawPixels(checkImageWidth, checkImageHeight, GL_RGB,
GL_UNSIGNED_BYTE, checkImage);

int main (int argc, char** argv)
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize(513, 513);



My question is, how do i single out one of these squares and assign it a specific colour? What method would do this? I have been trying colorTables but haven’t got it to work yet.

To make it clear why i want individual squares highlighted is because i am trying to model Salmon migration down a river and each square is going to represent a certain number of salmon which will ‘swim’ down the river. For this reason this square that has been assigned a certain color needs to know where the next square is so it can ‘swim’ into it.

Any general comments or specfic answers welcome;


You have a rectangular grid of pixels and don’t know where which checkered plate is even though you have the formula to fill in values in your app?
Analyze makeCheckImage, fill in the new values and redraw.

Though it’d actually be smarter to define a rectangular grid of flat shaded(?) quads and assign colors to them. The geometry never changes (actually you could do gorgeous 3D stacks varying the height), only the color needs to be changed per simulation step. This crys for vertex arrays or VBOs.

You could also use a 1D texture and have the texture coordinate count the salmons. This would be able to do iso-lines with the right texture.


I understand that the key to giving individual squares color is in the makeCheckImage but dont know how to single it out. The bottom left hand side of the grid is positioned at (-1,-1) but im not sure where the other corners are positioned. Do i have to specify individual coords to highlight the square or are they all automatically numbered for me?

Ive been playing with that makeCheckImage method for a while now and cant get much joy out of it. It must be really simple to assign a colour to a square its just that i dont know the exact command. Any ideas?

[This message has been edited by lynx7 (edited 03-10-2004).]