Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigRenderer.java @ 97a3a8eb

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.config;
21

    
22
import android.opengl.GLSurfaceView;
23

    
24
import org.distorted.library.effect.EffectType;
25
import org.distorted.library.effect.VertexEffectQuaternion;
26
import org.distorted.library.effect.VertexEffectRotate;
27
import org.distorted.library.main.DistortedLibrary;
28
import org.distorted.library.main.DistortedScreen;
29
import org.distorted.objectlib.effects.BaseEffect;
30

    
31
import javax.microedition.khronos.egl.EGLConfig;
32
import javax.microedition.khronos.opengles.GL10;
33

    
34
import static org.distorted.config.ConfigScreenPane.PADDING_RATIO;
35

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

    
38
public class ConfigRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
39
{
40
   private final ConfigSurfaceView mView;
41
   private final DistortedScreen mScreen;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
   ConfigRenderer(ConfigSurfaceView v)
46
     {
47
     final float BRIGHTNESS = 0.333f;
48

    
49
     mView = v;
50
     mScreen = new DistortedScreen();
51
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
52
     }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
   @Override
57
   public void onDrawFrame(GL10 glUnused)
58
     {
59
     long time = System.currentTimeMillis();
60
     mView.getObjectControl().preRender();
61
     mScreen.render(time);
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
      int debugWidth = (int)(0.2f*width);
73
      int debugHeight= (int)(0.5*debugWidth);
74
      int gap        = (int)(width*PADDING_RATIO);
75
      int textColor  = 0xffffffff;
76
      int backColor  = 0xff333333;
77

    
78
      mScreen.showFPS(debugWidth,debugHeight,gap,textColor,backColor);
79
      */
80
      }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
   @Override
85
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
86
      {
87
      DistortedLibrary.setMax(EffectType.VERTEX,61);    // 60 Minx quaternions + rotate
88
      VertexEffectRotate.enable();
89
      VertexEffectQuaternion.enable();
90
      BaseEffect.Type.enableEffects();
91

    
92
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
93
      }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

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

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

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