Results 1 to 2 of 2

Thread: representing a 2D array as colored points

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2009

    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.

  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Bay Area, CA, USA

    Re: representing a 2D array as colored points

    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.

Similar Threads

  1. How to vary point sizes in array of points data
    By jshafferman in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 09-25-2014, 06:58 AM
  2. Vertex Array drawing random points and colors
    By Beiufin in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-04-2012, 10:09 AM
  3. Representing a grid and rotating around it
    By Dan M in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-29-2010, 02:28 PM
  4. Representing patches/surfaces
    By jamesmilne in forum COLLADA
    Replies: 1
    Last Post: 07-07-2005, 06:25 PM
  5. Fastest method for colored points
    By karbuckle in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-23-2004, 04:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean