数据点折线和多点标记绘制

来源:互联网 发布:滨州行知中学是私立吗 编辑:程序博客网 时间:2024/05/17 22:14
#include<GL/glut.h>
GLsizei winWidth=600,winHeight=500;//Initial display window size.
GLint xRaster=25,yRaster=150;//Initialize raster position
GLint 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',   'S','e','n',
                 '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 display window.
    glColor3f(0.0,0.0,1.0);//Set line color to blue.
    glBegin(GL_LINE_STRIP);
       for(k=0;k
<12;k++)
           glVertex2i(x+k*50,dataValue[k]);
    glEnd();
    
    glColor3f(1.0,0.0,0.0);//Set marker color to red.
    for(k
=0;k<12;k++){
        
glRasterPos2i(xRaster+k*50,dataValue[k]-4);
        glutBitmapCharacter(GLUT_BITMAP_9_BY_15,'*');
    }
    glColor3f(0.0,0.0,0.0);//Set text color to black.
    xRaster
=20;
    
for(month=0;month<12;month++){
          
glRasterPos2i(xRaster,yRaster);
          for(k
=3*month;k<3*month+3;k++)
              
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,label[k]);
          xRaster+
=50;
          
}
    glFlush();
}
void winReshapeFcn(int newWidth,int newHeight)
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0,(GLdouble)newWidth,0.0,(GLdouble)newHeight);
    glClear(GL_COLOR_BUFFER_BIT);
}

void main(int argc,char** argv)//注意是char**
{
    glutInit(&argc,argv);//注意是char**
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(winWidth,winHeight);
    glutCreateWindow("Line Chart Data Plot");

    init();//访问类的公有成员,这就像访问普通函数一样,当然了,这里只有一个类
    glutDisplayFunc(lineGraph);
    glutReshapeFunc(winReshapeFcn);

    glutMainLoop();
}
<!--
http://f2.9612.org//vcpp/webinfo/WebInfoBata1.asp

QQ群:
34409541 讨论网页  
34409326 讨论JAVA 已满 
34408784 讨论VC++  
34409699 讨论VC++  
9143041 讨论MFC编程  
10614204 讨论C#  
10613030 讨论Win32编程  
10613067 讨论游戏开发  
18779860 讨论JAVA  
*/
--
>
 
原创粉丝点击