graphical chart drwaing

Hello ,

If I have a 2D - Array image [X][Y] , I wonder if there is in the Opengl any support for drawing a chart or Histogram like this one :

If there is asupport in opengl for histogram drawing where I can find a tutorial or source code help me on that ?

With my thanks in advance

I think you’re out of luck for histogram support; there isn’t any as far as I know.

Off the top of my head the only thing I could think of is iterating over the image (reading width(x)*height(y) pixels with glReadPixels) and keeping a running sum of each instance of a color.
Then you have your histogram data and it’s a matter of drawing a chart at that point.

Good luck.

Thank you Aeluned,

Could pls explain your idea in deatils so I can get easily?

Any Hint ?

Is it too easy or too dificult to answer

Hello !

If I understand correctly, you want to draw a histogram that you already have.

OpenGL is not specialized in any way. All that it can do is draw lines, points and polygons with or without textures. It can light, do depth, alpha, stencil test and so on. It does not have functions for displaying buttons, function graphics, windows and the like.

In order to display a plot you should code all that you want to be displayed.

Here are the elements of that plot:

  • the 2 axis (draw with glBegin(GL_LINES))
  • the text (draw it with wglUseFontOutlines or similar name and with glCallList). You can display rotated text also because you draw text like geometry
  • the function (display it as red boxes with glBegin(GL_QUADS));
  • the dotted lines (use glLineStipple)

As you can see, there is much to do to draw that function…

I made a function drawing class for myself a while ago since I didn’t want to code all that everytime I would have displayed a function.

All the logic behind the function draw, as the scaling and showing important points is up to you to code.

Hope I have helped you.

Hello fuxiulian ,

Thank you Vmuch for your useful help. But the difficult I faced that I didn’t know exactly how to start the code . I mean I have the array[x][y] which value goes from 0 … 255 ( integers) . What will be values of x-axis and what will be the values of Y-axis?. Do I have to draw fixed lines using (GL_LINES)for x,y axises?.

Could you pls post the draw function you wrote as a demo I can followed? .

Thanks in advance.

Done .