/************************************************************
* File: simple.cc
* Author: C.Yap
* Date: Sep 7, 2001.
* Synopsis:
* First OpenGL program (see [Hill, p.40]).
* Illustrates the initialization for a display window
* in GLUT.
*
************************************************************/
#include <iostream.h> // needed for use of cout
#include <math.h> // needed for math functions exp(x), etc
#include <windows.h>
#include <gl/glut.h>
/////////////////////////////////////////////////////////////
// Constants
/////////////////////////////////////////////////////////////
const int screenWidth = 640;
const int screenHeight = 480;
/////////////////////////////////////////////////////////////
// Initialization
/////////////////////////////////////////////////////////////
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); // background is white
glColor3f(0.0f, 0.0f, 1.0f); // pen is blue
glPointSize(2.0); // dot is 2pixels wide
glMatrixMode(GL_PROJECTION); // set camera shape
glLoadIdentity(); // initialize projection matrix
gluOrtho2D(0.0, (GLdouble)screenWidth,
0.0, (GLdouble)screenHeight); // set matrix for 2D graphics
}//myInit()
/////////////////////////////////////////////////////////////
// callback functions
/////////////////////////////////////////////////////////////
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); // clear screen
glBegin(GL_POINTS);
for (GLdouble x = 0; x < screenWidth; x += 2) {
// PLOT FUNCTION: y = e(-x) * cos (8 * pi * x)
GLdouble y = exp(-x/screenWidth) * cos(3.14159265 * 8 * x/screenWidth);
y = y*(screenHeight/2) + (screenHeight/2) ;
glVertex2d(x, y) ;
}//for
glEnd();
glFlush();
}//myDisplay()
void main(int argc, char** argv)
{
/////////////////////////////////////////////////////////////
// initialization and create screen window
/////////////////////////////////////////////////////////////
glutInit(&argc, argv); // initialize toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // display mode (single buffer)
glutInitWindowSize(screenWidth, screenHeight); // window size
glutInitWindowPosition(100, 150); // position of top right corner
glutCreateWindow("My First Window"); // open it
/////////////////////////////////////////////////////////////
// register callback functions
/////////////////////////////////////////////////////////////
glutDisplayFunc(myDisplay); // redraw window event
// glutReshapeFunc(myReshape); // reshape window event
// glutMouseFunc(myMouse); // mouse button event
// glutKeyboardFunc(myKeyboard); // keyboard event
myInit(); // special initialization
glutMainLoop(); // mandatory final call to glut
}//main
/////////////////////////////////////////////////////////////
// The end
/////////////////////////////////////////////////////////////