PDA

View Full Version : near values and far values



iris_raj
12-27-2005, 12:03 AM
Dear All,

I am drawing a pendulum. Initially I used glOrtho, I worked properly.
But when I changed to glPerspective, pendulum is not visible.
The code is given below

What values should I set for near and far plane.

#include<Gl/glut.h>
#include<GL/gl.h>
#include<stdio.h>

float ambient[] ={1.0,1.0,1.0,1.0};
float specular[]={1.0,1.0,1.0,1.0};
float diffuse[] ={1.0,1.0,1.0,1.0};
float position[]={0.5,0.5,3.5};
float reflect[] ={0.5,0.5,0.5,1.0};

float x=0.0,y=-0.6;

void render(void)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();

glColor3f(0.1, 0.1, 0.0);
glBegin(GL_QUADS);
glVertex3f(-0.1, 0.0, 0.0);
glVertex3f( 0.1, 0.0, 0.0);
glVertex3f( 0.1, 0.1, 0.0);
glVertex3f(-0.1, 0.1, 0.0);
glEnd();

glColor3f(0.8, 0.8, 0.8);

glBegin(GL_LINES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(x, y, 0.0);
glEnd();

glColor3f(0.2, 0.65, 0.9);
glPushMatrix();
glTranslated(x, y, 0.0);
glutSolidSphere(0.07, 30, 30);
glPopMatrix();
glPopMatrix();

glutSwapBuffers();
}

void Init(void)
{
glClearColor(0.0,0.0,0.0,1.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_CCW);

glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glEnable(GL_LIGHT0);

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
glMateriali(GL_FRONT,GL_SHININESS,200);
glClearColor(0.05,0.05,0.0,1.0);

}

void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w / (GLfloat) h, -1.0,200.0);
//glOrtho(-1.0,1.0,-1.0,1.0,1.0,-1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(1000,800);
glutInitWindowPosition(50,50);
glutCreateWindow(argv[0]);
glutDisplayFunc(render);
glutReshapeFunc(reshape);
Init();
glutMainLoop();
}

RigidBody
12-27-2005, 01:47 AM
i don't think a negative value for the near plane is allowed in gluPerspective.
change it to 1.0 and be sure that you're at least 1 unit away from the object.

UrbanLegend
12-27-2005, 07:06 AM
The Near clip plane must be positive and greater than > 0.0

And the Far clip plane must be positive and greater than the Near clip