# 1/31/05

Today we continued with the review of some of the concepts in linear algebra. We looked into the rotation and a handout (pages 4043 of Powerpoint notes for Chapter 2) was given out.

We also continued our discussion of the material at the end of Chapter (2).  In particular, we discussed the use of :

void glViewport(GLint x, GLint y, GLsizei w, GLsizei h)

Where (x,y) is the lower-left corner of the viewport, and w and h give the height and width, respectively.

Here is the triangle program with glViewPort

/* Program line.C. Draws a single line and also display the
end points of a line.  It is to show how the GL_LINES and
GL_POINTS work.  It also show how the single points or vectors
are used in the drawings of a line and the end points.
*/
#include <math.h>
#include <GL/glut.h>

typedef   GLfloat  point2[2];

void myinit(void)
{
/* attributes */
glClearColor(1.0, 1.0, 1.0, 1.0);

/* white background */
glColor3f(1.0, 0.0, 0.0);
/* draw in black */
/* set up viewing */
/* 50 x 50 window with origin lower left */

glMatrixMode(GL_PROJECTION);

gluOrtho2D(0.0, 120.0, 0.0, 120.0);
glMatrixMode(GL_MODELVIEW);

}

void display( void )
{
glViewport(0, 250, 250, 250);

glClear(GL_COLOR_BUFFER_BIT);
/*clear the window */
//  To get all sides of 100 for triangle
// we need the height to be D*cos(30)
double h = 86.60254;
point2 v1={10, 10}, v2={110,10};
point2 v3={60,h+10 };

glBegin(GL_LINES);
glVertex2fv(v1);
glVertex2fv(v2);
glEnd();

glBegin(GL_LINES);
glVertex2fv(v2);
glVertex2fv(v3);
glEnd();

glBegin(GL_LINES);
glVertex2fv(v3);
glVertex2fv(v1);
glEnd();

glFlush();
/* clear buffers */
}

void main(int argc, char** argv)
{
/* Standard GLUT initialization */
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
/* default, not needed */
glutInitWindowSize(500,500);
/* 500 x 500 pixel window */
glutInitWindowPosition(0,0);
/* place window top left on display */
glutCreateWindow("MyTest");
/* window title */
glutDisplayFunc(display);
/* display callback invoked when window opened */
myinit(); /* set attributes */
glutMainLoop(); /* enter event loop */
}

The output of this program is shown below.  Can you look at the above program and explain how this screen was generated.

I have a question for you.  Can we use the viewport to display 4 triangles in the 4 sections of the screen?