- Home /
GL Lines work on one platform, others, not so much
I am currently in the process to putting out a couple of builds of a project I am actively working on Independently. I will be deploying out to Linux, Windows and Mac. When I build out the game and send it to any Mac computers, no problems whatsoever. However, if all of my Windows and Linux players are experiencing the same problems. Here's whats going on.
I am using GL lines to turn things from a 3D mesh into a "wireframe" texture through javascript. Here is that code:
var lineColor : Color;
var backgroundColor : Color;
var ZWrite = true;
var AWrite = true;
var blend = true;
private var lines : Vector3[];
private var linesArray : Array;
private var lineMaterial : Material;
private var meshRenderer : MeshRenderer;
public function Start ()
{
meshRenderer = GetComponent(MeshRenderer);
if(!meshRenderer) meshRenderer = gameObject.AddComponent(MeshRenderer);
meshRenderer.material = new Material("Shader \"Lines/Background\" { Properties { _Color (\"Main Color\", Color) = (1,1,1,1) } SubShader { Pass {" + (ZWrite ? " ZWrite on " : " ZWrite off ") + (blend ? " Blend SrcAlpha OneMinusSrcAlpha" : " ") + (AWrite ? " Colormask RGBA " : " ") + "Lighting Off Offset 1, 1 Color[_Color] }}}");
lineMaterial = new Material("Shader \"Lines/Colored Blended\" { SubShader { Pass { Blend SrcAlpha OneMinusSrcAlpha ZWrite Off Cull Front Fog { Mode Off } } } }");
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
linesArray = new Array();
var filter : MeshFilter = GetComponent(MeshFilter);
var mesh = filter.mesh;
var vertices = mesh.vertices;
var triangles = mesh.triangles;
for (i = 0; i < triangles.length / 3; i++)
{
linesArray.Add(vertices[triangles[i * 3]]);
linesArray.Add(vertices[triangles[i * 3 + 1]]);
linesArray.Add(vertices[triangles[i * 3 + 2]]);
}
lines = linesArray.ToBuiltin(Vector3);
}
public function OnRenderObject()
{
meshRenderer.material.color = backgroundColor;
lineMaterial.SetPass(0);
GL.PushMatrix();
GL.MultMatrix(transform.localToWorldMatrix);
GL.Begin(GL.LINES);
GL.Color(lineColor);
for (i = 0; i < lines.length / 3; i++)
{
GL.Vertex(lines[i * 3]);
GL.Vertex(lines[i * 3 + 1]);
GL.Vertex(lines[i * 3 + 1]);
GL.Vertex(lines[i * 3 + 2]);
GL.Vertex(lines[i * 3 + 2]);
GL.Vertex(lines[i * 3]);
}
GL.End();
GL.PopMatrix();
}
When used on a Windows or Linux machine none of the lines rendered appear the color they are supposed to be. I know they are being drawn but the color is black not the color in the inspector (green, white, etc.) Any idea where to even begin?
EDIT: I looked a little further and testedout my builds and it looks like the mesh.renderer.material works, its just the lines that aren't being put into the colors specified. This led me to start looking at OnRenderObject() to make sure that was working up to snuff. Thoughts?
Shot in the dark: Have you verified that the shader you use for your material works the same on all platforms? $$anonymous$$ight also try using a pre-created material rather than a new $$anonymous$$aterial().
I watched what the script does to the shader ( I tried in a couple different shaders for testing purposes) and it replaces it with a shader that is created on the fly called Lines/Background. I have a feeling it's not compatible with Windows / Linux. I was actually about to try a pre material. I'll update with results.
Answer by carterCook · Jan 19, 2016 at 08:32 AM
I found that creating a new material via code shows up in the player, but not in the windows build. I used a material from the editor instead, and then it worked in the build :)
Your answer
Follow this Question
Related Questions
Why does my game run much faster on Windows than Linux 1 Answer
Is using Unity a viable way to create cross-platform screensavers? 0 Answers
Linux-export: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.14' not found 2 Answers
Dual Webcams work under Windows but not Linux 2 Answers
Graphics library 1 Answer