Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2070
Number of posts: 5361

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Desperately need help - OpenGl Posted by foxtog on 12 Nov 2008 at 4:58 AM
Hello!
i'm a very-very beginning OpenGl programmer.
And for making up first serious ( even somehow) programmes, i'd like to understand the basics.

I competely do NOT understand how function GluPerspective works. I mean, i know its usage in theory but i still can't use it the way it works as i need to.

For instance, i have a cobe centered in (0,0,0), its heigth is 0.6. (so it crosses all the axes in points 0.3,-0.3).

How should I call GluPerspective to see the edges of the cube ( some of them in fron of the viewer)???

And i do NOT understand the location of the viewer, i mean, the place i stand to see the scene ???

Can anybody explane me , please?

it's really urgent

HUGE thanks
Report
Re: Desperately need help - OpenGl Posted by gautam on 15 Nov 2008 at 12:25 PM
Hi,

Its very simple. There are two types of projecttion - Perspective Projection and othograpics projection.

Perspective Projection gives you a view like in the real world - further you go smaller it will look while Orthographics projection keeps the size in tact. However far in the world it goes - the size is the same.

Now to do perspective projection you need to use gluPerspective in Opengl.

Consider this diagram of the two types of viewing frustum. The cuboid/rectangular type is the Orthographics projection frustum while the other one is the perspective viewing frsutum.

http://www.microsoft.com/msj/archive/opengl8.gif

Now lets get to the specific of gluPerspective -
gluPerspective( GLdouble fovy,
GLdouble aspect,
GLdouble zNear,
GLdouble zFar )

fovy is field of view for the y direction. This is the amount that you would want to see. So it goes like this in terms of a diagram


.
. |
. |
. |y direction
eye. ) angle |
. |
. |
. |

The aspect ratio determines the angle or how much is visible to eye on the x direction. However in an application it needs to use something to determine thus so it uses the width/height as the factor to calculate this. Thus your aspect ratio becomes the application width divided by the application height.

| |
| |
near clipping | | far clipping plane
plane | |
zNear | | zFar
| |

zFar - Think of this as the horizon after which you cannot see anything. Anything outside of this value will be clipped meaning not rendered.

zNear - This is the nearest point to the view/eye before which nothing will be visible.

So what you would do is do the following in opengl for gluPerspective for what you want

gluPerspective(45.0f, width/height, 0.1f, 100.0f);

And also set yourself at (should be done after you call glClear(..) and before rendering anything.)
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);

Basically saying set the eye point at 0, 0, 5 pixels behind origin with center being 0, 0, 0 and Up vector being 0, 1, 0.

Hope this helps

: Hello!
: i'm a very-very beginning OpenGl programmer.
: And for making up first serious ( even somehow) programmes, i'd like
: to understand the basics.
:
: I competely do NOT understand how function GluPerspective
: works. I mean, i know its usage in theory but i still can't use it
: the way it works as i need to.
:
: For instance, i have a cobe centered in (0,0,0), its heigth is 0.6.
: (so it crosses all the axes in points 0.3,-0.3).
:
: How should I call GluPerspective to see the edges of the cube
: ( some of them in fron of the viewer)???
:
: And i do NOT understand the location of the viewer, i mean, the
: place i stand to see the scene ???
:
: Can anybody explane me , please?
:
: it's really urgent
:
: HUGE thanks
:



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.