//linda Cobb //winter 98/99 //http://www.timestocome.com //opengl plotting routine for data #include #include #include //open gl libraries for graphics void drawAxis(){ typedef GLfloat point2[2]; //define a point array long int k, j; //loop control point2 p = {0.0, 0.0}; //begin here glColor3f(0.0, 0.0, 1.0); for(k=-250; k<250; k++){ //vertical axis p[0] = 0.0; p[1] = k; glBegin(GL_POINTS); glVertex2fv(p); glEnd(); } glColor3f(0.0, 0.0, 1.0); //horizontal axis for(k=-250; k<250; k++){ p[0] = k; p[1] = 0.0; glBegin(GL_POINTS); glVertex2fv(p); glEnd(); } //tick marks for(k=-250; k<250; k+=10){ //horizontal tick marks for(j=-5; j<5; j++){ p[0] = k; p[1] = j; glBegin(GL_POINTS); glVertex2fv(p); glEnd(); } } for(k=-250; k<250; k+=10){ //vertical tick marks for(j=-5; j<5; j++){ p[0] = j; p[1] = k; glBegin(GL_POINTS); glVertex2fv(p); glEnd(); } } } //plot data in an opengl window previously stored in array void myDisplay(){ typedef GLfloat point2[2]; //define a point array long int k; //loop control point2 p = {0.0, 0.0}; //begin here extern displayData[2][51]; //hold data to plot w/ opengl routines glClear(GL_COLOR_BUFFER_BIT); //clear window drawAxis(); glColor3f(1.0, 0.0, 0.0); //plot color (red) for(k=0; k < 51; k++){ //plot data p[0] = displayData[0][k]*100; //x position (scale data so can see better...) p[1] = displayData[1][k]*100; //y position glBegin(GL_POINTS); //plot points glVertex2fv(p); glEnd(); } } //initialize opengl window for plotting void myinit(void){ glClearColor(1.0, 1.0, 1.0, 0.0); //backround color (r,g,b, alpha) glColor3f(1.0, 0.0, 0.0); //draw color (r, g, b) glMatrixMode(GL_PROJECTION); //projection stack gluOrtho2D(-250.0, 250.0, -250.0, 250.0); //2d coordinate system centered at (0,0) glMatrixMode(GL_MODELVIEW); //model view stack } plotData(int argc, char **argv){ glutInit(&argc, argv); glutInitWindowSize(500,500); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); (void)glutCreateWindow("plot data"); glutDisplayFunc(myDisplay); myinit(); glutMainLoop(); }