-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
ImDrawList callback with custom shader #4174
Comments
At this point you’d understand that your question is an OpenGL question and not much of a Dear ImGui question. If they are other OpenGL states you rely on or not rely on you should set them. You can use glGetError() and shader compilation reports to try to track on what is wrong in your code, perhaps the shaders haven’t been built or linked correctly. OpenGL is a tricky mess in general but I am afraid there’s not much we can do here unfortunately. When you resolve it maybe posting the answer can be useful to others! |
That's the thing, I don't rely on anything that changes the OpenGL state or anything. This is just like a small test program I've built with the code I provided. I tried running After everything that I've tested I really have no clue on what is wrong. All I do is literally change the active shader for another with the same code... I was hoping maybe you guys could give me some insight in what could be the issue here. Anyways, if I found out a fix for this, I will let you all know in case it is useful to anyone :) |
Have you tried using a graphics debugger like RenderDoc?
|
I'm on macOS now and sadly RenderDoc doesn't work on this platform. I will try using it tomorrow on Linux. Thanks for the tip :D |
Your shaders and example code are working for me on Windows: (My square is red because I modified the shader to remove the blue channel just to show it's definitely being used.) The only code I wrote was the shader compilation since you didn't show that. Here's my full modified |
Did you check if there's any shader compilation errors printed to the terminal? One thing that stands out to me is that the default vertex shader used by the OpenGL3 backend does not explicitly specify the locations of the vertex attributes. (Presumably because specifying the location was added in newer versions of GLSL.) I assumed they'd have the same locations, but I wonder if this means the shader compiler is free to arrange them however it pleases. It might be worth comparing the values of |
Yep, there are no errors on the terminal. I runned your code on Linux and it works no problem.
Indeed, on macOS I've got 1, 2 and 0 for the position, UV and color locations but my shader expects them to be 0, 1 and 2 respectively. When I change the attribute locations, this is what I get (finally!): Thank you so much! From here it should be easy to fix this :D |
No problem, glad I could help! Since it sounds like you're targeting OpenGL 3.3 anyway, you might look into increasing the version you pass to (I'm not sure why it's == 300. It's been like that since it was introduced in #1941. The 410 check was changed from == to >= for #2329, maybe the same would be appropriate for == 300? Likewise, it's labeled as OpenGL ES, but I think that's only because it was originally introduced to add OpenGL ES support.) |
OSX has specific constraint with OpenGL. The OSX path of example always use 3.2 Core with Forward Compat. |
It uses 3.2 Core, but it uses the GLSL version string |
Version/Branch of Dear ImGui:
Version: 1.84 WIP (commit 04fd507)
Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: AppleClang
Operating System: macOS
My Issue/Question:
I'm trying to implement some custom rendering on top of ImGui. I tried using
ImDrawList::AddCallback()
to add a callback to a function that only changes the active shader. For some reason, I can't get anything to render there. However, when I remove the line that does theglUseProgram()
so that it uses the default shader, then it renders properly. My shader does compile OK and it is indeed the same one the OpenGL3 backend uses, but for some reason I can't get it to work.With the example I provide, one would expect a window called "FX", with size 1000x600 and a pink rectangle inside it. And this is exactly what I get when I disable my shader and instead rely on the default one, but when I use my shader the window is completely empty.
I know this is probably a dumb mistake by my side, but I've tried everything and I can't get it to work, and it should since the shader source is identical (I literally copied & pasted it). I shouldn't get an empty window with either shader.
Standalone, minimal, complete and verifiable example:
Vertex Shader source
Fragment Shader source
ImGui rendering code
The text was updated successfully, but these errors were encountered: