Cramster.com - Homework Solutions, Lecture Notes, Exams, and Free Online Homework Help
Sign Up Now! Login Customer Support Cramster Blog
McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams
Problem Solved.
    Home    
    Homework Help    
   Answer Board   
    Resources (Beta)    
   
Member's Topic Headline:

Graphics !

Know the answer? Have a better solution? Share it.
Get Help Now.
View homework problems
explained for free!
Member Testimonials

Question:

Advertisement:

Answer | Ask New Question | Customize Profile | Leaderboards | 
FAQ

Member's Avatar

Rookie
Karma Points: 0
Respect (79%):
Date Posted: 5/14/2008 11:06:22 AM  Status: Live
Graphics !
Course Textbook Chapter Problem
N/A N/A N/A N/A
Question Details:
 Describe the strategy, How to implement 2D projection for drawing control over 3D rendering?
(answer must be in  10-15 lines)

Answers:

Cramster Expert

Member's Avatar

(Cramster SME)
Cramster In-House Subject Matter Expert
Date Posted: 5/23/2008 3:25:23 AM  Status: Live
Asker's Rating: Helpful   
Response:

Dear,

The basic strategy is to set up a 2D projection for drawing controls:

1) You can do this either on top of your 3D rendering or in overlay planes.

2) Draw into the overlay planes.

1) If you do on top of a 3D rendering, you'll need to redraw the controls at the end of every frame (immediately before swapping buffers).

2) If you draw into the overlay planes, you only need to redraw the controls if you're updating them. To set up a 2D projection, you need to change the Projection matrix.

heera's Comment:
thank u so much !


Member's Avatar

Expert
Karma Points: 899
Date Posted: 5/23/2008 3:28:05 AM  Status: Live
Asker's Rating: Lifesaver   
Response:

The basic strategy is to set up a 2D projection for drawing controls. You can do this either on top of your 3D rendering or in overlay planes. If you do so on top of a 3D rendering, you'll need to redraw the controls at the end of every frame (immediately before swapping buffers). If you draw into the overlay planes, you only need to redraw the controls if you're updating them.

To set up a 2D projection, you need to change the Projection matrix. Normally, it's convenient to set up the projection so one world coordinate unit is equal to one screen pixel, as follows:

glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, windowWidth, 0, windowHeight);

gluOrtho2D() sets up a Z range of -1 to 1, so you need to use one of the glVertex2*() functions to ensure your geometry isn't clipped by the zNear or zFar clipping planes.

Normally, the ModelView matrix is set to the identity when drawing 2D controls, though you may find it convenient to do otherwise (for example, you can draw repeated controls with interleaved translation matrices).

If exact pixelization is required, you might want to put a small translation in the ModelView matrix, as shown below:

glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glTranslatef (0.375, 0.375, 0.);

If you're drawing on top of a 3D-depth buffered image, you'll need to somehow disable depth testing while drawing your 2D geometry. You can do this by calling glDisable(GL_DEPTH_TEST) or glDepthFunc (GL_ALWAYS). Depending on your application, you might also simply clear the depth buffer before starting the 2D rendering. Finally, drawing all 2D geometry with a minimum Z coordinate is also a solution.

After the 2D projection is established as above, you can render normal OpenGL primitives to the screen, specifying their coordinates with XY pixel addresses (using OpenGL-centric screen coordinates, with (0,0) in the lower left).

heera's Comment:
thank u so much !

If you post one question/problem, I will provide 1 input/answer. If you put "x" questions/problems, I will provide"x" inputs/answers.  In both cases, appropriate ratings are appreciated for every input. Thanks.



By reading or posting messages on these forums, you are agreeing to the Answer Board's Terms of Service and Conduct (TSC).


About Cramster | Terms of Use | Privacy Policy | Contact Us | Press Room | Site Map | Support | Anti-Cheating Policy

Cramster.com is not affiliated with any publisher. Book covers, title and author names appear for reference only.
Copyright © 2008 Cramster, Inc.