@kognifai/cogsengine
    Preparing search index...

    Loading effects {#effects}

    For this example we are using GLSL shaders and loading them to a "OpenGL20" device. When using GLSL shaders it is necessary to use attribute names from the set of recognized attributes described in Attributes.

    Vertex shader:

    
    uniform mat4 projectionMatrix;
    
    attribute vec3 aPosition;
    attribute vec4 aColor;
    
    varying vVec4 vColor;
    
    void main()
    {
        vColor = aColor;
        
        gl_Position = projectionMatrix * aPosition;
    }
    

    Pixel shader:

    
    varying vVec4 vColor;
    
    void main()
    {
        gl_FragData[0] = vColor;
    }
    

    To load an effect we need at least a vertex shader and in most cases a pixel shaders. These can be provided to the effects interface as string buffers.

    #include 
    
    {
        ...
        
        std::string vertexShader = // Vertex shader contents.
        std::string pixelShader = // Pixel shader contents.
        
        // Get a pointer to the effects interface.
        auto effects = device->getEffects();
        
        // Load our shaders and compile them into an effect.
        auto effectHandle = effects->loadEffectSource(vertexShader, pixelShader);
        
        if (HandleIsValid(effectHandle)) {
            // Success!
        }
        
        ...
    }
    

    To use our effect we also need to create an input layout to map vertex buffer data to a format suitable for consumption by our shader. See Pipeline Setup for more information.