Closed NaNraptor closed 2 years ago
After installing nvidia-utils-510
and nvidia-driver-510
on my ubuntu and rebooting the code above works without issue however:
print(glGetString(GL_VENDOR), glGetString(GL_RENDERER))
Shows b'Intel' b'Mesa Intel(R) Graphics (ADL-S GT1)'
which is weird since the application still uses the intel igpu but now works without problem... I will investigate and post my finding here, then close the issue as resolved since this seems to be an issue with drivers on linux
EDIT: I actually just realised that the code does NOT work as expected as I only see a blank red screen instead of the stuff i put in the VBO and EBO
As an additional question - how does one force the glfw window to use a certain GPU on linux? On windows one can export NvOptimusEnablement
but what about linux?
EDIT: Okay so if using proprietary NVIDIA drivers with a GPU that supports ON-DEMAND rendering one needs :
for Vulkan offloading you have to use the following env variable:
__NV_PRIME_RENDER_OFFLOAD=1
For OpenGL apps, you have to use these variables:
__NV_PRIME_RENDER_OFFLOAD=1
__GLX_VENDOR_LIBRARY_NAME=nvidia
taken from: https://askubuntu.com/questions/1201072/how-nvidia-on-demand-option-works-in-nvidia-x-server-settings
So this now correctly uses my nvidia gpu and doesnt crash due to a context error, but after a few seconds of flickering the application closes with a core-dumped. Any idea what is going wrong?
With the intel igpu selected it does not crash with core dumped but instead just shows the blank red screen instead of the things that I have instructed it to draw.
Could that be a pyOpenGL issue? or a driver one? Im currently not sure
This might actually be problem with pyGLFW or glfw since I only get Aborted on a user action such as mouse move or keyboard press
I doubt that it is a pyGLFW issue, as this package is simply a wrapper around the GLFW library.
Can you enable pyOpenGL error reporting or put print(glGetError())
at the end of the loop, to see if an error gets reported? Your code looks alright, though perhaps you might need to call glBindFragDataLocation
to ensure the fragment output is actually used, I don't know how relaxed or strict nvidia drivers on Linux are for that. Though that would only explain the flickering, not the crash.
Also, do you have a traceback of the crash?
No traceback just a message saying Aborted (core dumped)
Putting print(glGetError())
at the end of the loop prints a lot of 0
again, until I either move the mouse or press a button, after I do that I again get met with an immediate Aborted (core dumped)
no other error messages whatsoever
If I run it without specifying __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia
then I only see a red window but no crash
For completeness sake here are my specs: Specs: intel i9-12900k (with igpu) running mesa igpu drivers Nvidia RTX 3080-ti with Nvidia 510 proprietary drivers Linux 21.10 with the 16.14 kernel
If I run it without specifying
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia
then I only see a red window but no crash
Try binding a fragment output location with glBindFragDataLocation
to see if that's why you don't see the orange square.
Since Im new to this just want to confirm do I call it like so:
...
glBindFragDataLocation(shader_program, 0, "FragColor")
while not glfw.window_should_close(window):
...
or do I pass in frag_shader
instead?
That looks correct.
If the way I have it at the moment is correct then I see no change at all
That looks correct.
No change at all still just a red screen
Also I just want to thank you for all the help you are providing which might not even directly relate to pyglfw. You rock! :)
Just simply running this:
import glfw
from OpenGL.GL import *
glfw.init()
glfw.window_hint(glfw.FOCUSED, glfw.FALSE)
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_COMPAT_PROFILE)
window = glfw.create_window(640, 400, "Window", None, None)
glfw.make_context_current(window)
glClearColor(1, 0, 0, 1)
print(glGetString(GL_VENDOR), glGetString(GL_RENDERER))
while not glfw.window_should_close(window):
glClear(GL_COLOR_BUFFER_BIT)
glfw.swap_buffers(window)
glfw.poll_events()
glfw.terminate()
works absolutely fine when ran using my nvidia gpu. So I assume the opengl code I have must be breaking something, although I have no idea what.
EDIT: by work I mean, it shows a red screen instead of black and does not abort with a core dump
Please replace glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0)
with glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, None)
, explanation will follow if that works :)
It works
I cannot BELIEVE I spent nearly 8h on this
Yet again @FlorianRhiem is a god among men and I have no idea what we did to deserve him. Thank you!
Welcome to the wonderful world of debugging stupid little OpenGL typos that take ages to find. :)
So, glDrawElements
expects as last parameter "a pointer to the location where the indices are stored". In practice, instead of an passing a pointer to an array of indices, you probably want to use a buffer for that, just like you did, but pyOpenGL has to support both use cases. So ctypes.c_void_p(0)
is clearly a pointer to an int, and can be passed to OpenGL as such. None
can be seen as indicating a null pointer, basically, but 0
needs conversion in some way. And I think in this case the code in pyOpenGL created an array containing the 0, then passed the pointer to that to OpenGL and OpenGL tried to read 6 ints from that.
Right I see, that makes it clear, although some kind of a more useful error message would have been nice :D
Anyway thank you again for the help, do you have some advice on resources where I can obtain your knowledge or is the only way just suffering through experience lol?
There are plenty of tutorials for OpenGL in general, but for pitfalls such as this, I think suffering is the way to go. 😂 Though it's not as bad as my statement might've made it seem, it's just that issues like this one that can be pretty disheartening/annoying, when you don't even manage to draw something.
Also: note that you actually got it right first try with glVertexAttribPointer
, you're passing a null pointer there.
Yeah I am not sure why I opted in for just typing 0 in there, i guess it was me converting C to python from the tutorial on here learnopengl.com and not realising what im doing.
Do you think there is any point in learning OpenGL btw or would you say learning Vulkan is the way forward?
I can't tell you what the future will hold for OpenGL and I don't know your use cases, but take a look at a Vulkan tutorial for drawing a single triangle. Vulkan is a wee bit more verbose and complex, the learning curve isn't any less steep than that of OpenGL. I think even if you don't end up using OpenGL all that much, it can be a useful tool to learn and understand.
Im following a very simple code example to draw something on screen using glfw and opengl but I get met with
I have reduced my code as much as possible so I can post it here, I am doing
glfw.make_context_current(window)
to make the context current so I am not sure what is going wrong:Putting:
just before:
prints
<glfw.LP__GLFWwindow object at 0x7f822c987340>
meaning that some context was created for that window, as far as I understand the glfw docs.EDIT: might be worth mentioning that I compiled glfw from source and replaced the wheel package with this newly compiled version as glfw 3.3.x does not work with ubuntu 21 and its wayland version
EDIT2: I am currently investigating if this has potentially something to do with my nvidia drivers and my gpu not showing up on some places as it should. Although I have an igpu capable of OpenGL 4.6 support