Skip to content

Commit

Permalink
fix shaders examples for OpenGL ES (#6223)
Browse files Browse the repository at this point in the history
#changelog #opengles
  • Loading branch information
avilleret authored and arturoc committed Feb 4, 2019
1 parent 68fdf1a commit 8db8e45
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 23 deletions.
5 changes: 5 additions & 0 deletions examples/shader/01_simpleColorQuad/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
//========================================================================
int main( ){

#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);

// this kicks off the running of my app
Expand Down
6 changes: 5 additions & 1 deletion examples/shader/02_simpleVertexDisplacement/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
//========================================================================
int main( ){

#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);


// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
Expand Down
5 changes: 5 additions & 0 deletions examples/shader/03_simpleShaderInteraction/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
//========================================================================
int main( ){

#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);

// this kicks off the running of my app
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

precision highp float;

uniform vec2 resolution;
uniform sampler2D tex0;

varying vec2 texCoordVarying;
uniform float mouseX;

void main()
{
gl_FragColor = texture2D(tex0, texCoordVarying);
gl_FragColor = texture2D(tex0, (gl_FragCoord.xy + vec2(mouseX,0))/resolution.xy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ attribute vec2 texcoord;
// this is something we're creating for this shader
varying vec2 texCoordVarying;

// this is coming from our C++ code
uniform float mouseX;

void main()
{
// here we move the texture coordinates
texCoordVarying = vec2(texcoord.x + mouseX, texcoord.y);

// send the vertices to the fragment shader
gl_Position = modelViewProjectionMatrix * position;
}
7 changes: 6 additions & 1 deletion examples/shader/04_simpleTexturing/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
//========================================================================
int main( ){

#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
Expand Down
7 changes: 1 addition & 6 deletions examples/shader/04_simpleTexturing/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ void ofApp::draw() {

// get mouse position relative to center of screen
float mousePosition = ofMap(mouseX, 0, ofGetWidth(), 1.0, -1.0, true);
#ifndef TARGET_OPENGLES
// when texture coordinates are normalised, they are always between 0 and 1.
// in GL2 and GL3 the texture coordinates are not normalised,
// so we have to multiply the normalised mouse position by the plane width.
mousePosition *= plane.getWidth();
#endif

shader.setUniform1f("mouseX", mousePosition);

shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight());
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);

Expand Down
5 changes: 5 additions & 0 deletions examples/shader/05_alphaMasking/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
//========================================================================
int main( ){

#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);

// this kicks off the running of my app
Expand Down
5 changes: 5 additions & 0 deletions examples/shader/06_multiTexture/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
//========================================================================
int main( ){

#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);

// this kicks off the running of my app
Expand Down
5 changes: 5 additions & 0 deletions examples/shader/07_fboAlphaMask/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
//========================================================================
int main( ){

#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);

// this kicks off the running of my app
Expand Down
7 changes: 6 additions & 1 deletion examples/shader/08_displacementMap/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
//========================================================================
int main( ){

#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
Expand Down
13 changes: 8 additions & 5 deletions examples/shader/09_gaussianBlurFilter/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
//========================================================================
int main( ){

// ofGLWindowSettings settings;
// settings.setGLVersion(3,2);
// ofCreateWindow(settings);

ofSetupOpenGL(1024, 768, OF_WINDOW);
#ifdef OF_TARGET_OPENGLES
ofGLESWindowSettings settings;
settings.glesVersion=2;
#else
ofGLWindowSettings settings;
settings.setGLVersion(3,2);
#endif
ofCreateWindow(settings);

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
Expand Down

0 comments on commit 8db8e45

Please sign in to comment.