• 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

· Add your reply
  • 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

OnDrag Draw Line For Pathfinding... 1 Answer

Allowing User to Draw a Gameobject 0 Answers

Debug.DrawLine problem 1 Answer

Free script/plugin for drawing a line with a collider? 2 Answers

Draw line within bounds of circular collider 0 Answers


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