Project

General

Profile

« Previous | Next » 

Revision fdddb0b2

Added by Leszek Koltunski almost 7 years ago

Further progress with Apps: 28 (out of 31) compile now.

View differences:

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

  
27 27
import org.distorted.examples.R;
28 28
import org.distorted.library.effect.EffectName;
29
import org.distorted.library.effect.FragmentEffectBrightness;
30
import org.distorted.library.effect.MatrixEffectMove;
31
import org.distorted.library.effect.MatrixEffectRotate;
32
import org.distorted.library.effect.MatrixEffectScale;
29 33
import org.distorted.library.main.Distorted;
30 34
import org.distorted.library.main.DistortedEffects;
31 35
import org.distorted.library.main.DistortedFramebuffer;
32 36
import org.distorted.library.main.DistortedNode;
33 37
import org.distorted.library.main.DistortedScreen;
34 38
import org.distorted.library.main.DistortedTexture;
35
import org.distorted.library.EffectNames;
36
import org.distorted.library.EffectTypes;
37 39
import org.distorted.library.main.MeshCubes;
38 40
import org.distorted.library.main.MeshFlat;
39 41
import org.distorted.library.main.MeshObject;
......
54 56
    private GLSurfaceView mView;
55 57
    private DistortedScreen mScreen;
56 58
    private DistortedTexture mCubeTex, mFloorTex, mFBOTex;
57
    private DistortedEffects mCube1Effects, mCube2Effects, mFloorEffects, mFBOEffects;
58 59
    private DistortedNode mCube1Node, mCube2Node, mFloorNode, mFBONode;
59 60
    private MeshObject mCubeMesh, mQuad;
61
    private Static3D mCubeMove, mCubeScale, mFloorScale, mFloorMove, mFBOScale;
60 62

  
61 63
///////////////////////////////////////////////////////////////////////////////////////////////////
62 64

  
......
89 91
      mCubeMesh = new MeshCubes(1,1,1);
90 92
      mQuad     = new MeshFlat(1,1);
91 93

  
94
      mCubeMove   = new Static3D(0,0,0);
95
      mCubeScale  = new Static3D(1,1,1);
96
      mFloorScale = new Static3D(1,1,1);
97
      mFloorMove  = new Static3D(0,0,0);
98
      mFBOScale   = new Static3D(1,1,1);
99

  
92 100
      mCubeTex   = new DistortedTexture(1,1);
93 101
      mFloorTex  = new DistortedTexture(1,1);
94 102
      mFBOTex    = new DistortedTexture(1,1);
95 103

  
96
      mCube1Effects = new DistortedEffects();
97
      mCube2Effects = new DistortedEffects();
98
      mFloorEffects = new DistortedEffects();
99
      mFBOEffects   = new DistortedEffects();
104
      DistortedEffects cube1Effects = new DistortedEffects();
105
      DistortedEffects cube2Effects = new DistortedEffects();
106
      DistortedEffects floorEffects = new DistortedEffects();
107
      DistortedEffects FBOEffects   = new DistortedEffects();
100 108

  
101
      mCube2Effects.brightness(new Static1D(0.5f));
109
      cube2Effects.apply( new FragmentEffectBrightness(new Static1D(0.5f)) );
102 110

  
103
      mCube1Node = new DistortedNode(mCubeTex ,mCube1Effects,mCubeMesh );
104
      mCube2Node = new DistortedNode(mCubeTex ,mCube2Effects,mCubeMesh );
105
      mFloorNode = new DistortedNode(mFloorTex,mFloorEffects,mQuad     );
106
      mFBONode   = new DistortedNode(mFBOTex  ,mFBOEffects  ,mQuad     );
111
      mCube1Node = new DistortedNode(mCubeTex ,cube1Effects,mCubeMesh );
112
      mCube2Node = new DistortedNode(mCubeTex ,cube2Effects,mCubeMesh );
113
      mFloorNode = new DistortedNode(mFloorTex,floorEffects,mQuad     );
114
      mFBONode   = new DistortedNode(mFBOTex  ,FBOEffects  ,mQuad     );
107 115

  
108 116
      ///////////////// The Meat of this App - shamelessly ripped off https://open.gl/depthstencils ///////////////////////
109 117
      /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
133 141
      mView.setEGLConfigChooser(5,6,5,0,16,8);       // Screen: 16 bit depth, 8 bit STENCIL
134 142

  
135 143
      setScreen(true);
136
      }
137

  
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

  
140
    public void onDrawFrame(GL10 glUnused) 
141
      {
142
      mScreen.render(System.currentTimeMillis());
143
      }
144 144

  
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
    
