Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by 1337GameDev · Jul 14, 2014 at 10:42 PM · worldlinesglonpostrender

Use Gl.Lines to connect Vector3 points in world space

I have the basic idea for GL and how to render lines, but i am a bit confused on how to render in world space given Vector3 coordinates.

I know I must either use GL.modelView or MultMatrix to render them in world space.

The real use is to iterate over a list of Vector3 objects of a path of one of my units, and render a line between them. I know I want to make a vertex at my unit, and for the first point in the list. Then I loop for every other vertex in the list and make a GL.Vertex call.

Here is my current snippet (that compiles but shows no lines): Current OnPostRender code

Comment
Add comment · Show 2
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 AlucardJay · Jul 15, 2014 at 05:18 AM 0
Share

maybe the code in this answer will help. sorry I don't have any more information.

avatar image 1337GameDev · Jul 15, 2014 at 09:52 PM 0
Share

I have seen that post, but wanted to write my own code, ins$$anonymous$$d of just blatant copying, especially since that does way more than what I want.

Plus, there is little to no explanation for that code. Thanks anyways.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Jul 15, 2014 at 06:23 AM

If you want to setup the GL context for a specific camera, all you have to do is:

 Camera cam;
 
 GL.LoadProjectionMatrix(cam.projectionMatrix);
 GL.modelview = cam.worldToCameraMatrix;

Now you're rendering in world space from that camera view.

edit
If your camera doesn't cover the whole screen, you also need to set the viewport so everything you draw is clipped by the viewport rect and the projection is actually centered in the viewport:

 GL.Viewport(cam.pixelRect);
Comment
Add comment · Show 2 · 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 1337GameDev · Jul 15, 2014 at 09:50 PM 0
Share

Hmm, both code segments seemed to solve my issue! Thanks a lot! Where did you learn GL concepts?

Can you explain or link me to a page/wiki that explains what these do? I would love to learn what this code does, rather than just "use it and have no idea what it does."

Plus, if I encounter problems I have to then ask others again. I can also pass on my knowledge to others who may not know.

$$anonymous$$y main camera (that renders my entire scene) should cover the entire screen, but for some reason needs the viewport code. Why would that be? (it's my main game view camera).

avatar image Bunny83 · Jul 16, 2014 at 12:02 PM 1
Share

Uhm, no sorry ;) I started program$$anonymous$$g 19 years ago. In the beginning i programmed in pascal (mainly DOS/W95) and later i switched to delphi. I started diving into OpenGL about 14 years ago i guess. The most famous OGL tutorials are probably the NeHe turorials because the example code of most tutorials has been ported to about 30 different (program$$anonymous$$g) lanugages. The first ones are already a bit outdated and of course not directly related to Unity. OpenGL is just an API, but it helps to understand how the GPU works.

Unity's GL class has some similarities to OpenGL. If you want to understand how to setup a certain "view" you should understand the graphics pipeline and what each stage actually means (local->world->camera->projection->clipping->screen). In plain OpenGl there's no definition for local, world or camera space. It's all combined in the modelview matrix. The projection matrix defines how to project the 3d coordinates to 2d coordinates to finally put things on our 2d screen.

OpenGL is nothing but a huge state-machine. So once you set a matrix / color / normal(missing in Unity) / texture coordinate / shader pass, it will be used from now on until it's changed again. In Unity it's similar but keep in $$anonymous$$d that Unity does it's own thing in between so you can't expect to have the same state the next frame.

It also depends on where you execute your drawing code. OnPostRender is called from a specific camera while OnRenderObject is called for every camera that renders the scene / object. This is useful when you want to see your stuff in the sceneview as well. $$anonymous$$eep in $$anonymous$$d to use Camera.current in that case and not Camera.main or something like that ;)

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.

Follow this Question

Answers Answers and Comments

25 People are following this question.

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

Related Questions

Drawing 3D Lines with GL? 2 Answers

Draw 2D polygon 1 Answer

Camera OnPostRenderer on iPhone/iPad sometimes paints all the GL.Lines Black. 1 Answer

GL.MultMatrix multiple instances drawing 0 Answers

Creating GL Lines 2 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