2014-03-13 5 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 
} 
관련 문제