Project

General

Profile

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

magiccube / src / main / java / org / distorted / purchase / PurchaseRenderer.java @ 2876aeb6

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.library.mesh.MeshBase;
20
import org.distorted.objectlib.effects.BaseEffect;
21
import org.distorted.objectlib.main.ObjectControl;
22
import org.distorted.overlays.OverlayGeneric;
23

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

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

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

    
34
   private final PurchaseSurfaceView mView;
35
   private final DistortedScreen mScreen;
36

    
37
   private boolean mFirstRender;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
   PurchaseRenderer(PurchaseSurfaceView v)
42
     {
43
     final float BRIGHTNESS = 0.333f;
44

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

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

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

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
   @Override
79
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
80
      {
81
      DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1);
82
      MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
83

    
84
      VertexEffectRotate.enable();
85
      VertexEffectQuaternion.enable();
86
      BaseEffect.Type.enableEffects();
87
      OverlayGeneric.enableEffects();
88

    
89
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
90
      DistortedLibrary.setCull(true);
91
      }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
   public void distortedException(Exception ex)
96
     {
97
     android.util.Log.e("PURCHASE", "unexpected exception: "+ex.getMessage() );
98
     }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
   DistortedScreen getScreen()
103
     {
104
     return mScreen;
105
     }
106
}
(3-3/6)