Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 11f6235

Browse files
committed
syphon output works on 2.1.1 and 0255, as well as camera/projection
setting to render dome. Added SyphonOuptut example
1 parent 19892f3 commit 11f6235

File tree

4 files changed

+117
-15
lines changed

4 files changed

+117
-15
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
/bin
77
/bin
88
/bin
9+
/bin
10+
/bin
11+
/bin
12+
/bin
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Example showing how to use the syphon library to export frames
2+
// to a Syphon client.
3+
4+
import codeanticode.planetarium.*;
5+
import codeanticode.syphon.*;
6+
7+
SyphonServer server;
8+
float cubeX, cubeY, cubeZ;
9+
10+
void setup() {
11+
// For the time being, only use square windows
12+
size(600, 600, Dome.RENDERER);
13+
14+
server = new SyphonServer(this, "Planetarium server");
15+
}
16+
17+
// Called one time per frame.
18+
void pre() {
19+
// The dome projection is centered at (0, 0), so the mouse coordinates
20+
// need to be offset by (width/2, height/2)
21+
cubeX += ((mouseX - width * 0.5) - cubeX) * 0.2;
22+
cubeY += ((mouseY - height * 0.5) - cubeY) * 0.2;
23+
}
24+
25+
// Called five times per frame.
26+
void draw() {
27+
background(0);
28+
29+
pushMatrix();
30+
translate(width/2, height/2, 300);
31+
32+
lights();
33+
34+
stroke(0);
35+
fill(150);
36+
pushMatrix();
37+
translate(cubeX, cubeY, cubeZ);
38+
box(50);
39+
popMatrix();
40+
41+
stroke(255);
42+
int linesAmount = 10;
43+
for (int i = 0; i < linesAmount;i++) {
44+
float ratio = (float)i/(linesAmount-1);
45+
line(0, 0, cos(ratio*TWO_PI) * 50, sin(ratio*TWO_PI) * 50);
46+
}
47+
popMatrix();
48+
}
49+
50+
// This function is called after the dome has been rendererd, so
51+
// it will send the final image out through syphon
52+
void screen() {
53+
server.sendImage(g);
54+
}
55+
56+
void keyPressed() {
57+
if (key == CODED) {
58+
if (keyCode == UP) cubeZ -= 5;
59+
else if (keyCode == DOWN) cubeZ += 5;
60+
}
61+
}

src/codeanticode/planetarium/Dome.java

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,20 @@ public class Dome extends PGraphics3D {
6868
protected boolean requestedRenderDomeChange = false;
6969
protected boolean requestedRenderDome;
7070

71+
protected float domeLeft, domeRight, domeTop, domeBottom;
7172
protected float domeDX, domeDY, domeDZ;
7273
protected float domeScale = 1;
7374

74-
protected Method borderMethod;
75+
protected Method borderMethod;
76+
protected Method screenMethod;
7577

7678
/**
7779
* The default constructor.
7880
*
7981
*/
8082
public Dome() {
8183
super();
82-
welcome();
84+
welcome();
8385
}
8486

8587

@@ -109,6 +111,11 @@ public void setParent(PApplet parent) {
109111
borderMethod = parent.getClass().getMethod("border", new Class[] {});
110112
} catch (Exception e) {
111113
}
114+
115+
try {
116+
screenMethod = parent.getClass().getMethod("screen", new Class[] {});
117+
} catch (Exception e) {
118+
}
112119
}
113120

114121

@@ -128,6 +135,10 @@ public void setSize(int iwidth, int iheight) {
128135
resolution = iwidth;
129136
offsetX = offsetY = 0;
130137
}
138+
domeLeft = 0;
139+
domeRight = iwidth;
140+
domeBottom = 0;
141+
domeTop = iheight;
131142
super.setSize(iwidth, iheight);
132143
}
133144

