zoukankan      html  css  js  c++  java
  • 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 下。

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

  • 相关阅读:
    在类中声明常量
    PHPStudy配置虚拟主机配置域名步骤
    PHPStudy配置虚拟主机步骤
    2019年7月22日星期一,简单的总结一下
    简单的面向对象
    session和cookie
    Jquery 事件绑定 bind 与on 的区别
    php try catch用法
    include,include_once,require,require_once的区别
    require与 include区别
  • 原文地址:https://www.cnblogs.com/lclblack/p/6378212.html
Copyright © 2011-2022 走看看