0
votes

I'm using OpenGL to display 3d model files such as stl and obj via Assimp.

I have a file containing a set of points and a corresponding value (not necessarily on the object) and I'd like to color each vertex of the shape based on where it lies in the range of all values.

My current plan is to open a .txt file from my .vert or .frag file and just color the vertices that way. However, it's not clear to me how the syntax of GLSL differs from that of C++. Can I use similar syntax to open the file and just use the values all via the .vert file? Is there another way to do it?

1
It's not clear what "corresponding value" means in this context. How does a vertex "lie in the range of all values"? Are you talking about the vertex relative to some arbitrary position? - Nicol Bolas
You can't read files from GLSL code. The shader code will be executed on the GPU. You need code running on the CPU to make the necessary library/system calls to read the content of a file. - Reto Koradi
@RetoKoradi, thanks! - faeophyta
@NicolBolas, I am given a file with points and corresponding values at those points. Those points are not necessarily on the surface, but they are close. I need to color all the points of the surface based on the KNN from the file. The value at the point in the file is given an RGB value based on where it lies in the range (file.min, file.max). Does that make more sense? I phrased it rather badly in the question. - faeophyta

1 Answers

1
votes

You cannot read data from file from OpenGL Shaders. What you can do is read the data in your cpp code and bind a data as attribute or uniform. If the data is very large, then you can send it as a texture.