Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialRenderer.java @ 3f7a4363

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 3f7a4363 Leszek Koltunski
import org.distorted.effects.BaseEffect;
34 af88bf2e Leszek Koltunski
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37 b6468abb Leszek Koltunski
public class TutorialRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
38 af88bf2e Leszek Koltunski
{
39 40a26c6c Leszek Koltunski
   private final TutorialSurfaceView mView;
40
   private final DistortedScreen mScreen;
41 af88bf2e Leszek Koltunski
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44
   TutorialRenderer(TutorialSurfaceView v)
45
     {
46
     final float BRIGHTNESS = 0.30f;
47
48
     mView = v;
49
     mScreen = new DistortedScreen();
50
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
51
     }
52
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
55
   @Override
56
   public void onDrawFrame(GL10 glUnused)
57
     {
58
     long time = System.currentTimeMillis();
59
     mView.getPreRender().preRender();
60
     mScreen.render(time);
61
     }
62
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
65
   @Override
66
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
67
      {
68
      mScreen.resize(width,height);
69
      mView.setScreenSize(width,height);
70
      mView.getPreRender().setScreenSize(width);
71
      }
72
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
75
   @Override
76
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
77
      {
78 c0460c5c Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX,61);    // 60 Minx quaternions + rotate
79 b6468abb Leszek Koltunski
      VertexEffectRotate.enable();
80
      VertexEffectQuaternion.enable();
81
      BaseEffect.Type.enableEffects();
82 af88bf2e Leszek Koltunski
83 d7de3072 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
84 af88bf2e Leszek Koltunski
      }
85
86 b6468abb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
87
88
   public void distortedException(Exception ex)
89
     {
90
     android.util.Log.e("TUTORIAL", "unexpected exception: "+ex.getMessage() );
91
     }
92
93 af88bf2e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
94
95
   DistortedScreen getScreen()
96
     {
97
     return mScreen;
98
     }
99
}