I am trying to write a simple application with xcode that displaces a quad.For this I am using glTranslatef.The evidenced part of the code is where I try to translate the points.
#import <OpenGL/OpenGL.h>
#import <GLUT/GLUT.h>
int width=500, height=500;
void init()
{
glViewport(0, 0, width, height);
glLoadIdentity();
glOrtho(0, width, height, 0, 0, 1);
}
void display()
{
glClearColor(0.9, 0.9, 0.9, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glMatrixMode(GL_MODELVIEW); /************************/
glLoadIdentity();[/b] /**************/
glTranslatef(100,0,0); /****** trying to translate the vertexes */
glBegin(GL_QUADS);
glVertex2i(100, 100);
glVertex2i(300, 100);
glVertex2i(300, 300);
glVertex2i(100, 300);
glEnd();
glFlush();
}
int main(int argc, char * argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(100, 100);
glutInitWindowSize(width, height);
glutCreateWindow("Test");
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
The quad should be displaced of 100 units in the widnow.Since in the glOrtho I specify the size of the view, I think that the quad shall be displayed inside the window.But instead I don’t see anything: there isn’t a quad in the window.So maybe I’m not using properly glTranslatef, but I can’t find the error.