2014-03-13 34 views
2

基本上我想创建一个包含我的顶点着色器以及片段着色器的文件。如何在OpenGL/GLES着色器中添加指令?

这样子。

#ifdef VERTEX 
    attribute vec4 a_pos; 
    attribute vec2 a_texCoords; 
    uniform mat4 combined; 
    varying vec2 v_texCoords; 
     void main(){ 
      v_texCoords = a_texCoords; 
      gl_Position = combined * a_pos; 
     } 
    #endif 

    #ifdef FRAGMENT 
    varying vec2 v_texCoords; 
    uniform sampler2D u_texture; 
    void main() { 
     gl_FragColor = texture2D(u_texture, v_texCoords); 
     //gl_FragColor = vec4(1,0,0,1); 
    } 
    #endif 

但是如何在编译像c/C++中的make_file这样的着色器时传递指令?用它作为顶点着色器源代码时使用它作为片段着色器的源代码

这样当

回答

2

我只是前缀#define VERTEX\n的代码串的开始,#define FRAGMENT\n: -

void compileShader(int TYPE, String source){ 
    switch(TYPE){ 
    case GL20.GL_VERTEX_SHADER: 
      source = "#define VERTEX \n" + source; 
    case GL20.GL_FRAGMENT_SHADER: 
      source = "#define FRAGMENT \n" + source; 
    } 
    //then compile source 
} 
相关问题