Revision 392e16fd
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/projection/ProjectionRenderer.java | ||
---|---|---|
23 | 23 |
import javax.microedition.khronos.opengles.GL10; |
24 | 24 |
|
25 | 25 |
import org.distorted.library.Distorted; |
26 |
import org.distorted.library.DistortedFramebuffer; |
|
26 | 27 |
import org.distorted.library.GridFlat; |
27 | 28 |
import org.distorted.library.DistortedTexture; |
28 | 29 |
import org.distorted.library.DistortedEffectQueues; |
... | ... | |
42 | 43 |
{ |
43 | 44 |
private GLSurfaceView mView; |
44 | 45 |
private DistortedTexture mTexture; |
45 |
private DistortedEffectQueues mQueues; |
|
46 |
private DistortedEffectQueues mEffects; |
|
47 |
private DistortedFramebuffer mScreen; |
|
46 | 48 |
private GridFlat mGrid; |
47 | 49 |
|
48 |
private static float mF, mX, mY;
|
|
49 |
private static int mWidth, mHeight;
|
|
50 |
private float mF, mX, mY; |
|
51 |
private int mWidth, mHeight; |
|
50 | 52 |
|
51 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
52 | 54 |
|
53 | 55 |
ProjectionRenderer(GLSurfaceView view) |
54 | 56 |
{ |
55 |
mView = view; |
|
56 |
mQueues = new DistortedEffectQueues(); |
|
57 |
mView = view; |
|
58 |
mEffects= new DistortedEffectQueues(); |
|
59 |
mScreen = new DistortedFramebuffer(0); |
|
57 | 60 |
} |
58 | 61 |
|
59 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
60 | 63 |
|
61 |
static int setFOV(int f)
|
|
64 |
int setFOV(int f) |
|
62 | 65 |
{ |
63 | 66 |
mF = f; |
64 |
Distorted.setProjection(mF,mX,mY);
|
|
67 |
mScreen.setProjection(mF,mX,mY);
|
|
65 | 68 |
return (int)mF; |
66 | 69 |
} |
67 | 70 |
|
68 | 71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
69 | 72 |
|
70 |
static int setX(int x)
|
|
73 |
int setX(int x) |
|
71 | 74 |
{ |
72 | 75 |
mX = (x-50)*0.02f*mWidth; |
73 |
Distorted.setProjection(mF,mX,mY);
|
|
76 |
mScreen.setProjection(mF,mX,mY);
|
|
74 | 77 |
return (int)mX; |
75 | 78 |
} |
76 | 79 |
|
77 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
78 | 81 |
|
79 |
static int setY(int y)
|
|
82 |
int setY(int y) |
|
80 | 83 |
{ |
81 | 84 |
mY = (y-50)*0.02f*mHeight; |
82 |
Distorted.setProjection(mF,mX,mY);
|
|
85 |
mScreen.setProjection(mF,mX,mY);
|
|
83 | 86 |
return (int)mY; |
84 | 87 |
} |
85 | 88 |
|
... | ... | |
88 | 91 |
public void onDrawFrame(GL10 glUnused) |
89 | 92 |
{ |
90 | 93 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
91 |
mQueues.draw(System.currentTimeMillis(), mTexture,mGrid);
|
|
94 |
mEffects.draw(System.currentTimeMillis(), mTexture,mGrid,mScreen);
|
|
92 | 95 |
} |
93 | 96 |
|
94 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
98 | 101 |
mWidth = width; |
99 | 102 |
mHeight= height; |
100 | 103 |
|
101 |
Distorted.setProjection(mF,mX,mY);
|
|
102 |
mQueues.abortAllEffects();
|
|
104 |
mScreen.setProjection(mF,mX,mY);
|
|
105 |
mEffects.abortAllEffects();
|
|
103 | 106 |
|
104 | 107 |
Paint paint = new Paint(); |
105 | 108 |
mTexture = new DistortedTexture(width,height); |
... | ... | |
127 | 130 |
Static3D vector = new Static3D(0,0,min/5); |
128 | 131 |
Static4D region = new Static4D(0,0,min/5,min/5); |
129 | 132 |
|
130 |
mQueues.distort(vector, new Static3D( width/4, height/4, 0), region);
|
|
131 |
mQueues.distort(vector, new Static3D(3*width/4, height/4, 0), region);
|
|
132 |
mQueues.distort(vector, new Static3D( width/4, 3*height/4, 0), region);
|
|
133 |
mQueues.distort(vector, new Static3D(3*width/4, 3*height/4, 0), region);
|
|
133 |
mEffects.distort(vector, new Static3D( width/4, height/4, 0), region);
|
|
134 |
mEffects.distort(vector, new Static3D(3*width/4, height/4, 0), region);
|
|
135 |
mEffects.distort(vector, new Static3D( width/4, 3*height/4, 0), region);
|
|
136 |
mEffects.distort(vector, new Static3D(3*width/4, 3*height/4, 0), region);
|
|
134 | 137 |
|
135 |
Distorted.onSurfaceChanged(width, height);
|
|
138 |
mScreen.resize(width, height);
|
|
136 | 139 |
} |
137 | 140 |
|
138 | 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Change in the API: we always have to create a DistortedFramebuffer to render to.