PDA

View Full Version : why when I rotatate my surface, it flicking?



ym
07-18-2001, 12:28 PM
I used double buffer

07-18-2001, 12:39 PM
It should not flicker if you have good hardware. I do not know... perhaps if you give some more details.

07-18-2001, 09:59 PM
Look into Backface Culling. If your box is trying to render both the front and the back of the object at the same time, it may flicker. If you use backface culling, you will not render the back of the object. (speeds up your prog, too!)

harsman
07-18-2001, 10:55 PM
Maybe you put the camera transform in the projection matrix? This only applies if you're using lighting though.

ym
07-19-2001, 06:39 AM
Thank you so much for all of you, I got a lot of help sice I joined the forums two days ago.
I have tried the back face culling. It doesn't work. About the camera, this is my code:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1,10,100);
gluLookAt(0,0,20, 0,0,0, 0,1,0);
glMatrixMode(GL_MODELVIEW);

Is it right? yes, I use lighting.


[This message has been edited by ym (edited 07-19-2001).]

Eric
07-19-2001, 06:50 AM
I can see a major problem in your setup. gluLookAt is used to set up the viewpoint, which should actually be done with the ModelView matrix.

If you use lighting or fog and are setting up your viewpoint with the projection matrix, you're likely to run into problems. You would also have problems if you did set up your projection in the modelview matrix...

So, you should do the following:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1,10,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,20, 0,0,0, 0,1,0);

Now, if this does not solve the problem, feel free to post more of your code (or e-mail it to me if you wish).

Hope this will help.

Best regards.

Eric

ym
07-19-2001, 08:07 AM
thanks a lot, but it still doesn't work, it happens only when I rotate the surface to some angle. When it became very shinning . Here is the code:
void display(void)
{
int i, j;
GLfloat ambient2[]={1,0,0,1};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix ();
glRotatef(spin,0,1,0);

glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
0, 1, 12, 4, &ctrlpoints1[0][0][0]);
for (j = 0; j <=20; j++) {
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= 20; i++)
{
glMaterialfv(GL_FRONT,GL_AMBIENT,ambient2);
glEvalCoord2f((GLfloat)i/20.0, (GLfloat)j/20.0);
glEvalCoord2f((GLfloat)j/20.0, (GLfloat)i/20.0);

}

glEnd();
}

glPopMatrix ();
glutSwapBuffers();
spin+=1;
}
void init(void)
{


GLfloat mat_diffuse[]={1,1,1,1.0};
GLfloat mat_specular[]={1.0,1.0,1.0,1.0};
GLfloat mat_shininess[]={1.0};
GLfloat light_position1[]={1.0,5.0,1.0,0.0};


glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_diff use);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,mat_spec ular);
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,mat_sh ininess);

glClearColor (.0, .0, .0, 1.0);
glLightfv(GL_LIGHT0,GL_POSITION,light_position1);

glEnable(GL_LIGHT0);
glDepthFunc(GL_LEQUAL);
glEnable(GL_LIGHTING);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);

glEnable(GL_MAP2_VERTEX_3);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1,10,100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,20, 0,0,0, 0,1,0);
}