/* October 2002 * Brian J.Ross * Brock University, Dept of Computer Science * COSC 3P98 Midterm solution B * * A simple 2D function plotter. */ #if !defined(Linux) #include //Not Linux must be windows #endif #include #include #include #include #define MINDIM 0 #define MAXDIM 500 struct glob { float xmin; float xmax; float xincr; }; struct glob global = {-5.0, 5.0, 0.5}; float func(float x) { return sin(x); } void initdraw(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 0.0); // red glBegin(GL_LINES); glVertex2f(0.0, -5.0); glVertex2f(0.0, 5.0); glVertex2f(-5.0, 0.0); glVertex2f(5.0, 0.0); glEnd(); } void plot2d(void) { float x; initdraw(); glColor3f(0.0, 0.0, 0.0); glBegin(GL_LINE_STRIP); for (x=global.xmin; x <= global.xmax; x+=global.xincr) { glVertex2f(x, func(x)); }; glEnd(); glFlush(); } int main(argc, argv) int argc; char **argv; { glutInit(&argc, argv); glutInitWindowSize(MAXDIM, MAXDIM); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutCreateWindow("window"); glutDisplayFunc(plot2d); glMatrixMode(GL_PROJECTION); gluOrtho2D(global.xmin, global.xmax, global.xmin, global.xmax); glClearColor (1.0, 1.0, 1.0, 1.0); glutMainLoop(); return 0; }