Revision 985ea9c5
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/library/DistortedBitmapGrid.java | ||
---|---|---|
68 | 68 |
position[3*vertex+2] = 0; |
69 | 69 |
|
70 | 70 |
texture[2*vertex ] = x; |
71 |
texture[2*vertex+1] = y; |
|
71 |
texture[2*vertex+1] = 1.0f-y;
|
|
72 | 72 |
|
73 | 73 |
normal[3*vertex ] = 0.0f; |
74 | 74 |
normal[3*vertex+1] = 0.0f; |
src/main/java/org/distorted/library/DistortedCubesGrid.java | ||
---|---|---|
36 | 36 |
private static final int EAST = 2; |
37 | 37 |
private static final int SOUTH = 3; |
38 | 38 |
|
39 |
private static final int NW = 0; |
|
40 |
private static final int NE = 1; |
|
41 |
private static final int SW = 2; |
|
42 |
private static final int SE = 3; |
|
43 |
|
|
44 | 39 |
private static final boolean BACK = true; |
45 | 40 |
private static final boolean FRONT = false; |
46 | 41 |
private static final boolean UPPER = false; |
... | ... | |
427 | 422 |
normal[3*vertex+1] = mNormalY[index]; |
428 | 423 |
normal[3*vertex+2] = mNormalZ[index]; |
429 | 424 |
texture[2*vertex ] = x; |
430 |
texture[2*vertex+1] = y; |
|
425 |
texture[2*vertex+1] = 1.0f-y;
|
|
431 | 426 |
|
432 | 427 |
return vertex+1; |
433 | 428 |
} |
... | ... | |
655 | 650 |
|
656 | 651 |
remainingVert--; |
657 | 652 |
|
658 |
float centerX = curr.col-(mCols-1.0f)/2.0f; |
|
659 |
float centerY = (mRows-1.0f)/2.0f-curr.row; |
|
660 |
|
|
653 |
float x, y; |
|
654 |
|
|
661 | 655 |
switch(curr.side) |
662 | 656 |
{ |
663 |
case NORTH: position[3*vertex ] = (back ? (centerX-0.5f) : (centerX+0.5f))/mCols; |
|
664 |
position[3*vertex+1] = (centerY+0.5f)/mRows; |
|
657 |
case NORTH: x = (float)(back ? (curr.col ):(curr.col+1))/mCols; |
|
658 |
|
|
659 |
position[3*vertex ] = x - 0.5f; |
|
660 |
position[3*vertex+1] = 0.5f - (float)curr.row/mRows; |
|
665 | 661 |
position[3*vertex+2] = lower ? BACKZ : FRONTZ; |
666 | 662 |
|
667 | 663 |
normal[3*vertex ] = side==NORTH ? 0.0f : (side==WEST?-R:R); |
668 | 664 |
normal[3*vertex+1] = 1.0f; |
669 | 665 |
normal[3*vertex+2] = lower ? -R:R; |
670 | 666 |
|
671 |
texture[2*vertex ] = (float)(back ? (curr.col ):(curr.col+1))/mCols;
|
|
672 |
texture[2*vertex+1] = (float)(lower? (curr.row-1):(curr.row ))/mRows;
|
|
667 |
texture[2*vertex ] = x;
|
|
668 |
texture[2*vertex+1] = 1.0f-(float)(lower? (curr.row-1):(curr.row ))/mRows;
|
|
673 | 669 |
break; |
674 |
case SOUTH: position[3*vertex ] = (back ? (centerX+0.5f) : (centerX-0.5f))/mCols; |
|
675 |
position[3*vertex+1] = (centerY-0.5f)/mRows; |
|
670 |
case SOUTH: x = (float)(back ? (curr.col+1):(curr.col ))/mCols; |
|
671 |
|
|
672 |
position[3*vertex ] = x - 0.5f; |
|
673 |
position[3*vertex+1] = 0.5f - (float)(curr.row+1)/mRows; |
|
676 | 674 |
position[3*vertex+2] = lower ? BACKZ : FRONTZ; |
677 | 675 |
|
678 | 676 |
normal[3*vertex ] = side==SOUTH ? 0.0f: (side==EAST?-R:R); |
679 | 677 |
normal[3*vertex+1] =-1.0f; |
680 | 678 |
normal[3*vertex+2] = lower ? -R:R; |
681 | 679 |
|
682 |
texture[2*vertex ] = (float)(back ? (curr.col+1):(curr.col ))/mCols;
|
|
683 |
texture[2*vertex+1] = (float)(lower? (curr.row+2):(curr.row+1))/mRows; |
|
680 |
texture[2*vertex ] = x;
|
|
681 |
texture[2*vertex+1] = 1.0f-(float)(lower? (curr.row+2):(curr.row+1))/mRows;
|
|
684 | 682 |
break; |
685 |
case WEST : position[3*vertex ] = (centerX-0.5f)/mCols; |
|
686 |
position[3*vertex+1] = (back ? (centerY-0.5f):(centerY+0.5f))/mRows; |
|
683 |
case WEST : y = (float)(back ? (curr.row+1):(curr.row))/mRows; |
|
684 |
|
|
685 |
position[3*vertex ] = (float)curr.col/mCols -0.5f; |
|
686 |
position[3*vertex+1] = 0.5f - y; |
|
687 | 687 |
position[3*vertex+2] = lower ? BACKZ : FRONTZ; |
688 | 688 |
|
689 | 689 |
normal[3*vertex ] =-1.0f; |
... | ... | |
691 | 691 |
normal[3*vertex+2] = lower ? -R:R; |
692 | 692 |
|
693 | 693 |
texture[2*vertex ] = (float)(lower ? (curr.col-1):(curr.col ))/mCols; |
694 |
texture[2*vertex+1] = (float)(back ? (curr.row+1):(curr.row ))/mRows;
|
|
694 |
texture[2*vertex+1] = 1.0f - y;
|
|
695 | 695 |
break; |
696 |
case EAST : position[3*vertex ] = (centerX+0.5f)/mCols; |
|
697 |
position[3*vertex+1] = (back ? (centerY+0.5f):(centerY-0.5f))/mRows; |
|
696 |
case EAST : y = (float)(back ? (curr.row):(curr.row+1))/mRows; |
|
697 |
|
|
698 |
position[3*vertex ] = (float)(curr.col+1)/mCols -0.5f; |
|
699 |
position[3*vertex+1] = 0.5f - y; |
|
698 | 700 |
position[3*vertex+2] = lower ? BACKZ : FRONTZ; |
699 | 701 |
|
700 | 702 |
normal[3*vertex ] = 1.0f; |
... | ... | |
702 | 704 |
normal[3*vertex+2] = lower ? -R:R; |
703 | 705 |
|
704 | 706 |
texture[2*vertex ] = (float)(lower ? (curr.col+2):(curr.col+1))/mCols; |
705 |
texture[2*vertex+1] = (float)(back ? (curr.row ):(curr.row+1))/mRows;
|
|
707 |
texture[2*vertex+1] = 1.0f - y;
|
|
706 | 708 |
break; |
707 | 709 |
} |
708 | 710 |
|
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'