Project

General

Profile

« Previous | Next » 

Revision 9c3e749e

Added by Leszek Koltunski over 6 years ago

Make the Cubes App capable of testing unprocessed OIT.

View differences:

src/main/java/org/distorted/examples/cubes/CubesActivity.java
30 30
import android.os.Bundle;
31 31
import android.view.Gravity;
32 32
import android.view.View;
33
import android.widget.AdapterView;
34
import android.widget.ArrayAdapter;
33 35
import android.widget.Button;
34 36
import android.widget.LinearLayout;
35 37
import android.widget.NumberPicker;
36 38
import android.widget.NumberPicker.OnValueChangeListener;
39
import android.widget.SeekBar;
40
import android.widget.Spinner;
37 41
import android.widget.TableRow;
38 42

  
39 43
///////////////////////////////////////////////////////////////////////////////////////////////////
40 44

  
41
public class CubesActivity extends Activity implements View.OnClickListener
45
public class CubesActivity extends Activity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
42 46
{
43 47
    private static final int COLOR_OFF = 0xffffe81f;
44 48
    private static final int COLOR_ON  = 0xff0000ff;
......
61 65

  
62 66
      setContentView(R.layout.cubespickerlayout);
63 67
      
64
      mLay = (LinearLayout)findViewById(R.id.cubespicker_buttongrid);
68
      mLay = findViewById(R.id.cubespicker_buttongrid);
65 69
      
66
      mColsPicker = (NumberPicker)findViewById(R.id.cubespicker_cols);
67
      mRowsPicker = (NumberPicker)findViewById(R.id.cubespicker_rows);
68
      mSlicPicker = (NumberPicker)findViewById(R.id.cubespicker_slices);
70
      mColsPicker = findViewById(R.id.cubespicker_cols);
71
      mRowsPicker = findViewById(R.id.cubespicker_rows);
72
      mSlicPicker = findViewById(R.id.cubespicker_slices);
69 73

  
70 74
      mColsPicker.setMaxValue(40);
71 75
      mColsPicker.setMinValue( 0);
......
178 182
    @Override
179 183
    protected void onPause() 
180 184
      {
181
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.cubesSurfaceView);
185
      GLSurfaceView mView = this.findViewById(R.id.cubesSurfaceView);
182 186
      if( mView!=null ) mView.onPause();
183 187

  
184 188
      Distorted.onPause();
......
192 196
      {
193 197
      super.onResume();
194 198
      
195
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.cubesSurfaceView);
199
      GLSurfaceView mView = this.findViewById(R.id.cubesSurfaceView);
196 200
      if( mView!=null ) mView.onResume();  
197 201
      }
198 202
    
......
218 222
      mTexture = new DistortedTexture(mNumCols,mNumRows);
219 223

  
220 224
      setContentView(R.layout.cubeslayout);
225

  
226
      Spinner renderSpinner  = findViewById(R.id.cubes_spinnerMode);
227
      renderSpinner.setOnItemSelectedListener(this);
228

  
229
      String[] objectBitmap = new String[] { "Render: Normal", "Render: OIT" };
230

  
231
      ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
232
      adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
233
      renderSpinner.setAdapter(adapterBitmap);
234

  
235
      SeekBar transparencyBar = findViewById(R.id.cubesTransparency);
236

  
237
      transparencyBar.setOnSeekBarChangeListener(this);
238

  
239
      CubesSurfaceView view = this.findViewById(R.id.cubesSurfaceView);
240
      view.getRenderer().setTransparency(50);
241
      transparencyBar.setProgress(50);
242
      }
243

  
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

  
246
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
247
      {
248
      CubesSurfaceView v = this.findViewById(R.id.cubesSurfaceView);
249
      CubesRenderer renderer = v.getRenderer();
250

  
251
      switch(parent.getId())
252
        {
253
        case R.id.cubes_spinnerMode: renderer.setRenderModeToOIT(pos==1);
254
                                     break;
255
        }
256
      }
257

  
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

  
260
    public void onNothingSelected(AdapterView<?> parent)
261
      {
262
      }
263

  
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

  
266
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
267
      {
268
      switch (bar.getId())
269
        {
270
        case R.id.cubesTransparency: CubesSurfaceView view = this.findViewById(R.id.cubesSurfaceView);
271
                                     view.getRenderer().setTransparency(progress);
272
                                     break;
273
        }
221 274
      }
222 275

  
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

  
278
    public void onStartTrackingTouch(SeekBar bar) { }
279

  
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281

  
282
    public void onStopTrackingTouch(SeekBar bar)  { }
283

  
223 284
///////////////////////////////////////////////////////////////////////////////////////////////////
224 285

  
225 286
    public DistortedTexture getTexture()
src/main/java/org/distorted/examples/cubes/CubesRenderer.java
27 27

  
28 28
import org.distorted.examples.R;
29 29

  
30
import org.distorted.library.effect.FragmentEffectAlpha;
30 31
import org.distorted.library.effect.MatrixEffectMove;
31 32
import org.distorted.library.effect.MatrixEffectQuaternion;
32 33
import org.distorted.library.effect.MatrixEffectScale;
......
35 36
import org.distorted.library.main.DistortedTexture;
36 37
import org.distorted.library.main.MeshObject;
37 38
import org.distorted.library.type.DynamicQuat;
39
import org.distorted.library.type.Static1D;
38 40
import org.distorted.library.type.Static4D;
39 41
import org.distorted.library.type.Static3D;
40 42
import org.distorted.library.main.Distorted;
......
54 56
    private DistortedScreen mScreen;
