< I A M A B E G I N N E R >
I have problem Regarding to GL_DEPTH_TEST
In following code when i remove glEnable(GL_DEPTH_TEST) and glDisable(GL_DEPTH_TEST)
every thing ok but not appear real
but after applying these enable it shows unwanted result: a red cone with green base sphere is line
main.cpp
#include <stdlib.h>
#include <GL/glut.h>
int WinWidth = 640,WinHeight = 480;
void Cylinder(GLdouble base, GLdouble top, GLdouble height);
void Disk(GLdouble inner, GLdouble outer);
void pyram(GLfloat rad,GLfloat Height)
{// Pyramidical
glColor3f(1.0f,0.0f,0.0f);
Cylinder(0.0f, rad, Height);
glColor3f(0.0f,1.0f,0.0f);
glTranslatef(0.0f,0.0f,Height);
Disk(0.0f,rad);
}
GLfloat zr = 0.5f;
void RScene()
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glEnable(GL_CW);
glEnable(GL_DEPTH_TEST);
glRotatef(zr,1.0f,0.0f,0.0f);
glPushMatrix();
pyram(0.5,0.5);
glPopMatrix();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CW);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
zr+= 0.5f;
glutSwapBuffers();
glutPostRedisplay();
}
void WinSize(GLsizei w,GLsizei h)
{
GLfloat Ratio = (GLdouble)w/(GLdouble)h;
if(h==0)h=1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,Ratio,-1.0f,10.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,w,h);
}
void Idle(){glutPostRedisplay();}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(WinWidth,WinHeight);
glutCreateWindow(“Camera in a room”);
glutDisplayFunc(RScene);
glutReshapeFunc(WinSize);
glutMainLoop();
}
void Cylinder(GLdouble base, GLdouble top, GLdouble height)
{GLUquadric *Cy;
Cy = gluNewQuadric ();
gluQuadricDrawStyle ( Cy, GLU_FILL);
gluQuadricNormals ( Cy, GLU_SMOOTH);
gluQuadricOrientation ( Cy, GLU_INSIDE);
gluCylinder (Cy, base, top, height, 32,24);
}
void Disk(GLdouble inner, GLdouble outer)
{GLUquadric *Dsk;
Dsk = gluNewQuadric ();
gluQuadricDrawStyle ( Dsk, GLU_FILL);
gluQuadricNormals ( Dsk, GLU_SMOOTH);
gluQuadricOrientation ( Dsk, GLU_INSIDE);
gluDisk ( Dsk, inner, outer,32,24);
}
makefile:
LIB = -I/usr/lib
INC = -I/usr/include
SRC = main.cpp
COMP = gcc
LINK = -lglut -lGL
1st:
$(COMP) -o cam1 $(SRC) $(LIB) $(INC) $(LINK)
Q.1 is glTranslatef problem give problem?
Q2. is there any way that fun Cylinder and Disk combine and make
one object CyPyramid which really act as one object
< I A M A B E G I N N E R >