Skip to content

Commit 3d3e042

Browse files
committed
Gl point renderer, debugging-attempts
1 parent 55b72c7 commit 3d3e042

7 files changed

Lines changed: 469 additions & 14 deletions

File tree

examples/liquidfun_ParticleRenderGroups_LiquidFx/liquidfun_ParticleRenderGroups_LiquidFx.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void setup(){
9595
pg_checkerboard = DwUtils.createCheckerBoard(this, width, height, 100, color(32, 0), color(48,0));
9696
// pg_checkerboard = DwUtils.createCheckerBoard(this, width, height, 100, color(200, 0), color(255,0));
9797
reset();
98-
frameRate(1000);
98+
frameRate(120);
9999
}
100100

101101

@@ -397,8 +397,8 @@ public void initScene() {
397397

398398
screen_x = width/4;
399399
screen_y = height/2;
400-
// world.mouse_spawn_particles.setBoxShape(500, 20);
401-
// world.mouse_spawn_particles.spawn(screen_x, screen_y);
400+
world.mouse_spawn_particles.setBoxShape(500, 20);
401+
world.mouse_spawn_particles.spawn(screen_x, screen_y);
402402

403403
setParticleSpawnProperties(spawn_type_cpy);
404404

examples/liquidfun_ParticleRenderGroups_LiquidFxDark/liquidfun_ParticleRenderGroups_LiquidFxDark.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void setup(){
9595
pg_checkerboard = DwUtils.createCheckerBoard(this, width, height, 100, color(32, 0), color(48,0));
9696
// pg_checkerboard = DwUtils.createCheckerBoard(this, width, height, 100, color(200, 0), color(255,0));
9797
reset();
98-
frameRate(1000);
98+
frameRate(120);
9999
}
100100

101101

@@ -127,6 +127,7 @@ public void reset(){
127127

128128

129129
// box2d/liquidfun world
130+
// world.INIT_GL_PARTICLES = false;
130131
world = new DwWorld(this, 15);
131132

132133
// particle render settings
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
*
3+
* LiquidFunProcessing | Copyright 2017 Thomas Diewald - www.thomasdiewald.com
4+
*
5+
* https://github.com/diwi/LiquidFunProcessing.git
6+
*
7+
* Box2d / LiquidFun Library for Processing.
8+
* MIT License: https://opensource.org/licenses/MIT
9+
*
10+
*/
11+
12+
13+
14+
#version 150
15+
16+
out vec4 fragColor;
17+
in vec4 tint;
18+
19+
uniform sampler2D tex_sprite;
20+
21+
void main() {
22+
fragColor = texture(tex_sprite, gl_PointCoord) * tint;
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
*
3+
* LiquidFunProcessing | Copyright 2017 Thomas Diewald - www.thomasdiewald.com
4+
*
5+
* https://github.com/diwi/LiquidFunProcessing.git
6+
*
7+
* Box2d / LiquidFun Library for Processing.
8+
* MIT License: https://opensource.org/licenses/MIT
9+
*
10+
*/
11+
12+
13+
14+
#version 150
15+
16+
uniform mat4 mat_mvp;
17+
18+
in vec2 pos;
19+
in vec4 col;
20+
21+
out vec4 tint;
22+
23+
void main() {
24+
gl_Position = mat_mvp * vec4(pos, 0, 1);
25+
tint = col;
26+
}

src/com/thomasdiewald/liquidfun/java/DwWorld.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class DwWorld extends World{
7070
public DwViewportTransform transform;
7171

7272
/**
73-
* if true, particles is an instance of {@link DwParticleRenderGL}
73+
* if true, particles is an instance of {@link DwParticleRenderGLQuads}
7474
* otheriwse {@link DwParticleRenderP5} is instantiated.
7575
*/
7676
static public boolean INIT_GL_PARTICLES = true;

src/com/thomasdiewald/liquidfun/java/render/DwParticleRenderGL.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.jbox2d.dynamics.World;
2020
import com.jogamp.opengl.GL;
2121
import com.jogamp.opengl.GL2ES1;
22+
import com.jogamp.opengl.GL2ES3;
2223
import com.jogamp.opengl.GL3;
2324
import com.thomasdiewald.liquidfun.java.DwViewportTransform;
2425

@@ -45,7 +46,7 @@ public class DwParticleRenderGL extends DwParticleRender{
4546
static public final String SHADER_DIR = "/com/thomasdiewald/liquidfun/glsl/";
4647

4748
// GL
48-
protected GL3 gl;
49+
protected GL2ES3 gl;
4950
protected PJOGL pgl;
5051

5152
// Shader
@@ -71,13 +72,15 @@ public class DwParticleRenderGL extends DwParticleRender{
7172
, "#version 150 " + NL
7273
, " " + NL
7374
, "uniform mat4 mat_mvp; " + NL
75+
, "uniform float point_size; " + NL
7476
, " " + NL
7577
, "in vec2 pos; " + NL
7678
, "in vec4 col; " + NL
7779
, "out vec4 tint; " + NL
7880
, " " + NL
7981
, "void main() { " + NL
8082
, " gl_Position = mat_mvp * vec4(pos, 0, 1); " + NL
83+
, " gl_PointSize = point_size; " + NL
8184
, " tint = col; " + NL
8285
, "} " + NL
8386
};
@@ -201,6 +204,8 @@ public void display(PGraphics2D canvas){
201204

202205
shader.set("mat_mvp", mat_mvp);
203206
shader.set("tex_sprite", param.tex_sprite);
207+
shader.set("point_size", particle_rad_screen * 2);
208+
204209
errCheck("DwParticleRenderGL.display-uniforms");
205210

206211
// shader vertex attribute: position
@@ -238,18 +243,22 @@ public void display(PGraphics2D canvas){
238243
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
239244
errCheck("DwParticleRenderGL.display-buffers");
240245

241-
246+
247+
242248
// settings
243-
// gl.glEnable(GL.GL_MULTISAMPLE );
249+
// https://github.com/diwi/LiquidFunProcessing/issues/2
244250
// gl.glEnable(GL2.GL_POINT_SMOOTH);
251+
// gl.glEnable(GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
252+
// gl.glPointSize(particle_rad_screen * 2);
253+
254+
// ... f***ing OpenGL mess
245255
gl.glEnable(GL3.GL_PROGRAM_POINT_SIZE);
246-
gl.glEnable(GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
247256
gl.glEnable(GL2ES1.GL_POINT_SPRITE);
248-
gl.glPointSize(particle_rad_screen * 2);
257+
249258
errCheck("DwParticleRenderGL.display-pointRendering");
250259

251260

252-
261+
253262
// draw particles as points (see fragment shader for details)
254263
if(USE_GROUPS)
255264
{
@@ -263,13 +272,13 @@ public void display(PGraphics2D canvas){
263272
}
264273
int off = group_offsets[id];
265274
int len = group_lengths[id];
266-
gl.glDrawElements(GL3.GL_POINTS, len, GL.GL_UNSIGNED_INT, off * 4);
275+
gl.glDrawElements(GL.GL_POINTS, len, GL.GL_UNSIGNED_INT, off * 4);
267276
}
268277
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
269278
errCheck("DwParticleRenderGL.display-glDrawElements");
270279
}
271280
else {
272-
gl.glDrawArrays(GL3.GL_POINTS, 0, particle_num);
281+
gl.glDrawArrays(GL.GL_POINTS, 0, particle_num);
273282
errCheck("DwParticleRenderGL.display-glDrawArrays");
274283
}
275284

@@ -292,7 +301,7 @@ public void display(PGraphics2D canvas){
292301
protected void beginGL(){
293302
if(gl == null){
294303
pgl = (PJOGL) papplet.beginPGL();
295-
gl = pgl.gl.getGL3();
304+
gl = pgl.gl.getGL2ES3();
296305
}
297306
}
298307

0 commit comments

Comments
 (0)