podgorskiy / bimpy

imgui for python
https://podgorskiy.github.io/bimpy/
MIT License
202 stars 33 forks source link

Add OpenGL example #20

Open gcardozo123 opened 5 years ago

gcardozo123 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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.