Project

General

Profile

« Previous | Next » 

Revision bc0a685b

Added by Leszek Koltunski almost 8 years ago

Add License

View differences:

src/main/java/org/distorted/examples/scratchpad/ScratchpadRenderer.java
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

  
1 20
package org.distorted.examples.scratchpad;
2 21

  
3 22
import javax.microedition.khronos.egl.EGLConfig;
......
17 36
///////////////////////////////////////////////////////////////////////////////////////////////////
18 37

  
19 38
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;
39
  {  
40
  public static final int NUMLINES = 10;
41
  public static final int BWID = 300;
42
  public static final int BHEI = 400;
24 43
   
25
   private GLSurfaceView mView;
26
   public static DistortedBitmap mBackground;
27
   private Paint mPaint;
28
   private int texWidth, texHeight;
44
  private GLSurfaceView mView;
45
  public static DistortedBitmap mBackground;
46
  private Paint mPaint;
47
  private int texWidth, texHeight;
29 48
    
30 49
///////////////////////////////////////////////////////////////////////////////////////////////////
31 50

  
32
   public ScratchpadRenderer(GLSurfaceView v)
33
     {    
34
     mPaint = new Paint();
35
     mPaint.setAntiAlias(true);
36
     mPaint.setFakeBoldText(true);
37
     mPaint.setStyle(Style.FILL);
51
  public ScratchpadRenderer(GLSurfaceView v)
52
    {    
53
    mPaint = new Paint();
54
    mPaint.setAntiAlias(true);
55
    mPaint.setFakeBoldText(true);
56
    mPaint.setStyle(Style.FILL);
38 57
      
39
     mView = v;
58
    mView = v;
40 59
      
41
     texWidth = BWID;
42
     texHeight= BHEI;
43
     }
60
    texWidth = BWID;
61
    texHeight= BHEI;
62
    }
44 63

  
45 64
///////////////////////////////////////////////////////////////////////////////////////////////////
46 65
   
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);  
66
  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);  
52 71
      
53
     mPaint.setColor(0xff008800);
54
     canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
55
     mPaint.setColor(0xffffffff);
72
    mPaint.setColor(0xff008800);
73
    canvas.drawRect(0, 0, texWidth, texHeight, mPaint);
74
    mPaint.setColor(0xffffffff);
56 75
         
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
       }
76
    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
      }
62 81
          
63
     mBackground.setBitmap(bitmap);
82
    mBackground.setBitmap(bitmap);
64 83
          
65
     try
66
       {
67
       Distorted.onSurfaceCreated(mView.getContext());
68
       }
69
     catch(Exception ex)
70
       {
71
       android.util.Log.e("Scratchpad", ex.getMessage() );
72
       }
73
     }
84
    try
85
      {
86
      Distorted.onSurfaceCreated(mView.getContext());
87
      }
88
    catch(Exception ex)
89
      {
90
      android.util.Log.e("Scratchpad", ex.getMessage() );
91
      }
92
    }
74 93

  
75 94
///////////////////////////////////////////////////////////////////////////////////////////////////
76 95

  
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
     }
96
  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
    }
84 103
   
85 104
///////////////////////////////////////////////////////////////////////////////////////////////////
86 105
   
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
}
106
  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
  }

Also available in: Unified diff