Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialRenderer.java @ ab19c113

1 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 bb62ca3f Leszek Koltunski
// 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 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10 eaf87d1d Leszek Koltunski
package org.distorted.tutorials;
11 af88bf2e Leszek Koltunski
12 3f7a4363 Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
13
import javax.microedition.khronos.opengles.GL10;
14
15 d0ad3964 Leszek Koltunski
import android.app.ActivityManager;
16
import android.content.Context;
17
import android.content.pm.ConfigurationInfo;
18
import android.content.res.Resources;
19 af88bf2e Leszek Koltunski
import android.opengl.GLSurfaceView;
20
21 b6468abb Leszek Koltunski
import org.distorted.library.effect.EffectType;
22
import org.distorted.library.effect.VertexEffectQuaternion;
23
import org.distorted.library.effect.VertexEffectRotate;
24
import org.distorted.library.main.DistortedLibrary;
25 af88bf2e Leszek Koltunski
import org.distorted.library.main.DistortedScreen;
26
27 34bc9f31 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
28 d2556e79 Leszek Koltunski
import org.distorted.objectlib.effects.BaseEffect;
29 34bc9f31 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
30 af88bf2e Leszek Koltunski
31 d0ad3964 Leszek Koltunski
import java.io.InputStream;
32
33 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35 d0ad3964 Leszek Koltunski
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
36 af88bf2e Leszek Koltunski
{
37 40a26c6c Leszek Koltunski
   private final TutorialSurfaceView mView;
38
   private final DistortedScreen mScreen;
39 d0ad3964 Leszek Koltunski
   private final Resources mResources;
40 af88bf2e Leszek Koltunski
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43
   TutorialRenderer(TutorialSurfaceView v)
44
     {
45
     final float BRIGHTNESS = 0.30f;
46
47
     mView = v;
48 d0ad3964 Leszek Koltunski
     mResources = v.getResources();
49 af88bf2e Leszek Koltunski
     mScreen = new DistortedScreen();
50
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
51
     }
52
53 d0ad3964 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
54
55
   DistortedScreen getScreen()
56
     {
57
     return mScreen;
58
     }
59
60 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62
   @Override
63
   public void onDrawFrame(GL10 glUnused)
64
     {
65
     long time = System.currentTimeMillis();
66 2afc6754 Leszek Koltunski
     mView.getObjectControl().preRender();
67 af88bf2e Leszek Koltunski
     mScreen.render(time);
68
     }
69
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
72
   @Override
73
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
74
      {
75
      mScreen.resize(width,height);
76
      mView.setScreenSize(width,height);
77
      }
78
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
81
   @Override
82
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
83
      {
84 34bc9f31 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX, ObjectControl.MAX_QUATS+1);
85
      MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
86
87 b6468abb Leszek Koltunski
      VertexEffectRotate.enable();
88
      VertexEffectQuaternion.enable();
89
      BaseEffect.Type.enableEffects();
90 af88bf2e Leszek Koltunski
91 d0ad3964 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(this,1);
92 6dff7924 Leszek Koltunski
      DistortedLibrary.setCull(true);
93 af88bf2e Leszek Koltunski
      }
94
95 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
96
97
   public void distortedException(Exception ex)
98
     {
99 d0ad3964 Leszek Koltunski
     android.util.Log.e("Tutorial", "unexpected exception: "+ex.getMessage() );
100 b6468abb Leszek Koltunski
     }
101
102 d0ad3964 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
103
104
   public InputStream localFile(int fileID)
105
     {
106
     return mResources.openRawResource(fileID);
107
     }
108
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
111
   public void logMessage(String message)
112
     {
113
     android.util.Log.e("Tutorial", message );
114 af88bf2e Leszek Koltunski
     }
115
}