representing a 2D array as colored points

First I would like to say that i’m an absolute beginner.

I have an a moderate size 2 dimensional array filled with floating point values between 10.00 and 100.00. I would like to represent each array value point as a pixel with a color specified by the numerical value held by the array location.

I create a window size slightly larger than the dimensions of the array and would like to have the points drawn starting in the top left with array value [0][0] with [0][1] being one pixel to the right in the x direction and [1][0] being one pixel down in the y direction.

I’m leaving the coloring algorithm out of the below code because it’s complicated and i’ve verified it working.


for (int y = 0; y < array row length; y++)
 for (int x = 0; x < array column length; x++)
   glVertex3f(x, y, 0.0f);


this isn’t working and doesn’t appear to be drawing anything. I can draw triangles and shapes which appear white on a black background.

I’m expecting this code to produce a white rectangle of the dimensions of the array, but i’m only getting the black background.

Any help would be greatly appreciated. TYIA.

You need to cast int to float for the arguments or make your loops float or use glVertex3i (declaring the variables as GLint just to be safe).

You also do not specify a color, the points will be colored with whatever is lying around in the state machine.

glColor3f(1.0f, 1.0f, 1.0f, 1.0f);

The pipeline affects points, the points are transformed clipped textured etc in 3D like all other primitives.

This is really horrendously inefficient code.

glDrawArrays would be a better choice.