Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayRenderer.java @ a353dcee

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.bandaged;
11

    
12
import android.content.res.Resources;
13
import android.opengl.GLSurfaceView;
14

    
15
import org.distorted.library.effect.EffectType;
16
import org.distorted.library.effect.VertexEffectQuaternion;
17
import org.distorted.library.effect.VertexEffectRotate;
18
import org.distorted.library.main.DistortedLibrary;
19
import org.distorted.library.main.DistortedScreen;
20
import org.distorted.library.mesh.MeshBase;
21
import org.distorted.objectlib.effects.BaseEffect;
22
import org.distorted.objectlib.main.ObjectControl;
23

    
24
import java.io.InputStream;
25

    
26
import javax.microedition.khronos.egl.EGLConfig;
27
import javax.microedition.khronos.opengles.GL10;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class BandagedPlayRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
32
{
33
   private final BandagedPlayView mView;
34
   private final Resources mResources;
35
   private final DistortedScreen mScreen;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
   BandagedPlayRenderer(BandagedPlayView v)
40
     {
41
     final float BRIGHTNESS = 0.333f;
42

    
43
     mView = v;
44
     mResources = v.getResources();
45
     mScreen = new DistortedScreen();
46
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
47
     mScreen.showFPS();
48
     }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

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

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
   @Override
63
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
64
      {
65
      mScreen.resize(width,height);
66
      mView.setScreenSize(width,height);
67
      }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
   DistortedScreen getScreen()
72
     {
73
     return mScreen;
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

    
88
      DistortedLibrary.onSurfaceCreated(this,1);
89
      DistortedLibrary.setCull(true);
90
      }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

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

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
   public InputStream localFile(int fileID)
102
      {
103
      return mResources.openRawResource(fileID);
104
      }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
   public void logMessage(String message)
109
      {
110
      android.util.Log.e("BandagedPlay", message );
111
      }
112
}
(14-14/16)