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


C++ GLShader::createShader方法代码示例

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


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

示例1: createShader

/**
* Create a shader, optimised for the specific splat rendering used
**/
GLShader* RendererHeightmap::createShader(RenderOpenGL* render, Heightmap* heightmap)
{
    CHECK_OPENGL_ERROR;

    GLShader* s = new GLShader(0);

    char* vertex_code = s->loadCodeFile("phong_static.glslv");

    GLuint vertex = s->createShader(GL_VERTEX_SHADER, vertex_code);
    free(vertex_code);
    if (vertex == 0) {
        GL_LOG("Invalid vertex shader");
        return NULL;
    }

    char* base_fragment_code = s->loadCodeFile("phong_splat.glslf");
    char* diffuse_code = RendererHeightmap::createShaderFunction_diffuseColor(heightmap);

    const char* strings[3];
    strings[0] = "#version 130\n";
    strings[1] = base_fragment_code;
    strings[2] = diffuse_code;

    GLuint fragment = s->createShader(GL_FRAGMENT_SHADER, 3, strings);
    free(base_fragment_code);
    free(diffuse_code);
    if (fragment == 0) {
        glDeleteShader(vertex);
        GL_LOG("Invalid fragment shader");
        return NULL;
    }

    bool result = s->createProgFromShaders(vertex, fragment);

    glDeleteShader(vertex);
    glDeleteShader(fragment);

    if (!result) {
        return NULL;
    }

    glUseProgram(s->p());
    glUniform1i(s->uniform("uTex"), 0);
    glUniform1i(s->uniform("uShadowMap"), 1);
    glUniform1i(s->uniform("uNormal"), 2);
    glUniform1i(s->uniform("uLightmap"), 3);
    glUniform1i(s->uniform("uDayNight"), 4);
    glUniform1i(s->uniform("uAlphaMap"), 0);
    glUniform1i(s->uniform("uLayers[0]"), 5);
    glUniform1i(s->uniform("uLayers[1]"), 6);
    glUniform1i(s->uniform("uLayers[2]"), 7);
    glUniform1i(s->uniform("uLayers[3]"), 8);
    glUniform1i(s->uniform("uLightmap"), 9);
    glUniform1i(s->uniform("uDetail[0]"), 10);
    glUniform1i(s->uniform("uDetail[1]"), 11);
    glUniform1i(s->uniform("uDetail[2]"), 12);
    glUniform1i(s->uniform("uDetail[3]"), 13);

    CHECK_OPENGL_ERROR;

    return s;
}
开发者ID:TheJosh,项目名称:chaotic-rage,代码行数:65,代码来源:renderer_heightmap.cpp


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