Project

General

Profile

« Previous | Next » 

Revision 08602667

Added by Leszek Koltunski almost 7 years ago

Beginnings of the GLOW unit test.

View differences:

src/main/AndroidManifest.xml
46 46
        <activity android:name=".blur.BlurActivity"/>
47 47
        <activity android:name=".multiblur.MultiblurActivity"/>
48 48
        <activity android:name=".stencil.StencilActivity"/>
49
        <activity android:name=".glow.GlowActivity"/>
49 50
    </application>
50 51
</manifest>
src/main/java/org/distorted/examples/TableOfContents.java
64 64
import org.distorted.examples.blur.BlurActivity;
65 65
import org.distorted.examples.multiblur.MultiblurActivity;
66 66
import org.distorted.examples.stencil.StencilActivity;
67
import org.distorted.examples.glow.GlowActivity;
67 68

  
68 69
///////////////////////////////////////////////////////////////////////////////////////////////////
69 70

  
......
356 357
      activityMapping.put(i++, StencilActivity.class);
357 358
   }
358 359

  
360
  {
361
      final Map<String, Object> item = new HashMap<>();
362
      item.put(ITEM_IMAGE, R.drawable.icon_example_glow);
363
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_glow));
364
      item.put(ITEM_SUBTITLE, getText(R.string.example_glow_subtitle));
365
      data.add(item);
366
      activityMapping.put(i++, GlowActivity.class);
367
   }
368

  
359 369
   final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
360 370
   setListAdapter(dataAdapter);  
361 371
      
src/main/java/org/distorted/examples/glow/GlowActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.examples.glow;
21

  
22
import android.app.Activity;
23
import android.os.Bundle;
24
import org.distorted.library.Distorted;
25

  
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

  
28
public class GlowActivity extends Activity
29
{
30
    private GlowSurfaceView mView;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
    @Override
35
    protected void onCreate(Bundle savedState)
36
      {
37
      super.onCreate(savedState);
38
      mView = new GlowSurfaceView(this);
39
      setContentView(mView);
40
      }
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
    
44
    @Override
45
    protected void onPause() 
46
      {
47
      mView.onPause();
48
      Distorted.onPause();
49
      super.onPause();
50
      }
51

  
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
    
54
    @Override
55
    protected void onResume() 
56
      {
57
      super.onResume();
58
      mView.onResume();
59
      }
60
 
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
    
63
    @Override
64
    protected void onDestroy() 
65
      {
66
      Distorted.onDestroy();  
67
      super.onDestroy();
68
      }
69
}
src/main/java/org/distorted/examples/glow/GlowRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.examples.glow;
21

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

  
26
import org.distorted.examples.R;
27
import org.distorted.library.Distorted;
28
import org.distorted.library.DistortedEffects;
29
import org.distorted.library.DistortedNode;
30
import org.distorted.library.DistortedScreen;
31
import org.distorted.library.DistortedTexture;
32
import org.distorted.library.EffectNames;
33
import org.distorted.library.EffectTypes;
34
import org.distorted.library.MeshFlat;
35
import org.distorted.library.MeshObject;
36
import org.distorted.library.type.Dynamic1D;
37
import org.distorted.library.type.Static1D;
38
import org.distorted.library.type.Static3D;
39

  
40
import java.io.IOException;
41
import java.io.InputStream;
42

  
43
import javax.microedition.khronos.egl.EGLConfig;
44
import javax.microedition.khronos.opengles.GL10;
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
class GlowRenderer implements GLSurfaceView.Renderer
49
{
50
   private static final int[] colors  = new int[] {0,0,1,  0,0,0,  1,0,0,  1,1,0,  0,1,0,  1,1,1}; // blue, black, red, yellow, green, white
51
   private static final int LEAF_SIZE = 100;
52
   private static final int NUM_LEAVES= colors.length/3;
53
   
54
   private GLSurfaceView mView;
55
   private DistortedNode mRoot;
56
   private DistortedTexture mLeaf;
57
   private DistortedScreen mScreen;
58
   private int mRootW, mRootH;
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
   GlowRenderer(GLSurfaceView v)
63
      {     
64
      mView = v;
65

  
66
      mRootW = 3*LEAF_SIZE;
67
      mRootH = 3*LEAF_SIZE;
68

  
69
      mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE);
70
      DistortedTexture surface = new DistortedTexture(mRootW,mRootH);
71
      MeshObject mesh = new MeshFlat(1,1);
72
      DistortedEffects[] leafEffects = new DistortedEffects[NUM_LEAVES];
73

  
74
      mRoot = new DistortedNode(surface, new DistortedEffects(), mesh);
75
     
76
      Static3D moveVector = new Static3D(0,LEAF_SIZE,0);
77
      Static1D chromaLevel= new Static1D(0.5f);
78
      Static3D center     = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
79
      Static3D axis       = new Static3D(0,0,1);
80

  
81
      for(int j=0; j<NUM_LEAVES; j++)
82
        {
83
        leafEffects[j] = new DistortedEffects();
84
        leafEffects[j].rotate( new Static1D(j*(360/NUM_LEAVES)), axis, center );
85
        leafEffects[j].move(moveVector);
86
        leafEffects[j].chroma( chromaLevel, new Static3D(colors[3*j],colors[3*j+1], colors[3*j+2]) );
87

  
88
        mRoot.attach( mLeaf, leafEffects[j], mesh);
89
        }
90

  
91
      mScreen = new DistortedScreen(mView);
92
      mScreen.attach(mRoot);
93
      }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
   
