Project

General

Profile

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

examples / src / main / java / org / distorted / examples / predeform / PredeformRenderer.java @ 0dc8ffef

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

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

    
25
import org.distorted.library.effect.MatrixEffectScale;
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedLibrary;
28
import org.distorted.library.main.DistortedScreen;
29
import org.distorted.library.main.DistortedTexture;
30
import org.distorted.library.mesh.MeshBase;
31
import org.distorted.library.type.Static3D;
32

    
33
import javax.microedition.khronos.egl.EGLConfig;
34
import javax.microedition.khronos.opengles.GL10;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
class PredeformRenderer implements GLSurfaceView.Renderer
39
{
40
    private static final float FOV =  0.0f;
41
    private static final float NEAR = 0.1f;
42

    
43
    private GLSurfaceView mView;
44
    private DistortedTexture mTexture;
45
    private DistortedEffects mEffects;
46
    private MeshBase mMesh;
47
    private DistortedScreen mScreen;
48
    private Static3D mScale;
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
    PredeformRenderer(GLSurfaceView v)
53
      {
54
      mView = v;
55

    
56
      mScale= new Static3D(1,1,1);
57
      mTexture = new DistortedTexture();
58
      mEffects = new DistortedEffects();
59
      mEffects.apply( new MatrixEffectScale(mScale));
60

    
61
      mScreen = new DistortedScreen();
62
      mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f);
63
      mScreen.setProjection(FOV, NEAR);
64
      }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
    void setMesh(MeshBase mesh)
69
      {
70
      mMesh = mesh;
71
      }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
    void setTexture(Bitmap bmp)
76
      {
77
      mTexture.setTexture(bmp);
78
      }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
    public void onDrawFrame(GL10 glUnused) 
83
      {
84
      mScreen.render( System.currentTimeMillis() );
85
      }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88
    
89
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
90
      {
91
      final float SCALE = 0.75f;
92

    
93
      float factor = ( width > height ) ? SCALE*height : SCALE*width;
94
      mScale.set(factor,factor,factor);
95
      mScreen.resize(width, height);
96
      }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
    
100
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
101
      {
102
      PredeformActivity act = (PredeformActivity)mView.getContext();
103

    
104
      mMesh = act.getMesh();
105
      mTexture.setTexture( act.getBitmap() );
106
      mScreen.detachAll();
107
      mScreen.attach(mTexture,mEffects,mMesh);
108

    
109
      try
110
        {
111
        DistortedLibrary.onCreate(act);
112
        }
113
      catch(Exception ex)
114
        {
115
        android.util.Log.e("Inflate", ex.getMessage() );
116
        }
117
      }
118
}
(4-4/7)