Project

General

Profile

« Previous | Next » 

Revision b0568eb5

Added by Leszek Koltunski about 7 years ago

Progress with Stencil App; should be working now AFAIK but doesn't.

View differences:

src/main/java/org/distorted/examples/stencil/StencilRenderer.java
21 21

  
22 22
import android.graphics.Bitmap;
23 23
import android.graphics.BitmapFactory;
24
import android.opengl.GLES30;
24 25
import android.opengl.GLSurfaceView;
25 26

  
26 27
import org.distorted.examples.R;
27 28
import org.distorted.library.Distorted;
28 29
import org.distorted.library.DistortedEffects;
30
import org.distorted.library.DistortedNode;
29 31
import org.distorted.library.DistortedScreen;
30 32
import org.distorted.library.DistortedTexture;
31 33
import org.distorted.library.EffectNames;
......
52 54
    private DistortedTexture mCubeTex, mFloorTex;
53 55
    private DistortedEffects mCube1Effects, mCube2Effects, mFloorEffects;
54 56
    private MeshObject mCubeMesh, mFloorMesh;
55
    private int bmpHeight, bmpWidth;
57
    private DistortedNode mCube1Node, mCube2Node, mFloorNode;
56 58

  
57 59
///////////////////////////////////////////////////////////////////////////////////////////////////
58 60

  
......
72 74

  
73 75
      mCube2Effects.brightness(new Static1D(0.5f));
74 76

  
75
      mScreen = new DistortedScreen();
76
      mScreen.attach(mCubeTex ,mCube1Effects,mCubeMesh );
77
      mScreen.attach(mFloorTex,mFloorEffects,mFloorMesh);
78
      mScreen.attach(mCubeTex ,mCube2Effects,mCubeMesh );
77
      mCube1Node = new DistortedNode(mCubeTex ,mCube1Effects,mCubeMesh );
78
      mCube2Node = new DistortedNode(mCubeTex ,mCube2Effects,mCubeMesh );
79
      mFloorNode = new DistortedNode(mFloorTex,mFloorEffects,mFloorMesh);
80

  
81
      mFloorNode.glEnable(GLES30.GL_STENCIL_TEST);                               // Enable Stencil when rendering this Node
82
      mFloorNode.glStencilFunc(GLES30.GL_ALWAYS, 1, 0xFF);                       // Set any stencil to 1
83
      mFloorNode.glStencilOp(GLES30.GL_KEEP, GLES30.GL_KEEP, GLES30.GL_REPLACE); // replace with 1 when we fail Depth test
84
      mFloorNode.glStencilMask(0xFF);                                            // Write to stencil buffer
85
      mFloorNode.glDepthMask(false);                                             // Don't write to depth buffer
86
      mFloorNode.glClear(GLES30.GL_STENCIL_BUFFER_BIT);                          // Clear stencil buffer (0 by default)
87

  
88
      mCube2Node.glEnable(GLES30.GL_STENCIL_TEST);                               // Enable Stencil when rendering this Node
89
      mCube2Node.glStencilFunc(GLES30.GL_EQUAL, 1, 0xFF);                        // Pass test if stencil value is 1
90
      mCube2Node.glStencilMask(0x00);                                            // Don't write anything to stencil buffer
91
      mCube2Node.glDepthMask(true);                                              // Write to depth buffer
79 92

  
93
      mScreen = new DistortedScreen();
94
      mScreen.attach(mCube1Node);
95
      mScreen.attach(mFloorNode);
96
      mScreen.attach(mCube2Node);
80 97
      mScreen.glClearColor(1.0f,1.0f,1.0f,1.0f);
81 98
      }
82 99

  
......
162 179
        catch(IOException e) { }
163 180
        }
164 181

  
165
      bmpHeight = bitmap.getHeight();
166
      bmpWidth  = bitmap.getWidth();
167

  
168 182
      mCubeTex.setTexture(bitmap);
169 183
      mFloorTex.setColor(0xff000000);  // ARGB
170 184

  

Also available in: Unified diff