• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by 1337GameDev · Feb 05, 2012 at 07:05 AM · linedrawgl

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?

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

  • Sort: 
avatar image

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);

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

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.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by dhawalbanker · Dec 10, 2013 at 08:15 AM

You found the answer?

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

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

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I draw 2D triangles in Unity 5? 0 Answers

Drawing a Range Icon in 3D Space 0 Answers

Draw a line to a new pontential character position/target 1 Answer

Click objects to draw a line between them 0 Answers

Drawning Line Problem useing custom class 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges