Draw array of points with individual colors

Started by
17 comments, last by CommanderLake 4 years, 6 months ago

How do draw thousands of points each with their own individual brightness for a 2D visualisation?

I use OpenTK in C#.

Advertisement

Since you tagged that opengl, you add lets say attribute/layer and bind another vertex attrib pointer which points to the color structure of the vertex structure itself, it can be done in other way...

This is a quite unspecific question. Are there any constraints (point size, ordering, software, API, etc.)? Otherwise, just upload your array of position and color pairs, create a simple shader and let OpenGL fire away.

 

Greetings

I'm very much not a graphics programmer so please try to be descriptive, my aim is to display data from a USB oscilloscope in my own way, I have the oscilloscope data stream in the form of shorts and I want to draw a squiggly line with it that fades away as new data comes in.

Since I can already draw dots I figured that may be sufficient and not overcomplicate it as I can get sufficient data points to form a line with dots.

I just need to be able to at least specify the alpha of the dots so I can make them fade away.

This is what I use to draw points in another application:


GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Color4(1.0F, 1.0F, 1.0F, 1.0F);
GL.PointSize(1.0F);
GL.Enable(EnableCap.PointSmooth);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.EnableClientState(ArrayCap.VertexArray);
GL.Disable(EnableCap.DepthTest);
GL.Disable(EnableCap.CullFace);
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GL.BufferData(BufferTarget.ArrayBuffer, buffersize, points1, BufferUsageHint.StaticDraw);
GL.VertexPointer(2, VertexPointerType.Float, 0, 0);
GL.DrawArrays(PrimitiveType.Points, 0, pcount);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
GL.DisableClientState(ArrayCap.VertexArray);
SwapBuffers();

 

If you have some time read the following tutorials until you reach the textures section:

https://learnopengl.com/

The 5 first tutorials should tell you everything you need, to do what you want. It is basically just copying the data to the GPU and issuing a draw command. To output the correct colour and for other fancy stuff, you use small, so-called shader programs that run on the GPU. But you will see yourself how easy it is, once you finished the tutorials. The only problem might be, that the tutorials are written in C++ and not C#. But I guess you can translate them easily.

 

Greetings

Coming back to this project, gave myself an OpenTK OGL 4.5 crash course, can make and draw points with shaders and vertices, no idea how to set the position or brightness of the points with buffers of data on every frame.

How does one position millions of vertices from an array of 2D float coordinates with their brightness set from a second array with minimal overhead?

DerTroll said:
If you have some time read the following tutorials until you reach the textures section: https://learnopengl.com/

Two chapters was translated to OpenTK: https://github.com/opentk/LearnOpenTK

CommanderLake said:
can make and draw points with shaders and vertices, no idea how to set the position or brightness of the points with buffers of data on every frame.

You need to draw squares or circles for 2D and spheres for 3D for drawing points. You cannot set size for points and width for lines in modern OpenGL. If you need width for line strip you need to use triangle strip instead.

I've done the 1st 5 chapters of this: http://dreamstatecoding.blogspot.com/2017/01/opengl-4-with-opentk-in-c-part-1.html

I said I can make points with shaders and vertices, I did not say I want to set the size of the points, I did not say I want to draw lines, I do not want circles or squares.

I have a buffer object on the GPU named vbo that contains the xy coordinates of the points, I have a _vertexArray with shaders, how do I apply the xy coordinates buffer object(vbo) to the position attribute(0) of the _vertexArray?

The position attribute of the vertex shader has 4 dimensions, will that make it difficult to apply a 2 dimensional array to it, can the position attribute be 2 dimensional?

8Observer8 said:
You cannot set size for points and width for lines in modern OpenGL.

glLineWidth and glPointSize have not been deprecated. It is possible that there are discrepancies between vendors though.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

This topic is closed to new replies.

Advertisement