Jump to content
  • Advertisement
CommanderLake

OpenGL Draw array of points with individual colors

Recommended Posts

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

I use OpenTK in C#.

Edited by CommanderLake

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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();

 

Edited by CommanderLake

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!