Project

General

Profile

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

magiccube / src / main / java / org / distorted / purchase / PurchaseRenderer.java @ 7f9c3cce

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

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

    
34
   private boolean mFirstRender;
35

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

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

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

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

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

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

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

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

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

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

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

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

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