@@ -204,14 +215,18 @@ public void beginDraw() {
204215
}
205216
requestedRenderDomeChange = false;
206217
}
207-
218+
208219
if (renderDome && 0 < parent.frameCount) {
209220
if (!cubeMapInit) {
210221
initDome();
211222
}
212-
223+
213224
beginPGL();
214-
225+
226+
pgl.activeTexture(PGL.TEXTURE1);
227+
pgl.enable(PGL.TEXTURE_CUBE_MAP);
228+
pgl.bindTexture(PGL.TEXTURE_CUBE_MAP, cubeMapTex.get(0));
229+
215230
// bind fbo
216231
pgl.bindFramebuffer(PGL.FRAMEBUFFER, cubeMapFbo.get(0));
217232

@@ -230,19 +245,29 @@ public void endDraw() {
230245
// Draw the rest of the cubemap faces
231246
for (int face = PGL.TEXTURE_CUBE_MAP_NEGATIVE_X;
232247
face <= PGL.TEXTURE_CUBE_MAP_POSITIVE_Z; face++) {
233-
beginFaceDraw(face);
248+
beginFaceDraw(face);
234249
parent.draw();
235250
endFaceDraw();
236251
}
237-
252+
238253
endPGL();
239-
240254
renderDome();
241-
}
255+
pgl.disable(PGL.TEXTURE_CUBE_MAP);
256+
pgl.bindTexture(PGL.TEXTURE_CUBE_MAP, 0);
257+
258+
}
242259
super.endDraw();
243260
}
244261

245262

263+
protected void setOrthoParams(float left, float right, float bottom, float top) {
264+
domeLeft = left;
265+
domeRight = right;
266+
domeBottom = bottom;
267+
domeTop = top;
268+
}
269+
270+
246271
protected void setOrigin(float dx, float dy, float dz) {
247272
domeDX = dx;
248273
domeDY = dy;
@@ -334,10 +359,6 @@ private void initDome() {
334359
// Attach depth buffer to FBO
335360
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT,
336361
PGL.RENDERBUFFER, cubeMapRbo.get(0));
337-
338-
pgl.enable(PGL.TEXTURE_CUBE_MAP);
339-
pgl.activeTexture(PGL.TEXTURE1);
340-
pgl.bindTexture(PGL.TEXTURE_CUBE_MAP, cubeMapTex.get(0));
341362

342363
endPGL();
343364

@@ -383,8 +404,8 @@ private void endFaceDraw() {
383404

384405
private void renderDome() {
385406
renderBorder();
386-
camera(0, 0, resolution * 0.5f + domeDZ, 0, 0, 0, 0, 1, 0);
387-
ortho(-width/2, width/2, -height/2, height/2);
407+
camera();
408+
ortho(domeLeft, domeRight, domeBottom, domeTop);
388409
resetMatrix();
389410
translate(domeDX, domeDY, domeDZ);
390411
scale(domeScale);
@@ -395,6 +416,7 @@ private void renderDome() {
395416
shape(domeSphere);
396417
resetShader();
397418
}
419+
renderScreen();
398420
}
399421

400422

@@ -408,6 +430,16 @@ private void renderBorder() {
408430
}
409431
}
410432

433+
private void renderScreen() {
434+
if (screenMethod != null) {
435+
try {
436+
screenMethod.invoke(parent, new Object[] {});
437+
} catch (Exception e) {
438+
e.printStackTrace();
439+
}
440+
}
441+
}
442+
411443

412444
private static int nextPowerOfTwo(int val) {
413445
int ret = 1;

src/codeanticode/planetarium/DomeCamera.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public void disable() {
2121
renderer.domeRendering(false);
2222
}
2323

24+
public void ortho(float left, float right,
25+
float bottom, float top) {
26+
renderer.setOrthoParams(left, right, bottom, top);
27+
}
28+
2429
public void translate(float tx, float ty, float tz) {
2530
renderer.setOrigin(tx, ty, tz);
2631
}

0 commit comments

Comments
 (0)