0
\$\begingroup\$

I have an array of 3 dimensional point objects, I can manipulate the input into this array into any configuration I want, for example, it could be a vector of floating point numbers, a vector of ints, etc.

Anyway, I want to display this 3d point cloud using OpenGL. How should I go about doing this? I know enough that I can create a 3d cube from structured inputs but how would I go about creating vertices from this unstructured input? If I don't need to construct these vertices how would I go about simply displaying these points as a cloud? Any suggestions or advice is welcome.

\$\endgroup\$
11
  • \$\begingroup\$ how would I go about creating vertices from this unstructured input? What does this mean? Your input has to be in some structure, otherwise it is just some random garbage and will look like random triangles if you draw it \$\endgroup\$
    – tkausl
    Commented Aug 10, 2015 at 7:47
  • \$\begingroup\$ @tkausl my apologies, it isn't structured as in they aren't already vertices. \$\endgroup\$ Commented Aug 10, 2015 at 7:49
  • \$\begingroup\$ So what are they? \$\endgroup\$
    – tkausl
    Commented Aug 10, 2015 at 7:56
  • \$\begingroup\$ @tkausl just something like Point(x,y,z), simply data points. They aren't structured such that they can be pushed into something like a vertex buffer, right? \$\endgroup\$ Commented Aug 10, 2015 at 7:59
  • \$\begingroup\$ What, you mean it is literally a textfile containing lines with Point(1, 2, 3) or what? \$\endgroup\$
    – tkausl
    Commented Aug 10, 2015 at 8:13

2 Answers 2

1
\$\begingroup\$

As stated in the comments, drawing points is as simple as drawing GL_POINTS instead of GL_TRIANGLES, you'll need one vertex instead of three of course.

Now to your non-structured input:

Of course it is structured. It may not be in the format OpenGL expects, but it definitely has some sort of structure, some format you're able to parse. In case of a text-format containing lines of three integers, you have to first parse those lines to get your three integers in binary format since ASCII (and other charsets) means nothing to the computer. After this, i recommend converting it to floats. Since OpenGL expects the data in one contiguous stream of data (at least if you don't do any advanced things with glVertexAttribPointer) you need to one float after the other, 4 bytes each, 3 floats per vertex -> 12 bytes per vertex tightly packed without empty space between them.

TLDR: Since you already know how to draw triangles or a cube (which itself is just built out of multiple triangles), you already know how the data looks OpenGL-expects and how to draw. So all you need to do now is convert your input data to the same format and draw your GL_POINTS.

\$\endgroup\$
1
\$\begingroup\$

The simplest solution to this would be simply buffering the vertices into a VBO like you normally do, then rendering them as GL_POINTS instead of GL_TRIANGLES or GL_TRIANGLE_STRIP.

This will give you a cloud of dots, that you can rotate the usual way with your vertex shader.

If you want nicely sized circles, you should use a geometry shader to create a camera-facing impostor/billboard from each vertex and process those using a fragment shader, you could event texture these.

While technically you could do the same with the built-in GL_POINTS approach, it is not supported properly by drivers in my experience, so you have to resort to your own geometry shader.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .