PDA

View Full Version : confused about redenring cylinder



beet6
01-23-2002, 08:21 PM
#include <windows.h>
#include <GL/glut.h>


static int R1=0,R2=45.0,R3=0,R4=0,R5=0,R6=0;
GLfloat nearView=-10.0;

void inti(void)
{
glClearColor(0.,0.,0.,0.);
glShadeModel(GL_SMOOTH);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
GLUquadric* pQu;
pQu=gluNewQuadric();
gluQuadricDrawStyle(pQu,GLU_FILL);
gluQuadricNormals(pQu,GLU_SMOOTH);

glTranslatef(0.0,0.0,-10.0);
gluCylinder(pQu,0.5,0.5,1.0,2,1);
glFlush();
}

void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w,(GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0,(GLfloat)w/(GLfloat)h,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,-10.0);
}


int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GL_DEPTH) ;
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
inti();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}


Why cannot I render the cylinder? any help is most appreciated!

beet

Bob
01-24-2002, 12:17 AM
In the display function, you translate the cylinder, but you don't reset the transformations before next call. Example, you call the init function, and move the cylinder 10 units. The display function is called, and you move another 10 units. It's now 20 units away. Next time the display function is called, you move it 10 units again, and it's located 30 units away. Next time, it will be 40 units away, and next, 50 units away.

Try put a glLoadIdentity before the translation in the display function.

[This message has been edited by Bob (edited 01-24-2002).]

beet6
01-24-2002, 08:22 AM
2 Qes:

fisrt I reset the model transformation in Redisplay()function;

second; even like that, when I first run the program, I should get the correct scene with -20 units translation in z direction.

thanks for your reply