55 57
    private int mObjWidth, mObjHeight, mObjDepth;
56 58
    private Static3D mMove, mScale, mCenter;
59
    private Static1D mAlpha;
57 60

  
58 61
    Static4D mQuat1, mQuat2;
59 62
    int mScreenMin;
60
    
63

  
61 64
///////////////////////////////////////////////////////////////////////////////////////////////////
62 65

  
63 66
    CubesRenderer(GLSurfaceView v)
64 67
      {
65 68
      mView = v;
66 69

  
70
      mAlpha = new Static1D(1.0f);
71

  
67 72
      mMove = new Static3D(0,0,0);
68 73
      mScale= new Static3D(1,1,1);
69 74
      mCenter=new Static3D(0,0,0);
......
91 96
      mEffects.apply( new MatrixEffectScale(mScale));
92 97
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
93 98
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
99
      mEffects.apply( new FragmentEffectAlpha(mAlpha));
94 100

  
95 101
      mScreen = new DistortedScreen();
102
      mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f);
96 103
      }
97 104

  
98 105
///////////////////////////////////////////////////////////////////////////////////////////////////
......
114 121
      mScreen.resize(width, height);
115 122
      }
116 123

  
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

  
126
    void setRenderModeToOIT(boolean oit)
127
      {
128
      mScreen.setOrderIndependentTransparency(oit);
129
      }
130

  
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

  
133
    void setTransparency(int level)
134
      {
135
      mAlpha.set((float)level/100.0f);
136
      }
137

  
117 138
///////////////////////////////////////////////////////////////////////////////////////////////////
118 139
    
119 140
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
......
139 160
      mScreen.detachAll();
140 161
      mScreen.attach(mTexture,mEffects,mMesh);
141 162

  
163
      FragmentEffectAlpha.enable();
164

  
142 165
      try
143 166
        {
144 167
        Distorted.onCreate(mView.getContext());
src/main/java/org/distorted/examples/cubes/CubesSurfaceView.java
55 55
        Toast.makeText(context, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show();
56 56
        }
57 57
      }
58
    
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

  
61
    public CubesRenderer getRenderer()
62
      {
63
      return mRenderer;
64
      }
65

  
59 66
///////////////////////////////////////////////////////////////////////////////////////////////////
60 67
    
61 68
    @Override public boolean onTouchEvent(MotionEvent event) 
src/main/java/org/distorted/examples/multiblur/MultiblurActivity.java
47 47
      super.onCreate(savedState);
48 48
      setContentView(R.layout.multiblurlayout);
49 49

  
50
      SeekBar distanceBar = (SeekBar)findViewById(R.id.multiblurDistanceSeek);
51
      SeekBar rangeBar    = (SeekBar)findViewById(R.id.multiblurRangeSeek);
50
      SeekBar distanceBar = findViewById(R.id.multiblurDistanceSeek);
51
      SeekBar rangeBar    = findViewById(R.id.multiblurRangeSeek);
52 52

  
53 53
      distanceBar.setOnSeekBarChangeListener(this);
54 54
      rangeBar.setOnSeekBarChangeListener(this);
......
60 60
        mQuality = EffectQuality.HIGHEST.ordinal();
61 61
        }
62 62

  
63
      Spinner typeSpinner  = (Spinner)findViewById(R.id.multiblur_spinnerQuality);
63
      Spinner typeSpinner  = findViewById(R.id.multiblur_spinnerQuality);
64 64
      typeSpinner.setOnItemSelectedListener(this);
65 65

  
66 66
      String[] objectType = new String[] {"Quality Highiest", "Quality High", "Quality Medium", "Quality Low"};
......
69 69
      adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
70 70
      typeSpinner.setAdapter(adapterType);
71 71

  
72
      Spinner bitmapSpinner  = (Spinner)findViewById(R.id.multiblur_spinnerMode);
72
      Spinner bitmapSpinner  = findViewById(R.id.multiblur_spinnerMode);
73 73
      bitmapSpinner.setOnItemSelectedListener(this);
74 74

  
75 75
      String[] objectBitmap = new String[] { "Render: Normal", "Render: OIT" };
src/main/res/layout/cubeslayout.xml
11 11
        android:layout_height="0dp"
12 12
        android:layout_weight="1.00" />
13 13

  
14
    <LinearLayout
15
        android:id="@+id/linearLayout3"
16
        android:layout_width="fill_parent"
17
        android:layout_height="wrap_content"
18
        android:gravity="center|fill_horizontal"
19
        android:orientation="horizontal"
20
        android:background="@color/blue">
21

  
22
        <SeekBar
23
            android:id="@+id/cubesTransparency"
24
            android:layout_weight="0.5"
25
            android:layout_width="0dp"
26
            android:layout_height="50dp"
27
            android:paddingLeft="10dp"
28
            android:paddingRight="10dp" />
29

  
30
        <Spinner
31
            android:layout_width="0dp"
32
            android:layout_height="50dp"
33
            android:layout_weight="0.5"
34
            android:id="@+id/cubes_spinnerMode"
35
            />
36
    </LinearLayout>
37

  
14 38
</LinearLayout>

Also available in: Unified diff