The code is as follows:
#include
GLsizei winWidth=600, winHeight=500;//Initial display window size.
GLint xRaster=25, yRaster=150;//Initialize raster position.
GLubyte label [36]={' J ', 'a', 'n', 'F', 'e', 'b', 'M', 'a', 'r',
'A', 'p', 'r', 'M', 'A', 'y', 'J', 'u', 'n',
'J', 'u', 'l', 'A', 'u', 'g' and 'S', 'e', 'p',
'O', 'c', 't', 'N', 'O', 'v', 'D', 'e', 'c'};
GLint dataValue [12]={420, 342, 324, 310, 262, 185,
190, 196, 217, 240, 312, 438};
Void init (void)
{
GlClearColor (1.0, 1.0, 1.0, 1.0);//White display window.
GlMatrixMode (GL_PROJECTION);
GluOrtho2D (0.0, 600.0, 0.0, 500.0);
}
Void lineGraph (void)
{
GLint month, k;
GLint x=30;//Initialize x position for chart.
GlClear (GL_COLOR_BUFFER_BIT);//Clear the display window.
GlColor3f (0.0, 0.0, 1.0);//Set the line color to blue.
GlBegin (GL_LINE_STRIP);//the Plot the data as a polyline.
For (k=0; K & lt; 12. K++)
GlVertex2i (x + k * 50, dataValue [k]);
GlEnd ();
GlColor3f (1.0, 0.0, 0.0);//Set the marker color to red.
For (k=0; K & lt; 12. K++) {//the Plot data as asterisk polymarkers.
GlRasterPos2i (xRaster + 50 k * and dataValue [k] - 4);
GlutBitmapCharacter (GLUT_BITMAP_9_BY_15, '*');
}
GlColor3f (0.0, 0.0, 0.0);//Set the text color to black.
XRaster=20.//Display chart labels.
For (the month=0; The month & lt; 12. Month++) {
GlRasterPos2i (xRaster yRaster);
For (k=3 * month; K & lt; The month + 3 * 3; K++)
GlutBitmapCharacter (GLUT_BITMAP_HELVETICA_12, label [k]);
XRaster +=50;
}
GlFlush ();
}
Void winReshapeFcn (GLint newWidth, GLint newHeight)
{
GlMatrixMode (GL_PROJECTION);
GlLoadIdentity ();
GluOrtho2D (0.0, GLdouble (newWidth), 0.0, GLdouble (newHeight));
GlClear (GL_COLOR_BUFFER_BIT);
}
Void main (int arg c, char * * argv)
{
GlutInit (& amp; Arg c, argv);
GlutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
GlutInitWindowPosition (100, 100);
GlutInitWindowSize (winWidth winHeight);
GlutCreateWindow (" Line Chart Data Plot ");
init();
GlutDisplayFunc (lineGraph);
GlutReshapeFunc (winReshapeFcn);
GlutMainLoop ();
}
CodePudding user response:
http://blog.sina.com.cn/s/blog_64ecf78f0102xzvl.htmlCodePudding user response:
Well, VS v is not a book, she always capricious, dynamic,