Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialRenderer.java @ 78478d7e

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.content.res.Resources;
16
import android.opengl.GLSurfaceView;
17

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

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

    
28
import java.io.InputStream;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
33
{
34
   private final TutorialSurfaceView mView;
35
   private final DistortedScreen mScreen;
36
   private final Resources mResources;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
   TutorialRenderer(TutorialSurfaceView v)
41
     {
42
     mView = v;
43
     mResources = v.getResources();
44
     mScreen = new DistortedScreen();
45

    
46
     TutorialActivity act = (TutorialActivity)v.getContext();
47
     act.setUpBackgroundColor(mScreen);
48
     }
49

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

    
52
   DistortedScreen getScreen()
53
     {
54
     return mScreen;
55
     }
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
   @Override
60
   public void onDrawFrame(GL10 glUnused)
61
     {
62
     long time = System.currentTimeMillis();
63
     mView.getObjectControl().preRender();
64
     mScreen.render(time);
65
     }
66

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

    
69
   @Override
70
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
71
      {
72
      mScreen.resize(width,height);
73
      mView.setScreenSize(width,height);
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("Tutorial", "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("Tutorial", message );
111
     }
112
}
(3-3/6)