Project

General

Profile

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

examples / src / main / java / org / distorted / examples / scratchpad / ScratchpadRenderer.java @ 5068fa06

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

    
16
///////////////////////////////////////////////////////////////////////////////////////////////////
17

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

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

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

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

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