Project

General

Profile

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

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

1
package org.distorted.examples.scratchpad;
2

    
3
import javax.microedition.khronos.egl.EGLConfig;
4
import javax.microedition.khronos.opengles.GL10;
5

    
6
import android.graphics.Bitmap;
7
import android.graphics.Canvas;
8
import android.graphics.Paint;
9
import android.graphics.Paint.Style;
10
import android.opengl.GLES20;
11
import android.opengl.GLSurfaceView;
12

    
13
import org.distorted.library.DistortedBitmap;
14
import org.distorted.library.Distorted;
15
import org.distorted.library.EffectTypes;
16

    
17
///////////////////////////////////////////////////////////////////////////////////////////////////
18

    
19
public class ScratchpadRenderer implements GLSurfaceView.Renderer 
20
   {  
21
   public static final int NUMLINES = 10;
22
   public static final int BWID = 300;
23
   public static final int BHEI = 400;
24
   
25
   private GLSurfaceView mView;
26
   public static DistortedBitmap mBackground;
27
   private Paint mPaint;
28
   private int texWidth, texHeight;
29
    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
   public ScratchpadRenderer(GLSurfaceView v)
33
     {    
34
     mPaint = new Paint();
35
     mPaint.setAntiAlias(true);
36
     mPaint.setFakeBoldText(true);
37
     mPaint.setStyle(Style.FILL);
38
      
39
     mView = v;
40
      
41
     texWidth = BWID;
42
     texHeight= BHEI;
43
     }
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46
   
47
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
48
     {      
49
     mBackground = new DistortedBitmap(texWidth,texHeight, 80);
50
     Bitmap bitmap = Bitmap.createBitmap(texWidth,texHeight, Bitmap.Config.ARGB_8888);
51
     Canvas canvas = new Canvas(bitmap);  
52
      
53
     mPaint.setColor(0xff008800);
54
     canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
55
     mPaint.setColor(0xffffffff);
56
         
57
     for(int i=0; i<=NUMLINES ; i++ )
58
       {
59
       canvas.drawRect(texWidth*i/NUMLINES - 1,                       0,  texWidth*i/NUMLINES + 1,  texHeight               , mPaint);
60
       canvas.drawRect(                      0, texHeight*i/NUMLINES -1,  texWidth               ,  texHeight*i/NUMLINES + 1, mPaint);  
61
       }
62
          
63
     mBackground.setBitmap(bitmap);
64
          
65
     try
66
       {
67
       Distorted.onSurfaceCreated(mView.getContext());
68
       }
69
     catch(Exception ex)
70
       {
71
       android.util.Log.e("Scratchpad", ex.getMessage() );
72
       }
73
     }
74

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
78
     {
79
     mBackground.abortEffects(EffectTypes.MATRIX);
80
     mBackground.scale((float)width/texWidth,(float)height/texHeight,1);
81
     Distorted.onSurfaceChanged(width,height);
82
     ScratchpadSurfaceView.setScreenSize(width,height);     
83
     }
84
   
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
   
87
   public void onDrawFrame(GL10 glUnused)
88
     {   
89
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
90
     mBackground.draw(System.currentTimeMillis());
91
     }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
}
(2-2/3)