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.app.ActivityManager;
|
16
|
import android.content.Context;
|
17
|
import android.content.pm.ConfigurationInfo;
|
18
|
import android.content.res.Resources;
|
19
|
import android.opengl.GLSurfaceView;
|
20
|
|
21
|
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
|
import org.distorted.library.main.DistortedScreen;
|
26
|
|
27
|
import org.distorted.library.mesh.MeshBase;
|
28
|
import org.distorted.objectlib.effects.BaseEffect;
|
29
|
import org.distorted.objectlib.main.ObjectControl;
|
30
|
|
31
|
import java.io.InputStream;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
|
36
|
{
|
37
|
private final TutorialSurfaceView mView;
|
38
|
private final DistortedScreen mScreen;
|
39
|
private final Resources mResources;
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
TutorialRenderer(TutorialSurfaceView v)
|
44
|
{
|
45
|
final float BRIGHTNESS = 0.30f;
|
46
|
|
47
|
mView = v;
|
48
|
mResources = v.getResources();
|
49
|
mScreen = new DistortedScreen();
|
50
|
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
|
51
|
}
|
52
|
|
53
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
|
55
|
DistortedScreen getScreen()
|
56
|
{
|
57
|
return mScreen;
|
58
|
}
|
59
|
|
60
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
61
|
|
62
|
@Override
|
63
|
public void onDrawFrame(GL10 glUnused)
|
64
|
{
|
65
|
long time = System.currentTimeMillis();
|
66
|
mView.getObjectControl().preRender();
|
67
|
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
|
DistortedLibrary.setMax(EffectType.VERTEX, ObjectControl.MAX_QUATS+1);
|
85
|
MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
|
86
|
|
87
|
VertexEffectRotate.enable();
|
88
|
VertexEffectQuaternion.enable();
|
89
|
BaseEffect.Type.enableEffects();
|
90
|
|
91
|
DistortedLibrary.onSurfaceCreated(this,1);
|
92
|
DistortedLibrary.setCull(true);
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
|
97
|
public void distortedException(Exception ex)
|
98
|
{
|
99
|
android.util.Log.e("Tutorial", "unexpected exception: "+ex.getMessage() );
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
}
|
115
|
}
|