147
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
148
      {
149 145
      float cw = mCubeTex.getWidth();
150 146
      float ch = mCubeTex.getHeight();
151 147
      float cd = mCubeTex.getDepth(mCubeMesh);
......
154 150
      float fh = mFloorTex.getHeight();
155 151
      float fd = mFloorTex.getDepth(mQuad);
156 152

  
157
      float bw = mFBOTex.getWidth();
158
      float bh = mFBOTex.getHeight();
159

  
160
      float cubeScale = 0.4f*(width>height ? height/ch:width/cw);
161
      float floorScale= 0.8f*(width>height ? height/fh:width/fw);
162

  
163 153
      Static3D cubeCenter = new Static3D(cw/2,ch  ,-cd/2);
164 154
      Static3D floorCenter= new Static3D(fw/2,fh/2,-fd/2);
165 155

  
......
177 167
      Static1D rotSt1 = new Static1D(angle);
178 168
      Static1D rotSt2 = new Static1D(angle-90.0f);
179 169

  
170
      MatrixEffectRotate rot1 = new MatrixEffectRotate(rotSt1, axisX, cubeCenter);
171
      MatrixEffectRotate rot2 = new MatrixEffectRotate(rotDyn, axisY, cubeCenter);
172
      MatrixEffectScale  scal = new MatrixEffectScale(mCubeScale);
173
      MatrixEffectMove   move = new MatrixEffectMove(mCubeMove);
174

  
180 175
      /////////////////////////////////////////////////////////////////////////////////////////////////////
181 176
      // Those Matrix effects, i.e. correct positioning of Objects on the Screen, is admittedly quite hard.
182 177
      // Figured out of experimentation.
183 178
      /////////////////////////////////////////////////////////////////////////////////////////////////////
184 179
      // Upper cube
185
      mCube1Effects.abortEffects(EffectTypes.MATRIX);
186
      mCube1Effects.move( new Static3D( (width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2) );
187
      mCube1Effects.scale(cubeScale);
188
      mCube1Effects.rotate(rotSt1, axisX, cubeCenter);
189
      mCube1Effects.rotate(rotDyn, axisY, cubeCenter);
180
      cube1Effects.apply( move );
181
      cube1Effects.apply( scal );
182
      cube1Effects.apply( rot1 );
183
      cube1Effects.apply( rot2 );
190 184

  
191 185
      /////////////////////////////////////////////////////////////////////////////////////////////////////
192 186
      // Floor
193
      mFloorEffects.abortEffects(EffectTypes.MATRIX);
194
      mFloorEffects.move( new Static3D( (width-floorScale*fw)/2 ,height/2-floorScale*fh/2, floorScale*fd/2) );
195
      mFloorEffects.scale(floorScale);
196
      mFloorEffects.rotate(rotSt2, axisX, floorCenter);
197
      mFloorEffects.rotate(rotDyn, axisZ, floorCenter);
187
      floorEffects.apply( new MatrixEffectMove(mFloorMove));
188
      floorEffects.apply( new MatrixEffectScale(mFloorScale) );
189
      floorEffects.apply( new MatrixEffectRotate(rotSt2, axisX, floorCenter) );
190
      floorEffects.apply( new MatrixEffectRotate(rotDyn, axisZ, floorCenter) );
198 191

  
199 192
      /////////////////////////////////////////////////////////////////////////////////////////////////////
200 193
      // Lower cube
201
      mCube2Effects.abortEffects(EffectTypes.MATRIX);
202
      mCube2Effects.move( new Static3D( (width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2) );
203
      mCube2Effects.scale(cubeScale);
204
      mCube2Effects.rotate(rotSt1, axisX, cubeCenter);
205
      mCube2Effects.rotate(rotDyn, axisY, cubeCenter);
206
      mCube2Effects.scale(new Static3D(1,-1,1) );
207
      mCube2Effects.move( new Static3D( 0, -2*ch , 0) );
194
      cube2Effects.apply( move );
195
      cube2Effects.apply( scal );
196
      cube2Effects.apply( rot1 );
197
      cube2Effects.apply( rot2 );
198
      cube2Effects.apply( new MatrixEffectScale(new Static3D(1,-1,1)) );
199
      cube2Effects.apply( new MatrixEffectMove(new Static3D( 0, -2*ch , 0)) );
208 200

  
209 201
      /////////////////////////////////////////////////////////////////////////////////////////////////////
210 202
      // Framebuffer
211
      mFBOEffects.abortEffects(EffectTypes.MATRIX);
212
      mFBOEffects.scale( new Static3D( (float)width/bw, (float)height/bh, 1.0f) );
203
      FBOEffects.apply( new MatrixEffectScale(mFBOScale) );
204
      }
205

  
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

  
208
    public void onDrawFrame(GL10 glUnused) 
209
      {
210
      mScreen.render(System.currentTimeMillis());
211
      }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
    
215
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
216
      {
217
      float cw = mCubeTex.getWidth();
218
      float ch = mCubeTex.getHeight();
219
      float cd = mCubeTex.getDepth(mCubeMesh);
220

  
221
      float fw = mFloorTex.getWidth();
222
      float fh = mFloorTex.getHeight();
223
      float fd = mFloorTex.getDepth(mQuad);
224

  
225
      float bw = mFBOTex.getWidth();
226
      float bh = mFBOTex.getHeight();
227

  
228
      float cubeScale = 0.4f*(width>height ? height/ch:width/cw);
229
      float floorScale= 0.8f*(width>height ? height/fh:width/fw);
230

  
231
      mCubeMove.set((width-cubeScale*cw)/2 , height/2-cubeScale*ch , cubeScale *cd/2 );
232
      mCubeScale.set(cubeScale,cubeScale,cubeScale);
233
      mFloorMove.set((width-floorScale*fw)/2 ,height/2-floorScale*fh/2, floorScale*fd/2 );
234
      mFloorScale.set(floorScale,floorScale,floorScale);
235
      mFBOScale.set((float)width/bw, (float)height/bh, 1.0f );
213 236

  
214 237
      mFBONode.resize( (int)((float)width/bw), (int)((float)height/bh) );
215 238
      mScreen.resize( width,height);

Also available in: Unified diff