Project

General

Profile

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

examples / src / main / java / org / distorted / examples / scratchpad / ScratchpadRenderer.java @ bc0a685b

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 5068fa06 Leszek Koltunski
package org.distorted.examples.scratchpad;
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 95593730 Leszek Koltunski
import org.distorted.library.EffectTypes;
35 427ab7bf Leszek Koltunski
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38
public class ScratchpadRenderer implements GLSurfaceView.Renderer 
39 bc0a685b Leszek Koltunski
  {  
40
  public static final int NUMLINES = 10;
41
  public static final int BWID = 300;
42
  public static final int BHEI = 400;
43 427ab7bf Leszek Koltunski
   
44 bc0a685b Leszek Koltunski
  private GLSurfaceView mView;
45
  public static DistortedBitmap mBackground;
46
  private Paint mPaint;
47
  private int texWidth, texHeight;
48 427ab7bf Leszek Koltunski
    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
51 bc0a685b Leszek Koltunski
  public ScratchpadRenderer(GLSurfaceView v)
52
    {    
53
    mPaint = new Paint();
54
    mPaint.setAntiAlias(true);
55
    mPaint.setFakeBoldText(true);
56
    mPaint.setStyle(Style.FILL);
57 427ab7bf Leszek Koltunski
      
58 bc0a685b Leszek Koltunski
    mView = v;
59 427ab7bf Leszek Koltunski
      
60 bc0a685b Leszek Koltunski
    texWidth = BWID;
61
    texHeight= BHEI;
62
    }
63 427ab7bf Leszek Koltunski
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65
   
66 bc0a685b Leszek Koltunski
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
67
    {      
68
    mBackground = new DistortedBitmap(texWidth,texHeight, 80);
69
    Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
70
    Canvas canvas = new Canvas(bitmap);  
71 427ab7bf Leszek Koltunski
      
72 bc0a685b Leszek Koltunski
    mPaint.setColor(0xff008800);
73
    canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
74
    mPaint.setColor(0xffffffff);
75 427ab7bf Leszek Koltunski
         
76 bc0a685b Leszek Koltunski
    for(int i=0; i<=NUMLINES ; i++ )
77
      {
78
      canvas.drawRect(texWidth*i/NUMLINES - 1,                       0,  texWidth*i/NUMLINES + 1,  texHeight               , mPaint);
79
      canvas.drawRect(                      0, texHeight*i/NUMLINES -1,  texWidth               ,  texHeight*i/NUMLINES + 1, mPaint);  
80
      }
81 427ab7bf Leszek Koltunski
          
82 bc0a685b Leszek Koltunski
    mBackground.setBitmap(bitmap);
83 427ab7bf Leszek Koltunski
          
84 bc0a685b Leszek Koltunski
    try
85
      {
86
      Distorted.onSurfaceCreated(mView.getContext());
87
      }
88
    catch(Exception ex)
89
      {
90
      android.util.Log.e("Scratchpad", ex.getMessage() );
91
      }
92
    }
93 427ab7bf Leszek Koltunski
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95
96 bc0a685b Leszek Koltunski
  public void onSurfaceChanged(GL10 glUnused, int width, int height)
97
    {
98
    mBackground.abortEffects(EffectTypes.MATRIX);
99
    mBackground.scale((float)width/texWidth,(float)height/texHeight,1);
100
    Distorted.onSurfaceChanged(width,height);
101
    ScratchpadSurfaceView.setScreenSize(width,height);     
102
    }
103 427ab7bf Leszek Koltunski
   
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
   
106 bc0a685b Leszek Koltunski
  public void onDrawFrame(GL10 glUnused)
107
    {   
108
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
109
    mBackground.draw(System.currentTimeMillis());
110
    }
111
  }