Project

General

Profile

Download (5.55 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / effectqueue / EffectQueueRenderer.java @ 758303a3

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 758303a3 Leszek Koltunski
package org.distorted.examples.effectqueue;
21 427ab7bf Leszek Koltunski
22
import javax.microedition.khronos.egl.EGLConfig;
23
import javax.microedition.khronos.opengles.GL10;
24
25
import android.graphics.Bitmap;
26
import android.graphics.Canvas;
27
import android.graphics.Paint;
28
import android.graphics.Paint.Style;
29
import android.opengl.GLES20;
30
import android.opengl.GLSurfaceView;
31
32 5068fa06 Leszek Koltunski
import org.distorted.library.DistortedBitmap;
33
import org.distorted.library.Distorted;
34 c5a28eb8 Leszek Koltunski
import org.distorted.library.EffectNames;
35 95593730 Leszek Koltunski
import org.distorted.library.EffectTypes;
36 af225332 Leszek Koltunski
import org.distorted.library.message.EffectListener;
37
import org.distorted.library.message.EffectMessage;
38 7589635e Leszek Koltunski
import org.distorted.library.type.Static3D;
39 427ab7bf Leszek Koltunski
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
42 758303a3 Leszek Koltunski
public class EffectQueueRenderer implements GLSurfaceView.Renderer, EffectListener
43 bc0a685b Leszek Koltunski
  {  
44 3f07bedc Leszek Koltunski
  private static final int NUMLINES =  10;
45
  static final int BWID = 300;
46
  static final int BHEI = 400;
47 427ab7bf Leszek Koltunski
   
48 758303a3 Leszek Koltunski
  private EffectQueueSurfaceView mView;
49 bc0a685b Leszek Koltunski
  private Paint mPaint;
50
  private int texWidth, texHeight;
51 3f07bedc Leszek Koltunski
52
  DistortedBitmap mBackground;
53
54 427ab7bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56 758303a3 Leszek Koltunski
  EffectQueueRenderer(EffectQueueSurfaceView v)
57 bc0a685b Leszek Koltunski
    {    
58
    mPaint = new Paint();
59
    mPaint.setAntiAlias(true);
60
    mPaint.setFakeBoldText(true);
61
    mPaint.setStyle(Style.FILL);
62 427ab7bf Leszek Koltunski
      
63 bc0a685b Leszek Koltunski
    mView = v;
64 427ab7bf Leszek Koltunski
      
65 bc0a685b Leszek Koltunski
    texWidth = BWID;
66
    texHeight= BHEI;
67
    }
68 427ab7bf Leszek Koltunski
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70
   
71 bc0a685b Leszek Koltunski
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
72
    {      
73
    mBackground = new DistortedBitmap(texWidth,texHeight, 80);
74
    Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
75
    Canvas canvas = new Canvas(bitmap);  
76 427ab7bf Leszek Koltunski
      
77 bc0a685b Leszek Koltunski
    mPaint.setColor(0xff008800);
78
    canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
79
    mPaint.setColor(0xffffffff);
80 427ab7bf Leszek Koltunski
         
81 bc0a685b Leszek Koltunski
    for(int i=0; i<=NUMLINES ; i++ )
82
      {
83
      canvas.drawRect(texWidth*i/NUMLINES - 1,                       0,  texWidth*i/NUMLINES + 1,  texHeight               , mPaint);
84
      canvas.drawRect(                      0, texHeight*i/NUMLINES -1,  texWidth               ,  texHeight*i/NUMLINES + 1, mPaint);  
85
      }
86 427ab7bf Leszek Koltunski
          
87 bc0a685b Leszek Koltunski
    mBackground.setBitmap(bitmap);
88 af225332 Leszek Koltunski
    mBackground.addEventListener(this);
89
90 bc0a685b Leszek Koltunski
    try
91
      {
92
      Distorted.onSurfaceCreated(mView.getContext());
93
      }
94
    catch(Exception ex)
95
      {
96 bdfec906 Leszek Koltunski
      android.util.Log.e("Effects2D", ex.getMessage() );
97 bc0a685b Leszek Koltunski
      }
98
    }
99 427ab7bf Leszek Koltunski
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 bc0a685b Leszek Koltunski
  public void onSurfaceChanged(GL10 glUnused, int width, int height)
103
    {
104
    mBackground.abortEffects(EffectTypes.MATRIX);
105 7589635e Leszek Koltunski
    mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
106 bc0a685b Leszek Koltunski
    Distorted.onSurfaceChanged(width,height);
107 3f07bedc Leszek Koltunski
    mView.setScreenSize(width,height);
108 bc0a685b Leszek Koltunski
    }
109 427ab7bf Leszek Koltunski
   
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111
   
112 bc0a685b Leszek Koltunski
  public void onDrawFrame(GL10 glUnused)
113
    {   
114
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
115
    mBackground.draw(System.currentTimeMillis());
116
    }
117 af225332 Leszek Koltunski
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119 c5a28eb8 Leszek Koltunski
// the library sending messages to us. This is running on a library 'MessageSender' thread.
120 af225332 Leszek Koltunski
121 c5a28eb8 Leszek Koltunski
  public void effectMessage(final EffectMessage em, final long effectID, final EffectNames effectName, final long objectID, final String message)
122 af225332 Leszek Koltunski
    {
123 758303a3 Leszek Koltunski
    EffectQueueActivity act = (EffectQueueActivity)mView.getContext();
124 af225332 Leszek Koltunski
125
    switch(em)
126
      {
127
      case EFFECT_REMOVED : act.effectRemoved(effectID) ; break;
128
      case EFFECT_FINISHED: act.effectFinished(effectID); break;
129
      default             : break;
130
      }
131
    }
132 bc0a685b Leszek Koltunski
  }