OpenGL中的渐变颜色绘图(应力可视化)

OpenGL中的渐变颜色绘图(应力可视化)_第1张图片
复制代码
1 #include
2 #include
3 #include
4 using namespace std;
5 const GLsizei width=640;
6 const GLsizei height=480;//设置窗口的宽和高
7
8 void myInit()
9 {
10 glClearColor(0,0,0,0);
11 }
12
13
14 void show()
15 {
16 GLsizei dw;
17 int n,i;
18 dw=2;
19 n=(width-1)/dw;
20 cout<<“n=”< 21 glClear(GL_COLOR_BUFFER_BIT);
22 GLsizei r,g,b;
23 for (i=0;i 24 {
25 //绘制应力云图的关键就是下面的这五种不同的颜色对应关系
26 //根据自己需要可以设置不同的等级,四种也是可以的
27 if (i>=0&&i<=n/5)
28 {
29 r=255;
30 g=i255/(n/5);
31 b=0;
32 }
33 else if (i>n/5&&i<=2
n/5)
34 {
35 r=255-(i-n/5)255/(n/5);
36 g=255;
37 b=0;
38 }
39 else if(i>2
n/5&&i<=3n/5)
40 {
41 r=0;
42 g=255;
43 b=(i-2
n/5)255/(n/5);
44 }
45 else if(i>3
n/5&&i<=4n/5)
46 {
47 r=0;
48 g=255-(i-3
n/5)255/(n/5);
49 b=255;
50 }
51 else
52 {
53 r=(i-4
n/5)255/(n/5);
54 g=0;
55 b=255;
56 }
57 glColor3f(r/255.0f,g/255.0f,b/255.0f);
58 glRectf(1.0
idw,0.0,1.0(i+1)*dw,height);
59 }
60 glFlush();
61 }
62 void reshape(int w,int h)
63 {
64 glViewport(0,0,(GLsizei)w,(GLsizei)h);
65 glMatrixMode(GL_PROJECTION);
66 glLoadIdentity();
67 glOrtho(0,w,0,h,-100,100);//设置视野的范围,(左,右,上,下,前,后)
68 glMatrixMode(GL_MODELVIEW);
69 glLoadIdentity();
70 }
71
72 int main(int argc,char *argv[])
73 {
74 glutInit(&argc, argv);
75 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
76 glutInitWindowPosition(100,100);
77 glutInitWindowSize(width,height);
78 glutCreateWindow(“应力云图绘制”);
79 myInit();
80 glutDisplayFunc(show);
81 glutReshapeFunc(reshape);
82 glutMainLoop();
83 return 0;
84 }
复制代码

转:https://www.cnblogs.com/icmzn/p/7567002.html
转:https://blog.csdn.net/walkandthink/article/details/50231859
转:https://blog.csdn.net/weixin_30540691/article/details/95876283

你可能感兴趣的:(opengl)