Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialRenderer.java @ 7fe59aa5

1 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 eaf87d1d Leszek Koltunski
package org.distorted.tutorials;
21 af88bf2e Leszek Koltunski
22 3f7a4363 Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
23
import javax.microedition.khronos.opengles.GL10;
24
25 af88bf2e Leszek Koltunski
import android.opengl.GLSurfaceView;
26
27 b6468abb Leszek Koltunski
import org.distorted.library.effect.EffectType;
28
import org.distorted.library.effect.VertexEffectQuaternion;
29
import org.distorted.library.effect.VertexEffectRotate;
30
import org.distorted.library.main.DistortedLibrary;
31 af88bf2e Leszek Koltunski
import org.distorted.library.main.DistortedScreen;
32
33 34bc9f31 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
34 d2556e79 Leszek Koltunski
import org.distorted.objectlib.effects.BaseEffect;
35 34bc9f31 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
36 af88bf2e Leszek Koltunski
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
39 b6468abb Leszek Koltunski
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
40 af88bf2e Leszek Koltunski
{
41 40a26c6c Leszek Koltunski
   private final TutorialSurfaceView mView;
42
   private final DistortedScreen mScreen;
43 af88bf2e Leszek Koltunski
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46
   TutorialRenderer(TutorialSurfaceView v)
47
     {
48
     final float BRIGHTNESS = 0.30f;
49
50
     mView = v;
51
     mScreen = new DistortedScreen();
52
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
53
     }
54
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
57
   @Override
58
   public void onDrawFrame(GL10 glUnused)
59
     {
60
     long time = System.currentTimeMillis();
61 2afc6754 Leszek Koltunski
     mView.getObjectControl().preRender();
62 af88bf2e Leszek Koltunski
     mScreen.render(time);
63
     }
64
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
67
   @Override
68
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
69
      {
70
      mScreen.resize(width,height);
71
      mView.setScreenSize(width,height);
72
      }
73
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
76
   @Override
77
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
78
      {
79 34bc9f31 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX, ObjectControl.MAX_QUATS+1);
80
      MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS);
81
82 b6468abb Leszek Koltunski
      VertexEffectRotate.enable();
83
      VertexEffectQuaternion.enable();
84
      BaseEffect.Type.enableEffects();
85 af88bf2e Leszek Koltunski
86 d7de3072 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
87 6dff7924 Leszek Koltunski
      DistortedLibrary.setCull(true);
88 af88bf2e Leszek Koltunski
      }
89
90 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92
   public void distortedException(Exception ex)
93
     {
94
     android.util.Log.e("TUTORIAL", "unexpected exception: "+ex.getMessage() );
95
     }
96
97 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
   DistortedScreen getScreen()
100
     {
101
     return mScreen;
102
     }
103
}