glTranslate ()
#include
"stdafx.h"
#include
<GL/glut.h>
void
init()
{
glClearColor (0.0,
0.0, 0.0, 0.0);
glShadeModel
(GL_FLAT);
}
void
display()
{
glTranslatef(10.0f,
10.0f, 0.0f);
glClear
(GL_COLOR_BUFFER_BIT);
glColor3f (1.0,
0.0, 0.0);
glBegin(GL_LINES);
glVertex2f(0.0f, 0.0f); // origin of the line
glVertex2f(580.0f, 0.0f); // ending point of the
line
glVertex2f(0.0f, 0.0f);
glVertex2f(0.0f,
580.0f);
glEnd( );
glFlush ();
//forces previously issued commands to
execute
}
void
reshape (int w,
int h)
{
glViewport (0, 0,
(GLsizei) w, (GLsizei) h);
glMatrixMode
(GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0,
(GLdouble) w, 0.0, (GLdouble) h);
}
int
main(int argc,
char** argv)
//Because of glut, parameters are
necessary
{
glutInit(&argc,
argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
// | means or
glutInitWindowSize
(600, 600);
//set window size in pixels
glutInitWindowPosition (100,100);
//set window position
glutCreateWindow
(argv[0]);
//create above window
init ();
//call init function
glutDisplayFunc(display);
//etc.
glutReshapeFunc(reshape);
glutMainLoop();
//must be last line of code - starts
things
return 0; } |