hi All

Started by
6 comments, last by kelvindavies11 17 years, 10 months ago
Im new to opengl programming and i am creating a simple room. The rooms will contain a chair desk and fan(the fan will move). I have created all of the above however when i combine into one scene it flashes on and off. I believe this is due to my fan, as it doesnt happen when the fan is not in the room. The code for my fan is split into three parts: fan base Fan head build fan Is there a way in which i can make the fan spin without having the room flashing??? The code for the fan is as followes: /****************************************************************** desktop fan*/ void deskTopFanBase(void) { glPushMatrix(); //Fan Base glScalef(2.0, 0.5, 2.0); buildBox(); //fan Arm 1 glScalef(0.25, 9.0, 0.25); glTranslatef(0.0, 0.4, 0.0); buildBox(); //Fan Arm 2 glScalef(5.0, 0.15,1.0); glTranslatef(0.3, 3.0, 0.0); buildBox(); //fan head & Joint glScalef(0.25, 1.0, 1.0); glTranslatef(-1.25, 0.0, 0.0); glutSolidSphere(1.0, 20.0, 20.0); glPopMatrix(); } void deskTopFanHead(void) { glPushMatrix(); glutSolidSphere(1.0, 20.0, 20.0); glScalef(2.0, 1.0, 0.1); glTranslatef(0.5, 0.0, 0.0); buildBox(); glTranslatef(-1, 0.0, 0.0); buildBox(); glScalef(0.33, 1.4, 1.0); glTranslatef(1.5, 0.75, 0.0); buildBox(); glTranslatef(0.0, -1.55, 0.0); buildBox(); glPopMatrix(); } /* this part puts all the aspect sof the fan together and makes the fan head spin*/ void buildFan(void) { glPushMatrix(); deskTopFanBase(); glRotatef(90.0, 0.0, 1.0, 0.0); glScalef(0.75, 0.75, 0.75); glTranslatef(0.0, 5.0, 3.2); glRotatef(spin, 0.0, 0.0, 1.0); deskTopFanHead(); glPopMatrix(); glutSwapBuffers(); spin = (spin+ 10)% 360; glutPostRedisplay(); } Thanks for taking the time to read this, i fully appreciate it. kind regards, kelvin
Advertisement
If the screen is flashing when you draw the fan maybe you are flipping the frame buffer before the complete seen has been drawn.

Something like:
begin frame
1.Draw room
2.Draw desk
3.Draw fan top
4.switch frame buffer <-- flip one
5.Draw fan middle
6.Draw fan bottom
7.Switch frame buffer <-- flip two
end frame
Exitus Acta Probat
thanks for your reply. What do you mean switch buffers, i dont think i have set any buffers. heres the code im using to create instaances of the objects:

void Create_desk_Chair_Computer_Fan(void)
{
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1.0, 1.0, 1.0);
gluLookAt(zoom*sin(float(angle)*0.0175),zoom , zoom*cos(float(angle)*0.0175), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

/*room
glPushMatrix();
glRotatef(90.0, 1.0, 0.0, 0.0);
glScalef(50.0, 100.0, 50.0);
buildBox();
glPopMatrix();*/


//chairs
glPushMatrix();
chair();
glTranslatef(4.0, 0.0, 0.0);
chair();
glPopMatrix();

glPushMatrix();
//table
glRotatef(90, 0.0, 1.0, 0.0);
glTranslatef(-4.0, 0.0, 5.0);
table();
glPopMatrix();

//fan
glPushMatrix();
glScalef(0.25, 0.25, 0.25);
glRotatef(90.0, 0.0, 1.0, 0.0);
glTranslatef(-12.0, 10.0, -2.0);
buildFan();
glPopMatrix();


//computer
glPushMatrix();
glScalef(0.5, 0.5, 0.5);
glRotatef(270.0, 0.0, 1.0, 0.0);
glTranslatef(6.0, 5.0, -4.0);
computer();

glPopMatrix();
glFlush();
}

thanks allot,
kind regards,
kelvin
If you are not currently, you might try using a double buffered opengl context and swapping the buffers at draw completion. What you are probably experiencing is that when your draw crosses a certain complexity level (or uses certain features) it doesn't get completed during the retrace as often as when it has less complexity. So you are seeing the standard single-buffered tearing problem. Also there are many situations where if the scene doesn't change, the tearing / flashing doesn't show up ... so the fan may be causing you to see the problem, rather than causing the problem itself.
i think you are right i need the double buffer, becuase by the time the motion of the fan is draw it is then removed striaght away.

Ive put the double buffer function in however how do i intialize or tell the program that i am using double buffer.

thanks,
kelvin
thanks for your help i just worked it out, thanks for all your help its most appreciated.

kind regards,
kelvin
It depends on what you are using to set up your window. Are you using Win32? SDL? Glut?
developing in c++ and using glut.

kelvin

This topic is closed to new replies.

Advertisement