yasuhirohoshino
8/18/2016 - 8:26 AM

openFrameworks inline shader template (only vert & frag)

openFrameworks inline shader template (only vert & frag)

#pragma once
#include "ofMain.h"

#define STRINGIFY(A) #A

class Shader{
public:
    string gl2VertShader;
    string gl2FragShader;
    
    string gl3VertShader;
    string gl3FragShader;
    
    Shader(){
        gl2VertShader = "#version 120\n";
        gl2VertShader += STRINGIFY(
          
          // vertex shader.
          
          );
          
        gl2FragShader = "#version 120\n";
        gl2FragShader += STRINGIFY(
          
          // fragment shader.
          
          );
      
        gl3VertShader = "#version 150\n";
        gl3VertShader += STRINGIFY(
          
          // vertex shader.
          
          );
        
        gl3FragShader = "#version 150\n";
        gl3FragShader += STRINGIFY(
          
          // fragment shader.
          
          );
          
        
    }
};
if(ofIsGLProgrammableRenderer()){
  shader.setupShaderFromSource(GL_VERTEX_SHADER, Shader.gl3VertShader);
  shader.setupShaderFromSource(GL_FRAGMENT_SHADER, Shader.gl3FragShader);
  shader.bindDefaults();
  shader.linkProgram();
}else{
  shader.setupShaderFromSource(GL_VERTEX_SHADER, Shader.gl2VertShader);
  shader.setupShaderFromSource(GL_FRAGMENT_SHADER, Shader.gl2FragShader);
  shader.linkProgram();
}