10000 Loading SVGs as viewport/texture · Issue #367 · pyimgui/pyimgui · GitHub
[go: up one dir, main page]

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

Loading SVGs as viewport/texture #367

Open
keriefie opened this issue Dec 17, 2023 · 2 comments
Open

Loading SVGs as viewport/texture #367

keriefie opened this issue Dec 17, 2023 · 2 comments

Comments

@keriefie
Copy link
keriefie commented Dec 17, 2023

Not sure if this is the best place to post this but I have been trying for the past hours to load SVG data (xml string) and render it in a viewport in PyImGui, but have not managed to do anything. I found an old thing with pyglet, and tried to use it to load it via a (manually updated) svgbatch. However it did not end up working, or I don't understand how to load the textures properly in PyImGui/OpenGL. Either way it seems like a silly way to do it, requiring svgbatch > pyglet > imgui, which is more libraries than I would like to use.

Is there some way to either directly load SVG shapes (or even just primitives) into PyImGui or some more efficient way to render it to an OpenGL texture?

svgtexture.py

import util.gsvgbatch as gsb
import pyglet
from pyglet.gl import *
from ctypes import byref


class SvgTexture:
    def __init__(self, string):
        self.batch = gsb.svg2batch(string)
        self.w = 800
        self.h = 800
        self.image = pyglet.image.create(self.w, self.h)
        self.texture = self.image.get_texture()
        self.fbo_id = GLuint(0)

        glGenFramebuffers(1, byref(self.fbo_id))
        glBindFramebuffer(GL_FRAMEBUFFER, self.fbo_id)

        glBindTexture(GL_TEXTURE_2D, self.texture.id)

        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self.texture.id, 0)

        self.batch.draw()

    def render(self):
        glBindFramebuffer(GL_FRAMEBUFFER, 0)
        self.texture.blit(0, 0)

main loop

            if show_viewport_area:
                window_flags = (imgui.WINDOW_NO_RESIZE |
                                imgui.WINDOW_NO_MOVE |
                                imgui.WINDOW_NO_COLLAPSE |
                                imgui.WINDOW_NO_TITLE_BAR |
                                imgui.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS)

                is_expand, show_glyph_area = (
                    imgui.begin("Viewport", False, flags=window_flags))
                if is_expand:
                    texture = svgtexture.SvgTexture(self.svg)
                    texture.render()
                    imgui.image(0, 80, 80)
                    # imgui.text("[image viewport goes here]")
                imgui.end()
@learn-more
Copy link
Collaborator

There is no builtin support for svg files in pyimgui.

@keriefie
Copy link
Author

There is no builtin support for svg files in pyimgui.

I was just curious if there were any tessellation libraries that work well with pyimgui. But if not I can do it myself.

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

No branches or pull requests

2 participants
0