Hi,
I am new to opengl programming. I have started learning it with the help of red book. Please find below the code which i used to draw a triangle. The problem is that one side of the triangle is always touching the sides of the window which is drawn, irrespective of whatever co-ordinates that I provide.
What should I do to make it appear at the centre of the window?
#include <GL/glut.h>
#include <GL/gl.h>
void display (void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(-10.0f,-10.0f, 0.0f);
glVertex3f(10.0f, -10.0f, 10.0f);
glEnd();
glFlush();
}
void init (void)
{
/* select clearing (background) color */
glClearColor (0.0, 0.0, 0.0, 0.0);
/* initialize viewing values */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/*Main*/
int main (int argc,char** argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(500,500);
/*Set the posotion of window*/
glutInitWindowPosition(0,0);
glutCreateWindow("My Vindow");
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}