Project

General

Profile

Download (3.61 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / purchase / PurchaseRenderer.java @ de131f0a

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.purchase;
11

    
12
import android.opengl.GLSurfaceView;
13

    
14
import org.distorted.library.effect.EffectType;
15
import org.distorted.library.effect.VertexEffectQuaternion;
16
import org.distorted.library.effect.VertexEffectRotate;
17
import org.distorted.library.main.DistortedLibrary;
18
import org.distorted.library.main.DistortedScreen;
19
import org.distorted.objectlib.effects.BaseEffect;
20
import org.distorted.objectlib.main.ObjectControl;
21

    
22
import javax.microedition.khronos.egl.EGLConfig;
23
import javax.microedition.khronos.opengles.GL10;
24

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

    
27
public class PurchaseRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
28
{
29
   private static final int NUM_SCRAMBLES = 5;
30
   private static final int DURATION = NUM_SCRAMBLES*2*2500;
31

    
32
   private final PurchaseSurfaceView mView;
33
   private final DistortedScreen mScreen;
34

    
35
   private boolean mFirstRender;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
   PurchaseRenderer(PurchaseSurfaceView v)
40
     {
41
     final float BRIGHTNESS = 0.333f;
42

    
43
     mFirstRender = true;
44
     mView = v;
45
     mScreen = new DistortedScreen();
46
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
47
     }
48

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

    
51
   @Override
52
   public void onDrawFrame(GL10 glUnused)
53
     {
54
     long time = System.currentTimeMillis();
55
     mView.getObjectControl().preRender();
56
     mScreen.render(time);
57

    
58
     if( mFirstRender )
59
       {
60
       mFirstRender=false;
61
       mView.getObjectControl().presentObject(NUM_SCRAMBLES, DURATION);
62
       }
63
     }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
   @Override
68
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
69
      {
70
      mScreen.resize(width,height);
71
      mView.setScreenSize(width,height);
72
      }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
   @Override
77
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
78
      {
79
      DistortedLibrary.setMax(EffectType.VERTEX, ObjectControl.MAX_QUATS+1);
80
      VertexEffectRotate.enable();
81
      VertexEffectQuaternion.enable();
82
      BaseEffect.Type.enableEffects();
83

    
84
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
85
      }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
   public void distortedException(Exception ex)
90
     {
91
     android.util.Log.e("PURCHASE", "unexpected exception: "+ex.getMessage() );
92
     }
93

    
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

    
96
   DistortedScreen getScreen()
97
     {
98
     return mScreen;
99
     }
100
}
(3-3/6)