본문 바로가기

C++(oF)

Desktop 과 IOS(openGLES2.0) 의 쉐이더 텍스처 기본 시작 코드

Desktop 코드


#define STRINGIFY(A) #A

ofImage image1;
ofShader shader1;
//--------------------------------------------------------------
void ofApp::setup(){


string shaderProgram = STRINGIFY(

uniform sampler2DRect tex0;
void main(void)
{
vec2 pos = gl_TexCoord[0].st;
gl_FragColor = texture2DRect(tex0 , pos);
}

);

shader1.setupShaderFromSource(GL_FRAGMENT_SHADER , shaderProgram);
shader1.linkProgram();

image1.load("images/image1.jpg");

}

//--------------------------------------------------------------
void ofApp::draw(){
shader1.begin();
image1.draw(0,0);
shader1.end();

} 









IOS 코드 (아래 중요(important!)부분이 반드시 들어가야 setupShaderFromSource(...) 를 이용 할 수 있다)

#define STRINGIFY(A) #A

ofImage image1;
ofShader shader1;
//--------------------------------------------------------------
void ofApp::setup(){


ofxiPhoneSetOrientation(OF_ORIENTATION_90_LEFT);

string shaderProgram_vert = STRINGIFY(
uniform mat4 modelViewProjectionMatrix;
attribute vec4 position;
attribute vec2 texcoord;
varying vec2 texCoordVarying;

void main(void)
{
texCoordVarying = texcoord;
gl_Position = modelViewProjectionMatrix * position;
}
);

string shaderProgram_frag = STRINGIFY(

precision highp float;
uniform sampler2D tex0;
varying vec2 texCoordVarying;
void main(void)
{
gl_FragColor = texture2D(tex0 , texCoordVarying);
}

);

shader1.setupShaderFromSource(GL_VERTEX_SHADER , shaderProgram_vert );
shader1.setupShaderFromSource(GL_FRAGMENT_SHADER , shaderProgram_frag);

// important!
if( ofIsGLProgrammableRenderer())
{
shader1.bindDefaults();
}
shader1.linkProgram();

image1.load("images/image1.jpg");

}

void ofApp::draw(){

shader1.begin();
image1.draw(0,0);
shader1.end();

}