#include <GL/gl.h>
#include <GL/glut.h>

#define WINWID 512
#define WINHT 512

int wid;
int ht;


/* Called when window needs to be redrawn */
void redraw()
{
    glClear(GL_COLOR_BUFFER_BIT); /* clear screen to black */
    /* just draw a boring red triangle */
    glBegin(GL_TRIANGLES);
    glColor3f(1.f, 0.f, 0.f);
    glVertex2i(wid/4, ht/4);
    glVertex2i(wid*3/4, ht/4);
    glVertex2i(wid/2, ht*3/4);
    glEnd();
    glFlush();
}


/*
** Fix things if the window is resized.
*/
void resize(int width, int height)
{
    glMatrixMode(GL_PROJECTION); /* make sure it's the projection matrix */
    glLoadIdentity(); /* reset to identity */
    gluOrtho2D(0, width, 0, height); /* multiply with current matrix */
    glViewport(0, 0, width, height);
    wid = width;
    ht = height;
}



/* Parse arguments, and set up interface between OpenGL and window system */
main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitWindowSize(WINWID, WINHT);
    glutInitDisplayMode(GLUT_RGBA);
    (void)glutCreateWindow("transform to screen coordinates");
    glutDisplayFunc(redraw); /* if window is uncovered */
    glutReshapeFunc(resize); /* if window changes shape or size */
    wid = WINWID;
    ht = WINHT;
    glutMainLoop();
}
