Project

General

Profile

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

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

1 c7238c67 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 d0ad3964 Leszek Koltunski
import android.app.ActivityManager;
13
import android.content.Context;
14
import android.content.pm.ConfigurationInfo;
15
import android.content.res.Resources;
16 c7238c67 Leszek Koltunski
import android.opengl.GLSurfaceView;
17
18
import org.distorted.library.effect.EffectType;
19 e3abaab9 Leszek Koltunski
import org.distorted.library.effect.VertexEffectQuaternion;
20
import org.distorted.library.effect.VertexEffectRotate;
21 c7238c67 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
22
import org.distorted.library.main.DistortedScreen;
23 e3abaab9 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
24
import org.distorted.objectlib.effects.BaseEffect;
25 c7238c67 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
26 e3abaab9 Leszek Koltunski
import org.distorted.overlays.OverlayGeneric;
27 c7238c67 Leszek Koltunski
28 d0ad3964 Leszek Koltunski
import java.io.InputStream;
29
30 c7238c67 Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
31
import javax.microedition.khronos.opengles.GL10;
32
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35 d0ad3964 Leszek Koltunski
public class PurchaseRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
36 c7238c67 Leszek Koltunski
{
37 7f9c3cce Leszek Koltunski
   private static final int NUM_SCRAMBLES = 5;
38 9e493af3 Leszek Koltunski
   private static final int DURATION = NUM_SCRAMBLES*2*1000;
39 7f9c3cce Leszek Koltunski
40 c7238c67 Leszek Koltunski
   private final PurchaseSurfaceView mView;
41 d0ad3964 Leszek Koltunski
   private final Resources mResources;
42 c7238c67 Leszek Koltunski
   private final DistortedScreen mScreen;
43
44 7f9c3cce Leszek Koltunski
   private boolean mFirstRender;
45
46 c7238c67 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
47
48
   PurchaseRenderer(PurchaseSurfaceView v)
49
     {
50
     final float BRIGHTNESS = 0.333f;
51
52
     mView = v;
53 d0ad3964 Leszek Koltunski
     mResources = v.getResources();
54
55
     mFirstRender = true;
56 c7238c67 Leszek Koltunski
     mScreen = new DistortedScreen();
57
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
58
     }
59
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62
   @Override
63
   public void onDrawFrame(GL10 glUnused)
64
     {
65
     long time = System.currentTimeMillis();
66
     mView.getObjectControl().preRender();
67
     mScreen.render(time);
68 7f9c3cce Leszek Koltunski
69
     if( mFirstRender )
70
       {
71
       mFirstRender=false;
72 de131f0a Leszek Koltunski
       mView.getObjectControl().presentObject(NUM_SCRAMBLES, DURATION);
73 7f9c3cce Leszek Koltunski
       }
74 c7238c67 Leszek Koltunski
     }
75
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
78
   @Override
79
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
80
      {
81
      mScreen.resize(width,height);
82
      mView.setScreenSize(width,height);
83
      }
84
85 d0ad3964 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
86
87
   DistortedScreen getScreen()
88
     {
89
     return mScreen;
90
     }
91
92 c7238c67 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
93
94
   @Override
95
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
96
      {
97 e3abaab9 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1);
98
      MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
99
100
      VertexEffectRotate.enable();
101
      VertexEffectQuaternion.enable();
102
      BaseEffect.Type.enableEffects();
103
      OverlayGeneric.enableEffects();
104 c7238c67 Leszek Koltunski
105 d0ad3964 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(this,1);
106 af0710b6 Leszek Koltunski
      DistortedLibrary.setCull(true);
107 c7238c67 Leszek Koltunski
      }
108
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
111
   public void distortedException(Exception ex)
112
     {
113 d0ad3964 Leszek Koltunski
     android.util.Log.e("Purchase", "unexpected exception: "+ex.getMessage() );
114 c7238c67 Leszek Koltunski
     }
115
116 d0ad3964 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118
   public InputStream localFile(int fileID)
119
      {
120
      return mResources.openRawResource(fileID);
121
      }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125
   public void logMessage(String message)
126
      {
127
      android.util.Log.e("Purchase", message );
128
      }
129 c7238c67 Leszek Koltunski
}