Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialRenderer.java @ 2cf21fdc

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.tutorials;
11

    
12
import javax.microedition.khronos.egl.EGLConfig;
13
import javax.microedition.khronos.opengles.GL10;
14

    
15
import android.opengl.GLSurfaceView;
16

    
17
import org.distorted.library.effect.EffectType;
18
import org.distorted.library.effect.VertexEffectQuaternion;
19
import org.distorted.library.effect.VertexEffectRotate;
20
import org.distorted.library.main.DistortedLibrary;
21
import org.distorted.library.main.DistortedScreen;
22

    
23
import org.distorted.library.mesh.MeshBase;
24
import org.distorted.objectlib.effects.BaseEffect;
25
import org.distorted.objectlib.main.ObjectControl;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
30
{
31
   private final TutorialSurfaceView mView;
32
   private final DistortedScreen mScreen;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
   TutorialRenderer(TutorialSurfaceView v)
37
     {
38
     final float BRIGHTNESS = 0.30f;
39

    
40
     mView = v;
41
     mScreen = new DistortedScreen();
42
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
43
     }
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

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

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
   @Override
58
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
59
      {
60
      mScreen.resize(width,height);
61
      mView.setScreenSize(width,height);
62
      }
63

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

    
66
   @Override
67
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
68
      {
69
      DistortedLibrary.setMax(EffectType.VERTEX, ObjectControl.MAX_QUATS+1);
70
      MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
71

    
72
      VertexEffectRotate.enable();
73
      VertexEffectQuaternion.enable();
74
      BaseEffect.Type.enableEffects();
75

    
76
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
77
      DistortedLibrary.setCull(true);
78
      }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
   public void distortedException(Exception ex)
83
     {
84
     android.util.Log.e("TUTORIAL", "unexpected exception: "+ex.getMessage() );
85
     }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
   DistortedScreen getScreen()
90
     {
91
     return mScreen;
92
     }
93
}
(3-3/6)