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

Is there a way to use the gr framework with CImGui.jl? #37

Closed
yadmtr opened this issue Jan 22, 2021 · 2 comments
Closed

Is there a way to use the gr framework with CImGui.jl? #37

yadmtr opened this issue Jan 22, 2021 · 2 comments

Comments

@yadmtr
Copy link

yadmtr commented Jan 22, 2021

Is there a way to use the gr framework (or GRUtils) with CImGui.jl ?

@yadmtr yadmtr changed the title Is there a way to use the gr framework with CImGui.jl Is there a way to use the gr framework with CImGui.jl? Jan 22, 2021
@Gnimuc
Copy link
Owner

Gnimuc commented Jan 23, 2021

If you're talking about how to use GR as a backend for CImGui.jl, then it is possible as long as GR exposes its OpenGL context and a callback function for hacking into its rendering loop. You might also be interested in the following post:
https://discourse.julialang.org/t/is-it-possible-to-use-makie-in-cimgui/45844/2

@yadmtr
Copy link
Author

yadmtr commented Jan 24, 2021

Thanks this post was what I needed.

using GRUtils
using Printf

ENV["GKS_WSTYPE"] = "100" # off-screen rendering
y  =  rand(1001)
img_width, img_height = 400, 400
image = rand(GLuint, 4, img_width, img_height) # allocate the memory 
GRUtils.colorscheme("LIGHT")
fg = GRUtils.plot( y) 
str_pointer = Printf.@sprintf("%p",pointer(image))
filename = Printf.@sprintf("!%dx%d@%s.mem",  img_width, img_height,str_pointer[3:end])
GC.@preserve image savefig(filename, fg) #  write an image directly to memory as 32-bit RGBA
...
# creat texture for image drawing
image_id = ImGui_ImplOpenGL3_CreateImageTexture(img_width, img_height)
# show image
CImGui.Begin("Image Demo")
ImGui_ImplOpenGL3_UpdateImageTexture(image_id, image, img_width, img_height)
CImGui.Image(Ptr{Cvoid}(image_id), (img_width, img_height))
CImGui.End()
...

Снимок экрана 2021-01-24 142405

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