Revision 985ea9c5
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/DistortedObject.java | ||
---|---|---|
20 | 20 |
package org.distorted.library; |
21 | 21 |
|
22 | 22 |
import android.graphics.Bitmap; |
23 |
import android.graphics.Matrix; |
|
23 | 24 |
import android.opengl.GLES20; |
24 | 25 |
import android.opengl.GLUtils; |
25 | 26 |
|
... | ... | |
52 | 53 |
int[] mTextureDataH; // have to be shared among all the cloned Objects |
53 | 54 |
boolean[] mBitmapSet; // |
54 | 55 |
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
// We have to flip vertically every single Bitmap that we get fed with. |
|
58 |
// |
|
59 |
// Reason: textures read from files are the only objects in OpenGL which have their origins at the |
|
60 |
// upper-left corner. Everywhere else the origin is in the lower-left corner. Thus we have to flip. |
|
61 |
// The alternative solution, namely inverting the y-coordinate of the TexCoord does not really work- |
|
62 |
// i.e. it works only in case of rendering directly to the screen, but if we render to an FBO and |
|
63 |
// then take the FBO and render to screen, (DistortedNode does so!) things get inverted as textures |
|
64 |
// created from FBO have their origins in the lower-left... Mindfuck! |
|
65 |
|
|
66 |
private static Bitmap flipBitmap(Bitmap src) |
|
67 |
{ |
|
68 |
Matrix matrix = new Matrix(); |
|
69 |
matrix.preScale(1.0f,-1.0f); |
|
70 |
|
|
71 |
return Bitmap.createBitmap(src,0,0,src.getWidth(),src.getHeight(), matrix,true); |
|
72 |
} |
|
73 |
|
|
55 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 75 |
|
57 | 76 |
protected abstract DistortedObject deepCopy(int flags); |
... | ... | |
129 | 148 |
|
130 | 149 |
if( mBmp!=null && mBmp[0]!=null) |
131 | 150 |
{ |
132 |
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, mBmp[0], 0);
|
|
151 |
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(mBmp[0]), 0);
|
|
133 | 152 |
mBmp[0] = null; |
134 | 153 |
} |
135 | 154 |
} |
... | ... | |
286 | 305 |
{ |
287 | 306 |
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); |
288 | 307 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataH[0]); |
289 |
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);
|
|
308 |
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, flipBitmap(bmp), 0);
|
|
290 | 309 |
} |
291 | 310 |
else |
292 | 311 |
{ |
Also available in: Unified diff
Finally fix the 'when rendering though an FBO, the other side of triangles is visible'