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

Add OpenGL example #20

Open
gcardozo123 opened this issue Aug 17, 2019 · 3 comments
Open

Add OpenGL example #20

gcardozo123 opened this issue Aug 17, 2019 · 3 comments

Comments

@gcardozo123
Copy link

Hi,
first, thanks for mantaining Python bindings for ImGui!
I noticed this line on bimpy readme file:
bimpy already has all necessary functionality for window/OpenGL context creation and hides those details from the user.

But I can't find examples anywhere. It would be awesome to have a simple "OpenGL Bimpy hello world", maybe just a triangle that you can switch its color with a color picker.

I'm already trying to implement this, but my triangles are not being rendered. I suppose I should just put the rendering code inside bimpy context loop like this:

        while not ctx.should_close():

            ctx.new_frame()

            glClearColor(0.0, 0.0, 0.0, 1.0)
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, None)

            ctx.render()

I got no errors, just an empty window, although changing the color in glClearColor properly changes the window background color.

Any pointers are welcome.
Thanks!

@gcardozo123
Copy link
Author

gcardozo123 commented Aug 25, 2019

If anyone else comes accross this issue, I believe the problem is related to #18: bimpy does not allow the user to customize its initialization, for example, it sets the OpenGL and GLSL version by itself.

@podgorskiy
Copy link
Owner

There was no intention to expose OpenGL API to the user but hide all the window/OpenGL stuff from the user, that would make usage of ImGUI more straightforward from python. Issue #18 addresses a useful feature indeed, which I plan to implement.

I'm already trying to implement this, but my triangles are not being rendered.

That's because actual rendering happens only at a time of ctx.render(), which clears screen before rendering.

One way would be to allow passing function to ctx.render() that does some custom OpenGL rendering before ImGUI render.

Another way, would be to render to a texture and then present it as an Image with ImGUI.

All depends on particular use cases. What are you trying to do? Could you please give an example? My point is it might be more practical to extend draw commands of ImDrawList?

@gcardozo123
Copy link
Author

I was trying to use bimpy + OpenGL to study a little bit of computer graphics. But as you say bimpy hides "all the window/OpenGL stuff from the user", so I can't set the GLSL version, for example.
I know that some people might be interested in playing around with different graphics APIs and bimpy could be useful for that too. Maybe make overwritable methods so the user could manage window creation and graphics API himself/herself? I mean, if that's not against bimpy's philosophy.

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