codemax
codemax

Reputation: 457

How to declare gluPerspective in OpenGL?

How can I actually declare gluPerspective?

I mean I am drawing a spiral and I am setting z = -50 in the beginning and looping until the circle is complete. So what will be the declaration of gluPerspective?

Upvotes: 0

Views: 7376

Answers (3)

Felix Kling
Felix Kling

Reputation: 816404

I strongly recommend that you have a look at the official OpenGL red book chapter 3, Viewing. There you'll find a good introduction to perspective projection.


Edit after comment:

Well if you would read the chapter carefully you would read this:

You can manufacture a viewing transformation in any of several ways, as described next. You can also choose to use the default location and orientation of the viewpoint, which is at the origin, looking down the negative z-axis.

and

void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far);
Creates a matrix for a symmetric perspective-view frustum and multiplies the current matrix by it. fovy is the angle of the field of view in the x-z plane; its value must be in the range [0.0,180.0]. aspect is the aspect ratio of the frustum, its width divided by its height. near and far values the distances between the viewpoint and the clipping planes, along the negative z-axis. They should always be positive.

Upvotes: 0

dig412
dig412

Reputation: 551

I'm not really sure what you mean.gluPerspective() is typically used once when the program starts, then whenever the window is resized, to define the way primitives are projected to the screen.

You do that as so:

glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
    glLoadIdentity();                                   // Reset The Projection Matrix
    gluPerspective(60,screenWidth/screenHeight,0.1,1000);

Upvotes: 0

Jim Buck
Jim Buck

Reputation: 20726

Somewhere at the top of the source file you want to use gluPerspective in:

#include <GL/glu.h>

and then you can use gluPerspective with no problem.

Upvotes: 2

Related Questions