zoukankan      html  css  js  c++  java
  • CompileGLShader

    //-----------------------------------------------------------------------------
    // Purpose: Compiles a GL shader program and returns the handle. Returns 0 if
    //            the shader couldn't be compiled for some reason.
    //-----------------------------------------------------------------------------
    GLuint CMainApplication::CompileGLShader( const char *pchShaderName, const char *pchVertexShader, const char *pchFragmentShader )
    {
        GLuint unProgramID = glCreateProgram();

        GLuint nSceneVertexShader = glCreateShader(GL_VERTEX_SHADER);
        glShaderSource( nSceneVertexShader, 1, &pchVertexShader, NULL);
        glCompileShader( nSceneVertexShader );

        GLint vShaderCompiled = GL_FALSE;
        glGetShaderiv( nSceneVertexShader, GL_COMPILE_STATUS, &vShaderCompiled);
        if ( vShaderCompiled != GL_TRUE)
        {
            dprintf("%s - Unable to compile vertex shader %d! ", pchShaderName, nSceneVertexShader);
            glDeleteProgram( unProgramID );
            glDeleteShader( nSceneVertexShader );
            return 0;
        }
        glAttachShader( unProgramID, nSceneVertexShader);
        glDeleteShader( nSceneVertexShader ); // the program hangs onto this once it's attached

        GLuint  nSceneFragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
        glShaderSource( nSceneFragmentShader, 1, &pchFragmentShader, NULL);
        glCompileShader( nSceneFragmentShader );

        GLint fShaderCompiled = GL_FALSE;
        glGetShaderiv( nSceneFragmentShader, GL_COMPILE_STATUS, &fShaderCompiled);
        if (fShaderCompiled != GL_TRUE)
        {
            dprintf("%s - Unable to compile fragment shader %d! ", pchShaderName, nSceneFragmentShader );
            glDeleteProgram( unProgramID );
            glDeleteShader( nSceneFragmentShader );
            return 0;    
        }

        glAttachShader( unProgramID, nSceneFragmentShader );
        glDeleteShader( nSceneFragmentShader ); // the program hangs onto this once it's attached

        glLinkProgram( unProgramID );

        GLint programSuccess = GL_TRUE;
        glGetProgramiv( unProgramID, GL_LINK_STATUS, &programSuccess);
        if ( programSuccess != GL_TRUE )
        {
            dprintf("%s - Error linking program %d! ", pchShaderName, unProgramID);
            glDeleteProgram( unProgramID );
            return 0;
        }

        glUseProgram( unProgramID );
        glUseProgram( 0 );

        return unProgramID;
    }

  • 相关阅读:
    poj3723Conscription
    hiho1304 24点
    hdu2089不要62
    hdu3555Bomb
    关于分割平面问题
    poj2976Dropping tests(01分数规划)
    linux命令行
    java内存不足
    如何设置jsp默认的编码为utf-8
    visul svn+花生壳
  • 原文地址:https://www.cnblogs.com/mazhenyu/p/6544126.html
Copyright © 2011-2022 走看看