Project

General

Profile

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

magiccube / src / main / java / org / distorted / purchase / PurchaseRenderer.java @ 7654a99d

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
import android.opengl.GLSurfaceView;
13
14
import org.distorted.library.effect.EffectType;
15 7654a99d Leszek Koltunski
import org.distorted.library.effect.PostprocessEffectGlow;
16 c7238c67 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
17
import org.distorted.library.main.DistortedScreen;
18
import org.distorted.objectlib.main.ObjectControl;
19 7654a99d Leszek Koltunski
import org.distorted.overlays.OverlayStars;
20 c7238c67 Leszek Koltunski
21
import javax.microedition.khronos.egl.EGLConfig;
22
import javax.microedition.khronos.opengles.GL10;
23
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
26
public class PurchaseRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
27
{
28 7f9c3cce Leszek Koltunski
   private static final int NUM_SCRAMBLES = 5;
29 9e493af3 Leszek Koltunski
   private static final int DURATION = NUM_SCRAMBLES*2*1000;
30 7f9c3cce Leszek Koltunski
31 c7238c67 Leszek Koltunski
   private final PurchaseSurfaceView mView;
32
   private final DistortedScreen mScreen;
33
34 7f9c3cce Leszek Koltunski
   private boolean mFirstRender;
35
36 c7238c67 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38
   PurchaseRenderer(PurchaseSurfaceView v)
39
     {
40
     final float BRIGHTNESS = 0.333f;
41
42 7f9c3cce Leszek Koltunski
     mFirstRender = true;
43 c7238c67 Leszek Koltunski
     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 7f9c3cce Leszek Koltunski
57
     if( mFirstRender )
58
       {
59
       mFirstRender=false;
60 de131f0a Leszek Koltunski
       mView.getObjectControl().presentObject(NUM_SCRAMBLES, DURATION);
61 7f9c3cce Leszek Koltunski
       }
62 c7238c67 Leszek Koltunski
     }
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 7654a99d Leszek Koltunski
      OverlayStars.enableEffects();
80
      PostprocessEffectGlow.enable();
81 c7238c67 Leszek Koltunski
82
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
83 af0710b6 Leszek Koltunski
      DistortedLibrary.setCull(true);
84 c7238c67 Leszek Koltunski
      }
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
}