PDA

View Full Version : Screen isn't refreshing?



ByDreaM
09-08-2013, 08:18 PM
Hello. I try to make a rotatable triangle. But i have a problem

#include <GL/glut.h>
#include <stdlib.h>
GLfloat rquad=0.0;

GLfloat aci;
void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
void gluPerspective(GLdouble fov, GLdouble aspect, GLdouble near, GLdouble far);
void ayarlar(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_SMOOTH);
gluPerspective(0.0,0.0, 1.5, 20.0);
}
void gosterim(void)
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glMatrixMode (GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glRotatef(aci,45.0f,45.0f,0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.75f,0.5f,0.0f);
glVertex3f(0.25f,0.5f,0.0f);
glVertex3f(0.5f,1.0f,0.2f);

glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.75f,0.5f,-0.2f);
glVertex3f(0.25f,0.5f,-0.2f);
glVertex3f(0.5f,1.0f,-0.2f);
glEnd();
aci+=0.5f;
glFlush();
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
glutInitWindowPosition(0,0);
glutInitWindowSize(200,200);
glutCreateWindow("OpenGL");
ayarlar();
glutDisplayFunc(gosterim);
glutMainLoop();
return 0;
}


But triangles isn't rotating. If i maximize the windows, the screen refreshing by 1 frame. Hope understand. Sorry for bad English..

debonair
09-08-2013, 10:24 PM
did you try by adding glLoadIdentity (); after glMatrixMode (GL_MODELVIEW).?

ByDreaM
09-09-2013, 05:39 AM
Yes i tried. But same problem :/

menzel
09-09-2013, 05:56 AM
I believe you need a glutIdleFunc which gets called whenever GLUT has nothing to do, in this you want to trigger a redisplay to redraw the scene, that will call your display function.

ByDreaM
09-09-2013, 06:35 AM
Thanks for reply. But I don't know how to use it. Can you change my code?

menzel
09-09-2013, 06:38 AM
But I don't know how to use it. Can you change my code?

You find the documentation here: http://www.opengl.org/resources/libraries/glut/spec3/node63.html . If I would start fixing your code, I would also switch from the out-dated immediate mode to modern GL and I don't have the time for that ;-)

ByDreaM
09-09-2013, 07:28 AM
I made it. Thank you :D