electronut / pp

Code for book Python Playground by Mahesh Venkitachalam (No Starch Press, USA)
564 stars 500 forks source link

b'invalid operation' in volrender.py #8

Closed patmo141 closed 8 years ago

patmo141 commented 8 years ago

I'm attempting to work through the Volume Rendering chapter. Love the book! This may be a driver or system error but any tips for teasing out this error would be greatly appreciated!

  1. I'm using windows7 64 bit and python 3.4 64bit (I made sure with platform.architecture())
  2. I downloaded the 64bit glfw binaries from http://www.glfw.org/download.html
  3. I copied glfw3.dll from the libvc-2012 folder into volrender.py and hardcoded the path to the dll in volrender.py. That seems to be working because glfw.glfwInit() returns 1
  4. I get "invalid operation' error when it get to the glViewport() call.

image

electronut commented 8 years ago

Hello,

Thanks for buying the book!

Regarding your error, a few questions/suggestions:

  1. Are you able to run the first OpenGL project in chapter 9?

    https://github.com/electronut/pp/tree/master/simplegl

  2. Instead of copying the dll and hardcoding paths, could you follow the process outlined in Appendix A, page 298? (See image below.)

The error indicates that the OpenGL context is invalid, which could be due to a number of reasons, but let's try to get the chapter 9 code to work first.

screen shot 2016-04-11 at 9 04 50 am
patmo141 commented 8 years ago

Re ch9: You have caught me! Trying to run before I walk. Yes I will try this first.

Re PATH: Yes that's no problem, it was just laziness on my part.

It will probably be sometime toward end of week. Thanks, Patrick

electronut commented 8 years ago

Sure. Let me know if you need help.

patmo141 commented 8 years ago

Ok, couldn't resist playing some more.

  1. I set up my PYTHONPATH and GLFW_LIBRARY environment variables
  2. I read (ok, I read part of and skimmed all of) Ch. 9
  3. I ran simpleglfw.py and....

image

More information to come

electronut commented 8 years ago

Could you try this quick test:

 > cd c:\dev\...\simplegl
 > python simpleglfw.py

Just wondering if it's still a path issue.

patmo141 commented 8 years ago

image

I have multiple python versions so I did a slightly different by explicity pointing to python34 since that is where my OpenGL is installed in site-packages.

electronut commented 8 years ago

I am a bit stumped...

How about the official glfw example below. Can you try running it?

https://pypi.python.org/pypi/glfw

If you can't run the above, one guess would be that your OS doesn't have an OpenGL driver installed. Could you try installing a driver for your graphics card? If you send me the system details, I can try to help.

patmo141 commented 8 years ago

While I am getting driver's updated. I have one of those dual graphics card situations, where the builtin chip operates some times, and the dedicated GPU works others.

image

electronut commented 8 years ago

Any luck with the official glfw example?

patmo141 commented 8 years ago

was able to run hello world gflw example from https://pypi.python.org/pypi/glfw I downloaded glfw.py from https://github.com/FlorianRhiem/pyGLFW I had to hardcode the location of glfw3.dll in that example because it could not find it even with the envorinment variable set, however once I did that, all was well

image

electronut commented 8 years ago

So if the official glfw sample works, simpleglfw.py should work?

patmo141 commented 8 years ago

The bindings are all different in the github version https://github.com/FlorianRhiem/pyGLFW/blob/master/glfw.py For example glfw.init() vs glfw.glfwInit(). I will alter them and see if I can get glsimple.py to work if I change the bindings.

patmo141 commented 8 years ago

Ok, I changed all the functions in simpleglfw.py to match the glfw.py bindings from github, and I get the same error 'invalid operation', so I must have an issue with OpenGL drivers or PyOpenGL

electronut commented 8 years ago

Can we go back to the glfw example:

https://pypi.python.org/pypi/glfw

Do NOT use https://github.com/FlorianRhiem/pyGLFW

You should be using glfw.py from the common/ directory of the book's source code.

Can you send me your PYTHONPATH?

patmo141 commented 8 years ago

the example code from pypi.python.org will not work with pp-master/common/glfw.py because the bindings are defined differently (eg, CamelCase vs lower_case).

My PYTHONPATH is only "C:\Dev\pp-master\common" I do the majority of my work in Blender python so I have not added anything to PYTHONPATH except this project :-)

patmo141 commented 8 years ago

I am starting fresh, updating drivers, installing PyOpenGL from PyPi, downloading fresh pp-master source to eliminate any setup errors on my part. Thanks for all of your help so far! I'll report back shortly

patmo141 commented 8 years ago

Step 1. Fresh pp-master directory Step 2. PYTHONPATH: "C:\Dev\pp-master\common", Step 3. GLFW_LIBRARY "C\Dev\glfw\lib-vc2012\glfw3.dll Step 4. Modify the example from PyPi to match the functions in C:\Dev\pp-master\common\glfw.py

import glfw

def main():
    # Initialize the library
    if not glfw.glfwInit():
        return
    # Create a windowed mode window and its OpenGL context
    window = glfw.glfwCreateWindow(640, 480)
    if not window:
        print("failed to open window")
        glfw.glfwTerminate()
        return
    # Make the window's context current
    glfw.glfwMakeContextCurrent(window)

    # Loop until the user closes the window
    while not glfw.glfwWindowShouldClose(window):
        # Render here, e.g. using pyOpenGL

        # Swap front and back buffers
        glfw.glfwSwapBuffers(window)

        # Poll for and process events
        glfw.glfwPollEvents()

    glfw.glfwTerminate()

if __name__ == "__main__":
    main()

This works, I get a blank glfw window

patmo141 commented 8 years ago

So, hours and hours ago, I tried global settings to test Nvida card and Builtin Intel card. Apparently it was ignoring my settings because once I specified that Python uses the Nvidia card, it works.

image

electronut commented 8 years ago

Awesome. Glad to see it working!

patmo141 commented 8 years ago

Me too. I'm sorry I hope I did not waste too much of your time. And for final closure

image

electronut commented 8 years ago

Happy to help!

A request:

If you like the book, please take a few minutes to write a review on amazon.com:

http://www.amazon.com/Python-Playground-Projects-Curious-Programmer/dp/1593276044