Variable color for GL_POINTS plotting to window

I am plotting points to the window and based on the pixel position I want to map a range of rgb color to it one shade/color per pixel. This is the loop:

glViewport(0.0, 0.0, 600.0, 600.0);
float a;

for (int i = 0; i < 256*1024; i++) {
   a = fmod((float)i, 255.0f);
   glColor3f(a, 0.0, 0.0);
   graph[i].x = output.x;
   graph[i].y = output.y;
   glVertex2f(graph[i].x, graph[i].y);


this is in side a render function call to glutDisplayFunc(). It just prints all the pixels as red doesn’t shade any of them darker. Is it because its too light of a change.

That glClear needs to come out of the loop for starters. It’s illegal to call glClear between glBegin and glEnd, and you certainly don’t want to clear after drawing each point. Put it at the start of each frame instead.

Secondly, glColor3f expects colours in a 0…1 range, not a 0…255 range. Use glColor3ub for 0…255.

I was wondering if it could go in between glBegin and glEnd. Thank you as well I’ll read up on glColor3ub and try it out.