# GLVisualize - Render dynamically created and destroyed particles

**URL:** <https://discourse.julialang.org/t/glvisualize-render-dynamically-created-and-destroyed-particles/11125>\
**Category:** Visualization\
**Tags:** glvisualize\
**Created:** [May 24, 2018, 11:35am UTC](https://discourse.julialang.org/t/glvisualize-render-dynamically-created-and-destroyed-particles/11125 "2018-05-24T11:35:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [May 24, 2018, 11:35am UTC](https://discourse.julialang.org/t/glvisualize-render-dynamically-created-and-destroyed-particles/11125/1 "2018-05-24T11:35:58Z")

</div>

Hi everyone,

I am looking for a way to realize the following situation with GLVisualize:

Given a dynamics under which “particles” are created and destroyed.  
Output is a vector of positions. I would like to visualize the particles as spheres in the plane.

The naive solution follows along the lines of

```julia
using GLVisualize, GLAbstraction, GeometryTypes, Reactive

window = glscreen();

timesignal = fps(1);

# Randomize up to 50 positions in the z=0 plane
positions = map(_->[Point3f0(rand(2)...,0) for _ in 1:rand(1:50)], timesignal)

robj = visualize((HyperSphere(Point3f0(0),0.1f0),positions))
_view(robj,window)

@async renderloop(window)

```

where `position` is obviously a mockup of a real dynamics.

This approach however won’t work, because

```julia
Failed to push!
    2.2109999656677246
to node
    42: "1 fps" = 2.2109999656677246 Float64 (active)

error at node: 66: "map(input-36, map(1 fps))" = nothing Void (active)
Dynamic resizing not implemented for GLAbstraction.TextureBuffer{GeometryTypes.Point{3,Float32}}
update!(::GLAbstraction.TextureBuffer{GeometryTypes.Point{3,Float32}}, ::Array{GeometryTypes.Point{3,Float32},1}) at C:\Users\stephan\.julia\v0.6\GLAbstraction\src\AbstractGPUArray.jl:81
(::Reactive.##33#34{GLAbstraction.#update!,Reactive.Signal{Void},Tuple{Reactive.Signal{GLAbstraction.TextureBuffer{GeometryTypes.Point{3,Float32}}},Reactive.Signal{Array{GeometryTypes.Point{3,Float32},1}}}})() at C:\Users\stephan\.julia\v0.6\Reactive\src\operators.jl:39
foreach(::Reactive.#runaction, ::Array{Function,1}) at .\abstractarray.jl:1733
run_node(::Reactive.Signal{Void}) at C:\Users\stephan\.julia\v0.6\Reactive\src\core.jl:312
run_push(::Reactive.Signal{Float64}, ::Float64, ::Reactive.#print_error, ::Bool) at C:\Users\stephan\.julia\v0.6\Reactive\src\core.jl:330
run_push(::Reactive.Signal{Float64}, ::Float64, ::Function) at C:\Users\stephan\.julia\v0.6\Reactive\src\core.jl:317
run(::Int64) at C:\Users\stephan\.julia\v0.6\Reactive\src\core.jl:277
(::Reactive.##27#29)() at .\task.jl:335

```

One could probably create a new render object for each position, but that seems like it’d waste a lot of performance. Or maybe not? I am not well-versed in neither OpenGL nor GLVisualize.

Is there a preferred way to do what I’m trying to achieve here?

Thanks in advance for your help!  
Stephan

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [May 25, 2018, 2:08pm UTC](https://discourse.julialang.org/t/glvisualize-render-dynamically-created-and-destroyed-particles/11125/2 "2018-05-25T14:08:01Z")

</div>

I posed the question on [Github too](https://github.com/JuliaGL/GLVisualize.jl/issues/255).

The gist is, that it’s (currently) not working with mesh objects. One may either

1. Use sprites instead of 3d objects, e.g `Circle(Point2f0(0),0.1f0)`. Won’t look as nice, but works out.
2. Initialize the render object with a large number `max_particles` and show only the ones that are “truly there”. For a simple implementation see the linked Github issue.
3. Delete and visualize the render object anew each time the particle number changes
