I’m working on a small app (Windows and Android) that reads a text file with coordinates and some additional info and then uses these infos to draw stuff on screen. I already created an app like that in Java that uses OpenGL_ES but I’m having troubles finding the right way to do it in Unity now (C#, version 2017.3.1f1 Personal).
The 3 most important things that I have to draw are:
- Some kind of line strip (GL_LINE_STRIP with OpenGL). The txt file lists coordinates of single vertices, which have to be connected in the right order (first vertex != last vertex).
- An untextured plane (GL_TRIANGEL_FAN or GL_TRIANGLES with OpenGL). The vertices in the text file describe a line strip (first vertex == last vertex) that has to be filled.
- A textured plane (rectangular with 90° angles). The txt file includes the coordinates of the 4 corner vertex, which then have to be used to display a picture (comes with the txt file) in the right spot.
What I have to do with these objects:
- Change the line width of the line strips
- Change the color of the line strips and untextured planes
- Get a grip on the created objects, so I can store them in an array in my static class, delete them from the scene and load them again later
- They don’t have to cast shadows, be animated or move but they do have to be created at runtime, which means that I can’t just import a mesh that was created in e.g. Blender.
I already tried this but google tells me that you can’t change the line width of stuff drawn with OpenGL in Unity and I’m not sure how you would even reuse the created objects (or whatever they are):
void OnRenderObject() {
Shader shader = Shader.Find("Hidden/Internal-Colored");
Material mat = new Material(shader);
mat.SetPass(0);
GL.Begin(GL.LINE_STRIP);
GL.Color(new Color(1,0,0));
GL.Vertex3(0,0,0);
GL.Vertex3(0,20,0);
GL.Vertex3(0,20,20);
GL.Vertex3(0,0,20);
GL.End();
}
Is there a way to do all of this in Unity without using additional assets from the store?