I am trying to display a square in a window… something is messed up, the square is not centered… the dimensions need to be 128x128 for the square to be centered and not 256x256! can you tell me what I am doing wrong?
#include <GL/gl.h>
#include <GL/glut.h>
void InitGL();
void DrawScene();
const float Height(256), Width(256);
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(200,200);
glutInitWindowSize(int(Width)+20,int(Height)+20);
glutCreateWindow(“Square”);
InitGL();
glutDisplayFunc(DrawScene);
glutMainLoop();
return 0;
}
void InitGL()
{
glClearColor(0.2f, 0.1f, 0.5f, 1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glViewport(0,0,int(Width+20),int(Height+20));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,Width+10,-10,Height+10);
glMatrixMode(GL_MODELVIEW);
}
void DrawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(0.0,1.0f,0.0f);
glBegin(GL_QUADS);
glNormal3f(0.0f,0.0f,1.0f);
glVertex4f(0.0f,0.0f,0.0f,0.5f);
glVertex4f(Width,0.0f,0.0f,0.5f);
glVertex4f(Width,Height,0.0f,0.5f);
glVertex4f(0.0f,Height,0.0f,0.5f);
glEnd();
glutSwapBuffers();
glutPostRedisplay();
}