Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dynamically update a texture? #90

Open
nathanielvirgo opened this issue Apr 2, 2018 · 2 comments
Open

How to dynamically update a texture? #90

nathanielvirgo opened this issue Apr 2, 2018 · 2 comments

Comments

@nathanielvirgo
Copy link

I'm not sure if this is the place to post "how do I..." type questions, but I wasn't able to find any kind of user forum, so please point me onwards if I'm in the wrong place.

I'm hoping I can use this package for the relatively simple task of displaying a simple 2D grid-based simulation in real time as it updates. I'd like to use OpenGL for this because then the display won't slow it down too much and I can easily zoom and pan around etc. To do this, I need to either dynamically update a texture, or create a new one each frame.

Starting with the tutorial at https://github.com/JuliaGL/GLAbstraction.jl/blob/master/tutorials/textures1.jl, I tried creating a new Texture object and calling std_renderobject again on each iteration. This works, but it seems quite slow, and makes me wonder if this is the right way to do it. However, I was unable to find any documentation suggesting whether these objects can be dynamically updated without creating new ones every time.

My apologies if this is a dumb question. I'm not at all an OpenGL expert, and would greatly appreciate a simple explanation or even just an example of the best way to dynamically update a texture (from a cpu-based Julia array), if that can be done in this package.

@SimonDanisch
Copy link
Member

You should be able to use GLAbstraction.update!(tex, newdata), or even tex[:, :] = newdata. Let me know if it works!

@nathanielvirgo
Copy link
Author

Great, the first option works, and is fast.

The second one fails with this message:

ERROR: LoadError: Indexing only defined for integers or ranges. Found: Colon()
Stacktrace:
[1] (::GLAbstraction.##1#2)(::Colon) at /Users/ndv/.julia/v0.6/GLAbstraction/src/AbstractGPUArray.jl:52
[2] setindex!(::GLAbstraction.Texture{ColorTypes.RGBA{FixedPointNumbers.Normed{UInt8,8}},2}, ::Array{ColorTypes.RGBA{FixedPointNumbers.Normed{UInt8,8}},2}, ::Colon, ::Colon) at /Users/ndv/.julia/v0.6/GLAbstraction/src/AbstractGPUArray.jl:58
[3] macro expansion at /Users/ndv/Dropbox/Code/Julia GL testing/test04.jl:53 [inlined]
[4] anonymous at ./:?
[5] include_from_node1(::String) at ./loading.jl:576
[6] include(::String) at ./sysimg.jl:14
[7] process_options(::Base.JLOptions) at ./client.jl:305
[8] _start() at ./client.jl:371
while loading /Users/ndv/Dropbox/Code/Julia GL testing/test04.jl, in expression starting on line 46

(Let me know if you need the code I'm running. But I'm happy now, since I have a method that works!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants