当前位置: 首页>>代码示例>>C++>>正文


C++ GLSLProgram::SetFragShaderSource方法代码示例

本文整理汇总了C++中GLSLProgram::SetFragShaderSource方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLProgram::SetFragShaderSource方法的具体用法?C++ GLSLProgram::SetFragShaderSource怎么用?C++ GLSLProgram::SetFragShaderSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GLSLProgram的用法示例。


在下文中一共展示了GLSLProgram::SetFragShaderSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: defined

//------------------------------------------------------------------------------
static bool
linkDefaultPrograms() {

#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
    #define GLSL_VERSION_DEFINE "#version 400\n"
#else
    #define GLSL_VERSION_DEFINE "#version 150\n"
#endif
    {   // setup samples program
        //
        // this shader takes position, uTangent and vTangent for each point
        // then generates 3 lines in the geometry shader.
        //
        static const char *vsSrc =
            GLSL_VERSION_DEFINE
            "in vec3 position;\n"
            "in vec3 uTangent;\n"
            "in vec3 vTangent;\n"
            "out vec3 p;\n"
            "out vec3 ut;\n"
            "out vec3 vt;\n"
            "uniform mat4 ModelViewMatrix;\n"
            "void main() {\n"
            "  p =  (ModelViewMatrix * vec4(position, 1)).xyz;\n"
            "  ut = (ModelViewMatrix * vec4(uTangent, 0)).xyz;\n"
            "  vt = (ModelViewMatrix * vec4(vTangent, 0)).xyz;\n"
            "}\n";

        static const char *gsSrc =
            GLSL_VERSION_DEFINE
            "layout(points) in;\n"
            "layout(line_strip, max_vertices = 6) out;\n"
            "in vec3 p[];\n"
            "in vec3 ut[];\n"
            "in vec3 vt[];\n"
            "out vec4 c;\n"
            "uniform mat4 ProjectionMatrix;\n"
            "uniform float scale;\n"
            "void main() {\n"
            "  vec3 pos = p[0]; \n"
            "  c = vec4(1, 0, 0, 1);\n"
            "  gl_Position = ProjectionMatrix * vec4(pos, 1);\n"
            "  EmitVertex();\n"
            "  \n"
            "  pos = p[0] + ut[0] * scale; \n"
            "  gl_Position = ProjectionMatrix * vec4(pos, 1);\n"
            "  EmitVertex();\n"
            "  EndPrimitive();\n"
            "  \n"
            "   pos = p[0]; \n"
            "  c = vec4(0, 1, 0, 1);\n"
            "  gl_Position = ProjectionMatrix * vec4(pos, 1);\n"
            "  EmitVertex();\n"
            "  \n"
            "  pos = p[0] + vt[0] * scale; \n"
            "  gl_Position = ProjectionMatrix * vec4(pos, 1);\n"
            "  EmitVertex();\n"
            "  EndPrimitive();\n"
            "  \n"
            "  pos = p[0]; \n"
            "  c = vec4(0, 0, 1, 1);\n"
            "  gl_Position = ProjectionMatrix * vec4(pos, 1);\n"
            "  EmitVertex();\n"
            "  \n"
            "  pos = p[0] + cross(ut[0], vt[0]) * scale; \n"
            "  gl_Position = ProjectionMatrix * vec4(pos, 1);\n"
            "  EmitVertex();\n"
            "  EndPrimitive();\n"
            "  \n"
            "}\n";

        static const char *fsSrc =
            GLSL_VERSION_DEFINE
            "in vec4 c;\n"
            "out vec4 color;\n"
            "void main() {\n"
            "   color = c;\n"
            "}\n";

        g_samplesProgram.SetVertexShaderSource(vsSrc);
        g_samplesProgram.SetGeometryShaderSource(gsSrc);
        g_samplesProgram.SetFragShaderSource(fsSrc);

        g_samplesProgram.AddAttribute( "position",3 );
        g_samplesProgram.AddAttribute( "uTangent",3 );
        g_samplesProgram.AddAttribute( "vTangent",3 );
    }

    return true;
}
开发者ID:AiYong,项目名称:OpenSubdiv,代码行数:91,代码来源:glStencilViewer.cpp

示例2: defined

//------------------------------------------------------------------------------
static bool
linkDefaultPrograms() {

#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
    #define GLSL_VERSION_DEFINE "#version 400\n"
#else
    #define GLSL_VERSION_DEFINE "#version 150\n"
#endif

    {   // setup control cage program
        static const char *vsSrc =
            GLSL_VERSION_DEFINE
            "in vec3 position;\n"
            "in vec3 color;\n"
            "out vec4 fragColor;\n"
            "uniform mat4 ModelViewProjectionMatrix;\n"
            "void main() {\n"
            "  fragColor = vec4(color, 1);\n"
            "  gl_Position = ModelViewProjectionMatrix * "
            "                  vec4(position, 1);\n"
            "}\n";

        static const char *fsSrc =
            GLSL_VERSION_DEFINE
            "in vec4 fragColor;\n"
            "out vec4 color;\n"
            "void main() {\n"
            "  color = fragColor;\n"
            "}\n";

        g_cageProgram.SetVertexShaderSource(vsSrc);
        g_cageProgram.SetFragShaderSource(fsSrc);

        g_cageProgram.AddAttribute( "position",3 );
        g_cageProgram.AddAttribute( "color",3 );
    }

    {   // setup samples program
        static const char *vsSrc =
            GLSL_VERSION_DEFINE
            "in vec3 position;\n"
            "uniform mat4 ModelViewProjectionMatrix;\n"
            "void main() {\n"
            "  gl_Position = ModelViewProjectionMatrix * "
            "                  vec4(position, 1);\n"
            "}\n";

        static const char *fsSrc =
            GLSL_VERSION_DEFINE
            "out vec4 color;\n"
            "const vec4 colors[3] = vec4[3]( vec4(1.0,0.0,0.0,1.0),    \n"
            "                                vec4(0.0,1.0,0.0,1.0),    \n"
            "                                vec4(0.0,0.0,1.0,1.0)  ); \n"
            "void main() {\n"
            "   color = colors[gl_PrimitiveID % 3];\n"
            "}\n";

        g_samplesProgram.SetVertexShaderSource(vsSrc);
        g_samplesProgram.SetFragShaderSource(fsSrc);

        g_samplesProgram.AddAttribute( "position",3 );
    }

    return true;
}
开发者ID:GameFusion,项目名称:OpenSubdiv,代码行数:66,代码来源:glStencilViewer.cpp


注:本文中的GLSLProgram::SetFragShaderSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。