Drawing primitives:

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;

}

Is this example taken from somewhere else or written by ur self…??

first thing is the projection type is missing in init() function…

And also as far as my knowledge is concerned,

glutMainLoop() must take display as its input…

Hi thanks for the reply, the problem was something related to the co-ordinates that I used to draw the triangle. The below code worked fine.

#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.35f,-0.25f, 0.0f);    // lower left vertex
		glVertex3f( 0.35f,-0.25f, 0.0f);    // lower right vertex
		glVertex3f( 0.0f,  0.35f, 0.0f);	// Upper vertex.
	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;

}