• Python环境搭建之OpenGL


    以下内容为我python OpenGl 环境搭建历程:

      win7 64位操作系统,python3.5.3 ,无其他相关。

      直接cmd或PowerShell输入以下命令:

    pip install  PyOpenGL PyOpenGL_accelerate

      安装失败,提示需安装Microsoft Visual C++ 14.0,让我使用Microsoft Visual C++ build tools。并且后面给出了下载链接http://landinghub.visualstudio.com/visual-cpp-build-tools,在该链接下载得到文件visualcppbuildtools_full.exe,进行安装。。。

      失败,提示需要.net framework4.5.1以上

      一开始我下载了.net framework 4.5 发现还不能安装,于是重新搜索,终于在https://www.microsoft.com/zh-CN/download/details.aspx?id=48130找到4.6版本,下载得文件NDP46-KB3045560-Web.exe安装之。

      终于可以安Microsoft Visual C++ build tools(visualcppbuildtools_full.exe)了。

      经过漫长的等待VC++也搞定,重启后继续执行命令:

    pip install  PyOpenGL PyOpenGL_accelerate

      一次性成功,兴奋之余在网上找了段测试代码,并稍作调整( glutCreateWindow(b"first")处,原文为glutCreateWindow("first"),运行会报错:Python glutCreateWindow error 'wrong type',详情参见https://codeyarns.com/2012/04/27/pyopengl-glut-ctypes-error/ 

    from OpenGL.GL import *
    from OpenGL.GLU import *
    from OpenGL.GLUT import *
    
    def drawFunc():
        #清楚之前画面
        glClear(GL_COLOR_BUFFER_BIT)
        glRotatef(0.1, 5, 5, 0)   #(角度,x,y,z)
        glutWireTeapot(0.5)
        #刷新显示
        glFlush()
        
    #使用glut初始化OpenGL
    glutInit()
    #显示模式:GLUT_SINGLE无缓冲直接显示|GLUT_RGBA采用RGB(A非alpha)
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
    #窗口位置及大小-生成
    glutInitWindowPosition(0,0)
    glutInitWindowSize(400,400)
    glutCreateWindow(b"first")
    #调用函数绘制图像
    glutDisplayFunc(drawFunc)
    glutIdleFunc(drawFunc)
    #主循环
    glutMainLoop()

      运行,结果提示OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling。原来我没搭建glut,又开始漫长的搜寻路程,终于在http://download.csdn.net/detail/knownall/6799947找到需要的(其实就需要glut.h、glut64.dll、glut64.lib三个文件,32位同理)。

      下载解压后将文件夹内 glut.h 放在 C:Program Files (x86)Microsoft Visual Studio 14.0VCinclude 下;

      将 .Releaseglut64.lib 放在 C:Program Files (x86)Microsoft Visual Studio 14.0VClib 下;

      将 .Releaseglut64.dll 放在 C:WindowsSystem32 下。

      再次运行,终于大功告成,可以看到一个旋转的茶壶。

  • 相关阅读:
    Index(4.3)
    第七次会议(4.22)
    第六次会议(4.15)
    第五次会议(4.8)
    第四次会议(4.2)
    第三次会议(3.25)
    第二次扩大会议(3.19)
    第二次会议(3.25)
    第一次会议(3.11)
    牛客练习赛25A求1-x因数和(离散求和)
  • 原文地址:https://www.cnblogs.com/lclblack/p/6378212.html
Copyright © 2020-2023  润新知