- Home /
GL.Line help? Cannot see line drawn... draw grid using gl.line
I am running into trouble with drawing a simple line to test the gl.line technique. How is this method used?
I used code in the documentation to draw a simple line, but nothing shows up. I am also confused as to what the material is used for that it asked for. What are the requirements to set up this material? Where do i have to use this material for my lines to show up?
Here is my code attached to an empty object:
void OnPostRender() {
if (!mat) {
Debug.LogError("Please Assign a material on the inspector");
return;
}
GL.PushMatrix();
mat.SetPass(0);
GL.LoadPixelMatrix();
GL.Color(Color.yellow);
GL.Begin(GL.LINES);
GL.Vertex3(0, 0, 3);
GL.Vertex3(Screen.width, Screen.height, 3);
GL.End();
GL.PopMatrix();
}
Can i set a transparency of the lines? Why doesnt my line show up?
Do i have to call this method somewhere, i assumed it is called in the draw procedure as it draws these last...
Any ideas?
Answer by Seizure · Jul 02, 2013 at 02:36 PM
Instead of: GL.Vertex3(Screen.width, Screen.height, 3);
Try : GL.Vertex3(1/Screen.width, 1/Screen.height, 3);
GL.Lines is normalized (all values are from 0 to 1);
Answer by Em3rgency · Jul 02, 2013 at 02:43 PM
For the lazy approach: http://answers.unity3d.com/questions/482128/draw-grid-lines-in-game-view.html
My answer to that question gives you a ready to go script that you can attach to your camera and have a custom sized, 3D or 2D grid in the game world.
Answer by Gerente · Sep 28, 2014 at 02:58 PM
Did you assign the "OnPostRender()" event to a camera? use Debug.log() to be sure that the event is being executed.
"OnPostRender is called after a camera finished rendering the scene.
This function is called only if the script is attached to the camera and is enabled. OnPostRender can be a co-routine, simply use the yield statement in the function."
More info: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnPostRender.html