Revision 16b22aab
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/differentbitmaps/DifferentBitmapsRenderer.java | ||
---|---|---|
49 | 49 |
|
50 | 50 |
class DifferentBitmapsRenderer implements GLSurfaceView.Renderer |
51 | 51 |
{ |
52 |
private static final int NUM = 3; |
|
52 |
private static final int[] bitmap = { R.raw.dog, R.raw.face, R.raw.cat }; |
|
53 |
private static final int NUM = bitmap.length; |
|
53 | 54 |
|
54 | 55 |
private GLSurfaceView mView; |
55 | 56 |
private DistortedEffects[] mEffects; |
56 | 57 |
private DistortedTexture[] mTexture; |
57 | 58 |
private MeshFlat mMesh; |
58 | 59 |
private DistortedScreen mScreen; |
59 |
private int bmpHeight, bmpWidth; |
|
60 | 60 |
private Static3D mScale; |
61 | 61 |
private Static3D[] mMove; |
62 | 62 |
|
... | ... | |
101 | 101 |
mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); |
102 | 102 |
} |
103 | 103 |
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
private Bitmap readBitmap(int id) |
|
107 |
{ |
|
108 |
InputStream is = mView.getContext().getResources().openRawResource(id); |
|
109 |
Bitmap bitmap; |
|
110 |
|
|
111 |
try |
|
112 |
{ |
|
113 |
bitmap = BitmapFactory.decodeStream(is); |
|
114 |
} |
|
115 |
finally |
|
116 |
{ |
|
117 |
try |
|
118 |
{ |
|
119 |
is.close(); |
|
120 |
} |
|
121 |
catch(IOException e) { } |
|
122 |
} |
|
123 |
|
|
124 |
return bitmap; |
|
125 |
} |
|
126 |
|
|
127 | 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
128 | 105 |
|
129 | 106 |
public void onDrawFrame(GL10 glUnused) |
... | ... | |
135 | 112 |
|
136 | 113 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
137 | 114 |
{ |
138 |
if( (float)bmpHeight/(NUM*bmpWidth) > (float)height/width ) |
|
139 |
{ |
|
140 |
int w = (height*bmpWidth)/bmpHeight; |
|
141 |
float factor = (float)height/bmpHeight; |
|
142 |
mScale.set(factor,factor,factor); |
|
115 |
float horiRatio = (float)width / (NUM*mTexture[0].getWidth()); |
|
116 |
float vertRatio = (float)height/ ( mTexture[0].getHeight()); |
|
117 |
float factor = horiRatio > vertRatio ? vertRatio : horiRatio; |
|
143 | 118 |
|
144 |
for(int i=NUM-1; i>=0; i--) |
|
145 |
{ |
|
146 |
mMove[i].set((width-NUM*w)/2 +i*w ,0,0); |
|
147 |
} |
|
148 |
} |
|
149 |
else |
|
150 |
{ |
|
151 |
int w = width/NUM; |
|
152 |
int h = (width*bmpHeight)/(bmpWidth*NUM); |
|
153 |
float factor = (float)width/(bmpWidth*NUM); |
|
154 |
mScale.set(factor,factor,factor); |
|
155 |
|
|
156 |
for(int i=NUM-1; i>=0; i--) |
|
157 |
{ |
|
158 |
mMove[i].set(i*w,(height-h)/2,0); |
|
159 |
} |
|
160 |
} |
|
119 |
mScale.set( factor,factor,factor ); |
|
161 | 120 |
|
121 |
for(int i=NUM-1; i>=0; i--) mMove[i].set((i-(NUM-1)/2.0f)*(width/NUM), 0, 0); |
|
162 | 122 |
|
163 | 123 |
mScreen.resize(width, height); |
164 | 124 |
} |
... | ... | |
167 | 127 |
|
168 | 128 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
169 | 129 |
{ |
170 |
Bitmap bitmap0= readBitmap(R.raw.dog); |
|
171 |
Bitmap bitmap1= readBitmap(R.raw.face); |
|
172 |
Bitmap bitmap2= readBitmap(R.raw.cat); |
|
173 |
|
|
174 |
bmpHeight = bitmap0.getHeight(); |
|
175 |
bmpWidth = bitmap0.getWidth(); |
|
130 |
Bitmap[] bmp = new Bitmap[NUM]; |
|
131 |
|
|
132 |
for(int i=0; i<NUM; i++) |
|
133 |
{ |
|
134 |
bmp[i] = readBitmap(bitmap[i]); |
|
135 |
} |
|
136 |
|
|
137 |
int bmpHeight = bmp[0].getHeight(); |
|
138 |
int bmpWidth = bmp[0].getWidth(); |
|
176 | 139 |
|
177 | 140 |
if( mTexture==null ) |
178 | 141 |
{ |
... | ... | |
182 | 145 |
mTexture[i] = new DistortedTexture(bmpWidth,bmpHeight); |
183 | 146 |
} |
184 | 147 |
|
185 |
mTexture[0].setTexture(bitmap0); |
|
186 |
mTexture[1].setTexture(bitmap1); |
|
187 |
mTexture[2].setTexture(bitmap2); |
|
148 |
for(int i=0; i<NUM; i++) |
|
149 |
{ |
|
150 |
mTexture[i].setTexture(bmp[i]); |
|
151 |
} |
|
188 | 152 |
|
189 | 153 |
if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth); |
190 | 154 |
|
... | ... | |
203 | 167 |
android.util.Log.e("Renderer", ex.getMessage() ); |
204 | 168 |
} |
205 | 169 |
} |
170 |
|
|
171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
|
|
173 |
private Bitmap readBitmap(int id) |
|
174 |
{ |
|
175 |
InputStream is = mView.getContext().getResources().openRawResource(id); |
|
176 |
Bitmap bitmap; |
|
177 |
|
|
178 |
try |
|
179 |
{ |
|
180 |
bitmap = BitmapFactory.decodeStream(is); |
|
181 |
} |
|
182 |
finally |
|
183 |
{ |
|
184 |
try |
|
185 |
{ |
|
186 |
is.close(); |
|
187 |
} |
|
188 |
catch(IOException e) { } |
|
189 |
} |
|
190 |
|
|
191 |
return bitmap; |
|
192 |
} |
|
193 |
|
|
206 | 194 |
} |
Also available in: Unified diff
Fix several more apps for the 'center-of-matrix-effects-in-screen-center' change.