python3.7 安装pyopengl,环境搭建

安装环境:win10 64位操作系统,python3.7

一.安装py库

需要用pip 安装

pip install  PyOpenGL PyOpenGL_accelerate

可能会报错,

是因为没有安装对应的c++库

打开网站https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl

找到pyopengl

扫描二维码关注公众号,回复: 3699594 查看本文章

下载对应的版本,我的是python3.7+win64

下载完后放到python目录的Scripts中然后在该路径下执行命令行

pip install PyOpenGL_accelerate-3.1.2-cp37-cp37m-win_amd64.whl

成功安装

再次安装

pip install  PyOpenGL PyOpenGL_accelerate

应该就不会报错了!

二.搭建glut环境(需要glut.h、glut64.dll、glut64.lib三个文件)

链接:https://pan.baidu.com/s/10ksiGaJMslHk9VMxOhFeXg
提取码:2o5o

或者在此下载:https://download.csdn.net/download/bigboysunshine/10396268

或者:https://www.opengl.org/resources/libraries/glut/

下载解压后

将文件夹内 glut.h 放在 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\ 下;

将 .\Release\glut64.lib 放在 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\ 下;

将 .\Release\glut64.dll 放在 C:\Windows\System32 下。

运行一下实例:

# -*- coding: utf-8 -*-
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import sys
import numpy as np

# 画圆

def circle(x, y, r, n):
    theta = np.linspace(0, 2*np.pi, n)
    x = x + r * np.cos(theta)
    y = y + r * np.sin(theta)
    return x, y

def plotfunc():
    glClear(GL_COLOR_BUFFER_BIT)        # 清除之前缓存
    glPointSize(3.0)                    # 设置点大小
    glColor3f(1.0, 0.0, 0.0)            # 设置点颜色
    glBegin(GL_POINTS)                  # 此次开始,设置此次画的几何图形
    x, y = circle(0, 0, 1, 100)
    for x_, y_ in zip(x, y):
        glVertex2f(x_, y_)
    glEnd()                             # 此次结束
    glFlush()                           # 刷新屏幕

if __name__ == '__main__':
    glutInit(sys.argv)  #初始化
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) #设置显示模式
    glutInitWindowPosition(100, 100)    #窗口打开的位置,左上角坐标在屏幕坐标
    glutInitWindowSize(900, 600)        #窗口大小
    glutCreateWindow(b"Function Plotter")   #窗口名字,二进制
    glutDisplayFunc(plotfunc)           #设置当前窗口的显示回调
    glClearColor(1.0, 1.0, 1.0, 1.0)    # 设置背景颜色
    gluOrtho2D(-5.0, 5.0, -5.0, 5.0)    # 设置显示范围
    glutMainLoop()                      # 启动循环

此时,应该可以显示一个椭圆

至此,OpenGL环境搭建完成!

opencv的学习,推荐网站www.opencv.org.cn

参考:

https://blog.csdn.net/BigBoySunshine/article/details/80218245?utm_source=blogkpcl4

https://blog.csdn.net/qq_15602569/article/details/79670880

http://pyopengl.sourceforge.net/

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/9840986.html
今日推荐