Project

General

Profile

Download (4.29 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / monalisa / MonaLisaRenderer.java @ 3c28857f

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.monalisa;
21

    
22
import java.io.IOException;
23
import java.io.InputStream;
24

    
25
import javax.microedition.khronos.egl.EGLConfig;
26
import javax.microedition.khronos.opengles.GL10;
27

    
28
import org.distorted.examples.R;
29
import org.distorted.library.Distorted;
30
import org.distorted.library.DistortedBitmap;
31
import org.distorted.library.EffectTypes;
32
import org.distorted.library.type.Dynamic3D;
33
import org.distorted.library.type.Static2D;
34
import org.distorted.library.type.Static3D;
35
import org.distorted.library.type.Static4D;
36

    
37
import android.graphics.Bitmap;
38
import android.graphics.BitmapFactory;
39
import android.opengl.GLES20;
40
import android.opengl.GLSurfaceView;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
class MonaLisaRenderer implements GLSurfaceView.Renderer 
45
{
46
    private GLSurfaceView mView;
47
    private DistortedBitmap monaLisa;
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
    public MonaLisaRenderer(GLSurfaceView v) 
52
      {
53
      mView = v;
54
      }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
   
58
    public void onDrawFrame(GL10 glUnused) 
59
      {
60
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
61
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
62
      
63
      monaLisa.draw(System.currentTimeMillis());
64
      }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
    
68
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
69
      { 
70
      monaLisa.abortEffects(EffectTypes.MATRIX);
71
      monaLisa.move( new Static3D((width-200)/2, 10, 0) );
72

    
73
      Distorted.onSurfaceChanged(width, height); 
74
      }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
    
78
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
79
      {
80
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.monalisa);
81
      Bitmap bitmap;
82
        
83
      try 
84
        {
85
        bitmap = BitmapFactory.decodeStream(is);
86
        } 
87
      finally 
88
        {
89
        try 
90
          {
91
          is.close();
92
          } 
93
        catch(IOException e) { }
94
        }  
95

    
96
      monaLisa = new DistortedBitmap(200,200,1);
97
      monaLisa.setBitmap(bitmap);
98

    
99
      try
100
        {
101
        Distorted.onSurfaceCreated(mView.getContext());
102
        }
103
      catch(Exception ex)
104
        {
105
        android.util.Log.e("MonaLisa", ex.getMessage() );
106
        }
107
      }
108
}
(2-2/3)