Project

General

Profile

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

examples / src / main / java / org / distorted / examples / effects2d / Effects2DRenderer.java @ e5424523

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.examples.effects2d;
21

    
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
import org.distorted.library.DistortedBitmap;
33
import org.distorted.library.Distorted;
34
import org.distorted.library.EffectTypes;
35
import org.distorted.library.type.Static3D;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
public class Effects2DRenderer implements GLSurfaceView.Renderer
40
  {  
41
  public static final int NUMLINES = 10;
42
  public static final int BWID = 300;
43
  public static final int BHEI = 400;
44
   
45
  private GLSurfaceView mView;
46
  public static DistortedBitmap mBackground;
47
  private Paint mPaint;
48
  private int texWidth, texHeight;
49
    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  public Effects2DRenderer(GLSurfaceView v)
53
    {    
54
    mPaint = new Paint();
55
    mPaint.setAntiAlias(true);
56
    mPaint.setFakeBoldText(true);
57
    mPaint.setStyle(Style.FILL);
58
      
59
    mView = v;
60
      
61
    texWidth = BWID;
62
    texHeight= BHEI;
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
   
67
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
68
    {      
69
    mBackground = new DistortedBitmap(texWidth,texHeight, 80);
70
    Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
71
    Canvas canvas = new Canvas(bitmap);  
72
      
73
    mPaint.setColor(0xff008800);
74
    canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
75
    mPaint.setColor(0xffffffff);
76
         
77
    for(int i=0; i<=NUMLINES ; i++ )
78
      {
79
      canvas.drawRect(texWidth*i/NUMLINES - 1,                       0,  texWidth*i/NUMLINES + 1,  texHeight               , mPaint);
80
      canvas.drawRect(                      0, texHeight*i/NUMLINES -1,  texWidth               ,  texHeight*i/NUMLINES + 1, mPaint);  
81
      }
82
          
83
    mBackground.setBitmap(bitmap);
84
          
85
    try
86
      {
87
      Distorted.onSurfaceCreated(mView.getContext());
88
      }
89
    catch(Exception ex)
90
      {
91
      android.util.Log.e("Scratchpad", ex.getMessage() );
92
      }
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  public void onSurfaceChanged(GL10 glUnused, int width, int height)
98
    {
99
    mBackground.abortEffects(EffectTypes.MATRIX);
100
    mBackground.scale( new Static3D((float)width/texWidth,(float)height/texHeight,1) );
101
    Distorted.onSurfaceChanged(width,height);
102
    Effects2DSurfaceView.setScreenSize(width,height);
103
    }
104
   
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
   
107
  public void onDrawFrame(GL10 glUnused)
108
    {   
109
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
110
    mBackground.draw(System.currentTimeMillis());
111
    }
112
  }
(2-2/3)