tags:

views:

218

answers:

4

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?

A: 

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.

Jim Buck
Sorry sir, we usually use the word declare over here, i might have gotten it wrong. Thanks neways
codemax
Ohh, ok, I think you mean the word "call" then. :)
Jim Buck
aah, ya thats what i meant...................
codemax
A: 

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);
dig412
oh k thanks for the reply. got it
codemax
+1  A: 

How about you look at the example in my answer to your previous question. If that answer has helped you to move on to this question, could you at least accept it there?

catchmeifyoutry
sir, actually somebody suggested that i should start a new question that's y i did and ya it did work....i thot starting a new question would improve ma chances of being answered. i apologizejust gimme some time to get a hang of this surrounding.........sorry againi am a student actually am not used to much communities like this
codemax
void RenderScene(void){ glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(0, 1.0f, 0.0f, 0.0f); glRotatef(0, 0.0f, 1.0f, 0.0f); GLfloat x,y,z = -50,angle; glBegin(GL_POINTS); for(angle = 0; angle < 360; angle += 1) { x = 50 * cos(angle); y = 50 * sin(angle); glVertex3f(x,y,z); z+=1; } glEnd(); glPopMatrix(); glutSwapBuffers();}
codemax
Sorry forgot to indend it
codemax
sir, what does the 60.0f ingluPerspective(60.0f, aspectratio, 1, 400.0);signify?
codemax
it is the field-of-view in the vertical direction, thus it specifies with what angle your view frustum extends. See http://profs.sci.univr.it/~colombar/html_openGL_tutorial/en/03basic_transforms_018.html
catchmeifyoutry
K sir thank you again, but i still have doubt.i mean they say near and far, from which direction are we viewing?-ve or +ve?or did i get the whole concept wrong?
codemax
A: 

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.

Felix Kling
Yes sir, but what i din c newhere is that they say near and far but where am i actually viewing it from?-ve side or +ve side. we need to know that dont we?
codemax
Yes sir, so i am viewing from the -ve Z rt?so for example,, i am making a spiral, and my z i start from -50 and keeps on incrementing z by 1 till the whole circle is complete once so that i get a spiral... so how shud i use gluperspective?
codemax
That depends from which point you want to look at your spiral.
Felix Kling
sir no, i saw in superbible they use near and far as -1 and 1, so?it is negative isnt it? then y?
codemax