一段OpenGL的简单代码
这是基于OpenGL的代码,把它放进draw中即可。渲染出来的效果还不错
1 #define PI 3.14159 2 #define N 100 3 void test::Draw() 4 { 5 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // 设置刷新背景色 6 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);// 刷新背景 7 glLoadIdentity(); 8 glEnable( GL_BLEND ); 9 glBlendFunc( GL_SRC_ALPHA, GL_ONE ); 10 glDisable( GL_DEPTH_TEST ); 11 glDisable( GL_TEXTURE_2D ); 12 13 #pragma region 圆圈轨迹 14 glPushMatrix(); 15 glColor4f(1.0f,1.0f,1.0f,1.0f); 16 float step,zstep; 17 step=1.0*PI/N; 18 zstep=1.0/N; 19 glBegin(GL_LINES); 20 float factor=2.0f; 21 float length=3.0f; 22 float HOT=2.0f; 23 float COLD=0.0f; 24 GLfloat z=0.0f; 25 while (factor>0) 26 { 27 setColor(length,HOT,COLD); 28 for (int i=0;i<(int)(2*N);i++) 29 { 30 GLfloat x=factor*cos(step*i); 31 GLfloat y=factor*sin(step*i); 32 //GLfloat z=zstep*i; 33 glVertex3f(x,y,z); 34 glVertex3f(x,y,z+length); 35 } 36 factor=factor-0.05f; 37 length=length-0.1f; 38 } 39 glEnd(); 40 glPopMatrix(); 41 #pragma endregion 42 } 43 44 void test::setColor(float t,float HOT,float COLD) 45 { 46 float r,g,b; 47 r=(t-COLD)/(HOT-COLD); 48 g=0.0; 49 b=1.0-r; 50 glColor3f(r,g,b); 51 }