Пример #1
0
bool StGLImageSphereProgram::init(StGLContext& theCtx) {
    if(!StGLImageProgram::init(theCtx)) {
        return false;
    }

    const StGLResources aShaders("StGLWidgets");
    StGLVertexShader vShaderMain(StGLProgram::getTitle());
    vShaderMain.initFile(theCtx, aShaders.getShaderFile("sphereImage.shv"));
    StGLAutoRelease aTmp1(theCtx, vShaderMain);

    StGLFragmentShader fShaderMain(StGLProgram::getTitle());
    fShaderMain.initFile(theCtx, aShaders.getShaderFile("sphereImage.shf"));
    StGLAutoRelease aTmp2(theCtx, fShaderMain);

    fGetColorLinear.initFile(theCtx, aShaders.getShaderFile("sphereGetColorLinear.shf"));

    return StGLProgram::create(theCtx)
        .attachShader(theCtx, vShaderMain)
        .attachShader(theCtx, fShaderMain)
        .attachShader(theCtx, *fGetColorPtr)
        .attachShader(theCtx, *f2RGBPtr)
        .attachShader(theCtx, *fCorrectPtr)
        .attachShader(theCtx, *fGammaPtr)
        .link(theCtx);
}
Пример #2
0
bool StGLMenuProgram::init(StGLContext& theCtx) {
    const char VERTEX_SHADER[] =
       "uniform mat4 uProjMat;\n"
       "uniform vec4 uDisp;\n"
       "attribute vec4 vVertex;\n"
       "void main(void) {\n"
       "    gl_Position = uProjMat * (vVertex + uDisp);\n"
       "}\n";

    const char FRAGMENT_SHADER[] =
       "uniform vec4 uColor;\n"
       "void main(void) {\n"
       "    gl_FragColor = uColor;\n"
       "}\n";

    StGLVertexShader aVertexShader(StGLProgram::getTitle());
    aVertexShader.init(theCtx, VERTEX_SHADER);
    StGLAutoRelease aTmp1(theCtx, aVertexShader);

    StGLFragmentShader aFragmentShader(StGLProgram::getTitle());
    aFragmentShader.init(theCtx, FRAGMENT_SHADER);
    StGLAutoRelease aTmp2(theCtx, aFragmentShader);
    if(!StGLProgram::create(theCtx)
       .attachShader(theCtx, aVertexShader)
       .attachShader(theCtx, aFragmentShader)
       .bindAttribLocation(theCtx, "vVertex", getVVertexLoc())
       .link(theCtx)) {
        return false;
    }

    uniProjMatLoc = StGLProgram::getUniformLocation(theCtx, "uProjMat");
    uniDispLoc    = StGLProgram::getUniformLocation(theCtx, "uDisp");
    uniColorLoc   = StGLProgram::getUniformLocation(theCtx, "uColor");
    return uniProjMatLoc.isValid()
        && uniColorLoc.isValid();
}