博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
openGL 折线
阅读量:4628 次
发布时间:2019-06-09

本文共 2074 字,大约阅读时间需要 6 分钟。

#include "stdafx.h"#include
/*Initial display-window size*/GLsizei winWidth = 600, winHeight = 500;/*Initialize raster position*/GLint xRaster = 25, yRaster = 150;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','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 windows. 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);//PLot data as a polyline. for (k = 0; k < 12; k++) glVertex2i(x + k * 50, dataValue[k]); glEnd(); glColor3f(1.0, 0.0, 0.0);//Ser marker color to red. for (k = 0; k < 12; k++) {
//Plot data as asterisk polymakers. glRasterPos2i(xRaster + k * 50, dataValue[k] - 4); glutBitmapCharacter(GLUT_BITMAP_9_BY_15, '*'); } glColor3f(0.0, 0.0, 0.0);//Ser test color to black. xRaster = 20;//Display chart labels. 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(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 argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(100, 100); glutInitWindowSize(winWidth, winHeight); glutCreateWindow("Line Chart Data Plot"); init(); glutDisplayFunc(lineGraph); glutReshapeFunc(winReshapeFcn); glutMainLoop();}

 

 

转载于:https://www.cnblogs.com/pqhuang/p/11268960.html

你可能感兴趣的文章
SQL数据库无法附加 系统表损坏修复 数据库中病毒解密恢复
查看>>
JMeter的安装和使用
查看>>
Es5正则
查看>>
Unicode,UTF-32,UTF-16,UTF-8到底是啥关系?
查看>>
Git 版本还原命令
查看>>
【C#技术】一篇文章搞掂:Infragistics组件库
查看>>
记一次生产的bug
查看>>
ubuntu14.04上搭建android开发环境
查看>>
搭建nexus后,进入首页的时候出现warning: Could not connect to Nexus.错误
查看>>
Multithread 之 introduction
查看>>
zabbix 监控tomcat实例
查看>>
WinForm 实现验证码
查看>>
[C++]C++中的IO类
查看>>
笔记本电脑(Windows7)实现无线AP
查看>>
JqGridView 1.0.0.0发布
查看>>
欲精一行,必先通十行
查看>>
前端相关html和css
查看>>
celery
查看>>
实现音乐播放器
查看>>
BZOJ1002 [FJOI2007]轮状病毒(最小生成树计数)
查看>>