97
    public void onDrawFrame(GL10 glUnused) 
98
      {
99
      mScreen.render(System.currentTimeMillis());
100
      }
101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
    
104
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
105
      {
106
      float qw = (float)width /mRootW;
107
      float qh = (float)height/mRootH;
108
      float factor = 0.6f* (qw<qh ? qw:qh);
109
      int w = (int)(factor*mRootW);
110
      int h = (int)(factor*mRootH);
111

  
112
      Dynamic1D rot = new Dynamic1D(5000,0.0f);
113
      rot.setMode(Dynamic1D.MODE_JUMP);
114
      rot.add(new Static1D(  0));
115
      rot.add(new Static1D(360));
116

  
117
      Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
118
      Static3D axis   = new Static3D(0,0,1);
119

  
120
      DistortedEffects effects = mRoot.getEffects();
121
      effects.abortEffects(EffectTypes.MATRIX);
122
      effects.move( new Static3D((width-w)/2 ,(height-h)/2, 0) );
123
      effects.scale( factor );
124
      effects.rotate( rot, axis, center );
125

  
126
      mScreen.resize(width, height);
127
      }
128

  
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130
    
131
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
132
      {
133
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
134
      Bitmap leaf;
135
      
136
      try 
137
        {
138
        leaf = BitmapFactory.decodeStream(is);
139
        } 
140
      finally 
141
        {
142
        try 
143
          {
144
          is.close();
145
          } 
146
        catch(IOException e) { }
147
        }  
148
      
149
      mLeaf.setTexture(leaf);
150

  
151
      DistortedEffects.enableEffect(EffectNames.CHROMA);
152
      DistortedEffects.enableEffect(EffectNames.GLOW);
153

  
154
      try
155
        {
156
        Distorted.onCreate(mView.getContext());
157
        }
158
      catch(Exception ex)
159
        {
160
        android.util.Log.e("Glow", ex.getMessage() );
161
        }
162
      }
163
 
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165
    
166
}
src/main/java/org/distorted/examples/glow/GlowSurfaceView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.examples.glow;
21

  
22
import android.content.Context;
23
import android.opengl.GLSurfaceView;
24

  
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

  
27
class GlowSurfaceView extends GLSurfaceView
28
{
29
    public GlowSurfaceView(Context context)
30
      {
31
      super(context);
32
      setRenderer(new GlowRenderer(this));
33
      }
34
}
35

  
src/main/res/values/strings.xml
145 145
    <string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</string>
146 146
    <string name="example_stencil">Stencil Buffer</string>
147 147
    <string name="example_stencil_subtitle">Implement the classic stencil example from https://open.gl/depthstencils</string>
148
    <string name="example_glow">Glow Effect</string>
149
    <string name="example_glow_subtitle">See objects glowing with light.</string>
148 150

  
149 151
    <string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string>
150 152
    <string name="example_rotate_toast">Rotate the scene by swiping the screen</string>

Also available in: Unified diff