官网：古典小说网 gudianxiaoshuo.com
官网：你真正需要下载的软件 需要下载站 needdown.com
网站大全
绿色导航

统一变量根据线段设置不同颜色

         char vShaderStr[] =
            "#version 300 es                          \n"
            "layout(location = 0) in vec4 vPosition;  \n"
            "out vec4 tranglePos;   \n"
            "void main()                              \n"
            "{                                        \n"
            "   gl_Position = vPosition;              \n"
            "   tranglePos=vPosition;  \n"
            "}                                        \n";

         char fShaderStr[] =
            "#version 300 es                              \n"
            "precision mediump float;                     \n"
            "uniform vec2 verPos;"
            "uniform float rColor;"
            "uniform float gColor;"
            "uniform float bColor;"
            "out vec4 fragColor;                          \n"
            "in  vec4 tranglePos;    \n"
            "void main()                                  \n"
            "{                                            \n"
            "if(tranglePos.y>(verPos.y+0.5)/verPos.x*tranglePos.x-0.5)"
            "    fragColor = vec4(rColor,gColor,bColor,1.0 ); \n"
            "else"
            "    fragColor = vec4(1,gColor,0,1.0 ); "
            "}                                            \n";

      void Draw ( ESContext *esContext )
      {
         UserData *userData = esContext->userData;
         GLfloat vVertices[] = {
                                  x,  y, 0.0f,
                                  -0.5f, 0.0f, 0.0f,

0.5f, 0.0f, 0.0f,

                                  x,  -y, 0.0f,
                                  -0.5f, 0.0f, 0.0f,

0.5f, 0.0f, 0.0f

                               };
         int nLocation=0;
          x=r*cos(angle);
          y=r*sin(angle);
         angle+=0.1f;
         if(bAdd)
              xAdd+=0.01f;
         else
             xAdd-=0.01f;
         if(x+xAdd>1)
           bAdd=FALSE; // xAdd=-1-x;

         if(x+xAdd<-1)
           bAdd=TRUE; // xAdd=-1-x;
         if(bRedAdd)
            rColor+=0.02f;
         else
            rColor-=0.01f;
         if(bGreenAdd)
           gColor+=0.01f;
         else
           gColor-=0.01f;
         if(bBlueAdd)
           bColor+=0.01f;
         else
           bColor-=0.01f;
         if(rColor>1.0f)
             bRedAdd=FALSE;
         if(rColor<0.0f)
              bRedAdd=TRUE;
          if(gColor>1.0f)
             bGreenAdd=FALSE;
          if(gColor<0.0f)
              bGreenAdd=TRUE;
          if(bColor>1.0f)
             bBlueAdd=FALSE;
          if(bColor<0.0f)
              bBlueAdd=TRUE;
        nLocation=glGetUniformLocation(userData->programObject,"rColor");
        glUniform1f(nLocation, rColor);
        nLocation=glGetUniformLocation(userData->programObject,"gColor");
        glUniform1f(nLocation, gColor);
         nLocation=glGetUniformLocation(userData->programObject,"bColor");
        glUniform1f(nLocation, bColor);
           nLocation=glGetUniformLocation(userData->programObject,"verPos");
        glUniform2f(nLocation, x,y);
         // Set the viewport
         glViewport ( 0, 0, esContext->width, esContext->height );
         // Clear the color buffer
         glClear ( GL_COLOR_BUFFER_BIT );
         // Use the program object
         glUseProgram ( userData->programObject );
         // Load the vertex data
         glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices );
         glEnableVertexAttribArray ( 0 );
         glDrawArrays ( GL_TRIANGLES, 0,3 );