PDA

View Full Version : Not showing result



strongnas
05-19-2015, 11:34 PM
hi, i have this code....

#include<gl\glut.h>
void init()
{
glClearColor(0.0,0.0,0.0,1.0);
glViewport(0,0,500,500);
gluOrtho2D(-5.0,495.0,-5.0,495.0);
glMatrixMode(GL_MODELVIEW);
}
int hapa=0;
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(20.0*hapa,0,0);
glRectf(-5,-5,5,5);
glFlush();
}
void update(int);
int main(int a,char** b)
{
glutInit(&a,b);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutCreateWindow("Dritare");
init();
glutDisplayFunc(Display);
glutMainLoop();
}
void update(int value)
{
hapa++;
glutPostRedisplay();
glutTimerFunc(1000,update,0);
}

and it just shows me a white window when i try to compile....
ps. when i remove update function does not shows nothing too but if i replace translatef(...) with rotate function it works :/
thank you in advance

GClements
05-20-2015, 07:07 AM
Your init() function needs to call glMatrixMode(GL_PROJECTION) before calling gluOrtho2D(). Otherwise, it will be part of the model-view matrix, and will be cleared by the glLoadIdentity() call.