- 浏览: 200741 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
悲梦天下:
楼主,有些视频到一半就没声音了,怎么破!!!
python视频教程 更新22(完) -
schi:
啊,我太傻了,都想到使用uv了,可以有更简单的方法,只要把uv ...
Get Reversed Normal Faces(获取反法线面) [原理] -
schi:
相对Pillow和PySide而言,显示图片opengl就显得 ...
display an image with pyopengl and Pillow -
schi:
我也是今天才偶然想到的,我以后可能用不着了,所有分享给有需要的 ...
Get Reversed Normal Faces(获取反法线面) [原理] -
baiyanbin:
支持楼主原创,关注楼主博客有一阵子了,国内认真认真搞技术的太少 ...
python视频教程 更新22(完)
Base on this tutorial
基于这个教程
http://www.arcsynthesis.org/gltut/Basics/Tut02%20Vertex%20Attributes.html
Required packages:
pyopengl with freeglut.
To make freeglut works you need to download a pre-compiled binary from http://www.transmissionzero.co.uk/software/freeglut-devel/ or compile it from source http://freeglut.sourceforge.net/.
Copy the freeglut.dll or freeglut64.dll to site-packages/OpenGL/DLLS/
你需要去下载编译好的freeglut,下载地址http://www.transmissionzero.co.uk/software/freeglut-devel/,把freeglut.dll 或 freeglut64.dll放到site-packages/OpenGL/DLLS/里
pyopengl with glfw.
Get pyglfw from https://github.com/nightcracker/pyglfw
There was a glfw.dll included in pyglfw. I think it was a 32bit version. You can replace it to the 64bit version for using python 64bit. The pyglfw only support GLFW 2.x.x version. You can download it from http://sourceforge.net/projects/glfw/. I think it had a small bug that it only works with python2.7. It's easy to fix if you want to using python2.6.
安装pyglfw,下载地址https://github.com/nightcracker/pyglfw。
它已经附带了一个glfw.dll,但这版本可能不是你想要或能用的,你可以直接替换成你需要的版本,但pyglfw只支持GLFW 2.x.x的版本,下载地址http://sourceforge.net/projects/glfw/。它有个小bug,使得它只支持python2.7,这个bug不难修复。
pyopengl with PySide/PyQt.
Install PySide/PyQt4. I only tested with PySide. It should works fine with PyQt4.
安装PySide或PyQt4。我只测试了PySide。
基于这个教程
http://www.arcsynthesis.org/gltut/Basics/Tut02%20Vertex%20Attributes.html
Required packages:
- pyopengl
- numpy
pyopengl with freeglut.
To make freeglut works you need to download a pre-compiled binary from http://www.transmissionzero.co.uk/software/freeglut-devel/ or compile it from source http://freeglut.sourceforge.net/.
Copy the freeglut.dll or freeglut64.dll to site-packages/OpenGL/DLLS/
你需要去下载编译好的freeglut,下载地址http://www.transmissionzero.co.uk/software/freeglut-devel/,把freeglut.dll 或 freeglut64.dll放到site-packages/OpenGL/DLLS/里
# -------------------------------------------------------------------------------- # Copyright (c) 2013 Mack Stone. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # -------------------------------------------------------------------------------- """ Modern OpenGL with python. render a color triangle with pyopengl using freeglut. @author: Mack Stone """ import ctypes import numpy from OpenGL.GL import * from OpenGL.GL import shaders from OpenGL.GLUT import * VERTEX_SHADER = """ #version 330 layout (location=0) in vec4 position; layout (location=1) in vec4 color; smooth out vec4 theColor; void main() { gl_Position = position; theColor = color; } """ FRAGMENT_SHADER = """ #version 330 smooth in vec4 theColor; out vec4 outputColor; void main() { outputColor = theColor; } """ shaderProgram = None VAO = None def initialize(): global VERTEX_SHADER global FRAGMENT_SHADER global shaderProgram global VAO # compile shaders and program vertexShader = shaders.compileShader(VERTEX_SHADER, GL_VERTEX_SHADER) fragmentShader = shaders.compileShader(FRAGMENT_SHADER, GL_FRAGMENT_SHADER) shaderProgram = shaders.compileProgram(vertexShader, fragmentShader) # triangle position and color vertexData = numpy.array([0.0, 0.5, 0.0, 1.0, 0.5, -0.366, 0.0, 1.0, -0.5, -0.366, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, ], dtype=numpy.float32) # create VAO VAO = glGenVertexArrays(1) glBindVertexArray(VAO) # create VBO VBO = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, VBO) glBufferData(GL_ARRAY_BUFFER, vertexData.nbytes, vertexData, GL_STATIC_DRAW) # enable array and set up data glEnableVertexAttribArray(0) glEnableVertexAttribArray(1) glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, None) # the last parameter is a pointer # python donot have pointer, have to using ctypes glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(48)) glBindBuffer(GL_ARRAY_BUFFER, 0) glBindVertexArray(0) def render(): global shaderProgram global VAO glClearColor(0, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # active shader program glUseProgram(shaderProgram) glBindVertexArray(VAO) # draw triangle glDrawArrays(GL_TRIANGLES, 0, 3) glBindVertexArray(0) glUseProgram(0) glutSwapBuffers() def main(): # init freeglut glutInit([]) # make a window glutInitContextVersion(3, 3) glutInitContextFlags(GLUT_FORWARD_COMPATIBLE) glutInitContextProfile(GLUT_CORE_PROFILE) glutInitWindowSize(640, 480) glutCreateWindow("pyopengl with glut") initialize() glutDisplayFunc(render) glutMainLoop() if __name__ == '__main__': main()
pyopengl with glfw.
Get pyglfw from https://github.com/nightcracker/pyglfw
There was a glfw.dll included in pyglfw. I think it was a 32bit version. You can replace it to the 64bit version for using python 64bit. The pyglfw only support GLFW 2.x.x version. You can download it from http://sourceforge.net/projects/glfw/. I think it had a small bug that it only works with python2.7. It's easy to fix if you want to using python2.6.
安装pyglfw,下载地址https://github.com/nightcracker/pyglfw。
它已经附带了一个glfw.dll,但这版本可能不是你想要或能用的,你可以直接替换成你需要的版本,但pyglfw只支持GLFW 2.x.x的版本,下载地址http://sourceforge.net/projects/glfw/。它有个小bug,使得它只支持python2.7,这个bug不难修复。
# -------------------------------------------------------------------------------- # Copyright (c) 2013 Mack Stone. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # -------------------------------------------------------------------------------- """ Modern OpenGL with python. render a color triangle with pyopengl using glfw. @author: Mack Stone """ import ctypes import numpy from OpenGL.GL import * from OpenGL.GL import shaders import glfw VERTEX_SHADER = """ #version 330 layout (location=0) in vec4 position; layout (location=1) in vec4 color; smooth out vec4 theColor; void main() { gl_Position = position; theColor = color; } """ FRAGMENT_SHADER = """ #version 330 smooth in vec4 theColor; out vec4 outputColor; void main() { outputColor = theColor; } """ shaderProgram = None VAO = None def initialize(): global VERTEX_SHADER global FRAGMENT_SHADER global shaderProgram global VAO # compile shaders and program vertexShader = shaders.compileShader(VERTEX_SHADER, GL_VERTEX_SHADER) fragmentShader = shaders.compileShader(FRAGMENT_SHADER, GL_FRAGMENT_SHADER) shaderProgram = shaders.compileProgram(vertexShader, fragmentShader) # triangle position and color vertexData = numpy.array([0.0, 0.5, 0.0, 1.0, 0.5, -0.366, 0.0, 1.0, -0.5, -0.366, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, ], dtype=numpy.float32) # create VAO VAO = glGenVertexArrays(1) glBindVertexArray(VAO) # create VBO VBO = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, VBO) glBufferData(GL_ARRAY_BUFFER, vertexData.nbytes, vertexData, GL_STATIC_DRAW) # enable array and set up data glEnableVertexAttribArray(0) glEnableVertexAttribArray(1) glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, None) # the last parameter is a pointer # python donot have pointer, have to using ctypes glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(48)) glBindBuffer(GL_ARRAY_BUFFER, 0) glBindVertexArray(0) def render(): global shaderProgram global VAO glClearColor(0, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # active shader program glUseProgram(shaderProgram) glBindVertexArray(VAO) # draw triangle glDrawArrays(GL_TRIANGLES, 0, 3) glBindVertexArray(0) glUseProgram(0) glfw.SwapBuffers() def main(): # init glfw glfw.Init() # make a window glfw.OpenWindowHint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) glfw.OpenWindowHint(glfw.OPENGL_VERSION_MAJOR, 3) glfw.OpenWindowHint(glfw.OPENGL_VERSION_MINOR, 3) glfw.OpenWindow(640, 480, 8, 8, 8, 8, 0, 0, glfw.WINDOW) initialize() while glfw.GetWindowParam(glfw.OPENED): render() glfw.Terminate() if __name__ == '__main__': main()
pyopengl with PySide/PyQt.
Install PySide/PyQt4. I only tested with PySide. It should works fine with PyQt4.
安装PySide或PyQt4。我只测试了PySide。
# -------------------------------------------------------------------------------- # Copyright (c) 2013 Mack Stone. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # -------------------------------------------------------------------------------- """ Modern OpenGL with python. render a color triangle with pyopengl using PySide/PyQt4. @author: Mack Stone """ import ctypes import numpy from OpenGL.GL import * from OpenGL.GL import shaders from PySide import QtGui, QtOpenGL #from PyQt4 import QtGui, QtOpenGL VERTEX_SHADER = """ #version 330 layout (location=0) in vec4 position; layout (location=1) in vec4 color; smooth out vec4 theColor; void main() { gl_Position = position; theColor = color; } """ FRAGMENT_SHADER = """ #version 330 smooth in vec4 theColor; out vec4 outputColor; void main() { outputColor = theColor; } """ class MyWidget(QtOpenGL.QGLWidget): def initializeGL(self): glViewport(0, 0, self.width(), self.height()) # compile shaders and program vertexShader = shaders.compileShader(VERTEX_SHADER, GL_VERTEX_SHADER) fragmentShader = shaders.compileShader(FRAGMENT_SHADER, GL_FRAGMENT_SHADER) self.shaderProgram = shaders.compileProgram(vertexShader, fragmentShader) # triangle position and color vertexData = numpy.array([0.0, 0.5, 0.0, 1.0, 0.5, -0.366, 0.0, 1.0, -0.5, -0.366, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, ], dtype=numpy.float32) # create VAO self.VAO = glGenVertexArrays(1) glBindVertexArray(self.VAO) # create VBO VBO = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, VBO) glBufferData(GL_ARRAY_BUFFER, vertexData.nbytes, vertexData, GL_STATIC_DRAW) # enable array and set up data glEnableVertexAttribArray(0) glEnableVertexAttribArray(1) glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, None) # the last parameter is a pointer # python donot have pointer, have to using ctypes glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, ctypes.c_void_p(48)) glBindBuffer(GL_ARRAY_BUFFER, 0) glBindVertexArray(0) def paintGL(self): glClearColor(0, 0, 0, 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # active shader program glUseProgram(self.shaderProgram) glBindVertexArray(self.VAO) # draw triangle glDrawArrays(GL_TRIANGLES, 0, 3) glBindVertexArray(0) glUseProgram(0) def main(): import sys app = QtGui.QApplication(sys.argv) glformat = QtOpenGL.QGLFormat() glformat.setVersion(3, 3) glformat.setProfile(QtOpenGL.QGLFormat.CoreProfile) w = MyWidget(glformat) w.resize(640, 480) w.show() sys.exit(app.exec_()) if __name__ == '__main__': main()
发表评论
-
uv重叠(uv overlap)
2014-06-28 22:28 5199两年多前我需要解决uv重叠的问题,当时觉得是一个挺有挑 ... -
display an image with pyopengl and Pillow
2014-04-09 17:05 2328使用opengl和Pillow来显示图片。 如果你以前使用过p ... -
cmdReporterHighlighter
2014-01-19 19:30 832A syntaxhighlighter I wrote ... -
python视频教程 更新22(完)
2013-09-07 20:31 2195实际上最后的类实战的ood是不正确,虽然Point类和Vect ... -
Add MEL syntax highlighting for expression editor[给表达式编辑器添加mel的高光显示]
2013-08-30 18:16 1891I don't use mel for years. But ... -
GPU, Python and Maya
2013-06-27 17:32 3025Here an example how to use pyop ... -
Qt5.1 And Modern OpenGL
2013-07-16 12:15 3911I been learning modern opengl f ... -
mentalray cause maya2012 crash on standalone mode
2013-03-28 20:27 1023如果你想使用maya2012和python来做些批处理,你就要 ... -
python基础视频教程
2013-08-14 15:56 1673我打算做一系列的python基础视频教程。 目前的计划是从0基 ... -
convert color image to grayscale with pyopencl(example code)
2013-03-09 20:38 2207grayscale.py import pyopencl as ... -
sierpinski triangle 2d maya plug-in(with python API 2.0)
2012-11-07 16:55 2285因为python API 2.0可用的类很少,OpenMaya ... -
sierpinski triangle 2d in maya(with python API 2.0)
2012-10-22 20:41 1965在国庆前我刚好完成手上的工作,有两三天的空闲,于是就去 ... -
mel,cmds,python API哪个更快?
2012-09-13 14:37 3881昨天偶然的跟同事谈论 ... -
Maya Python API 2.0 - MGlobal
2012-08-31 18:07 2278MGlobal是一个静态类,提供通用的API涵数. 包括获取m ... -
Maya Python API 2.0 - MSelectionList
2012-07-09 14:03 2495从Maya2012开始我们迎来了新的Python API, ... -
我讨厌给UI起名字,也懒得起名字
2012-07-05 14:35 1321从我开始给Maya开发UI工具的时候起就觉得给窗口起名是件麻烦 ... -
算法(algorithm) 101
2012-07-02 23:01 1124在Maya中实现深度/广度优先搜索算法 Depth-First ... -
(Get Maya Main Window for PyQt4/PySide)为PyQt4/PySide获取Maya的主窗口
2012-07-02 22:47 1769我们都知道Maya的主窗口保存在mel的全局变量$gMainW ... -
PyQt4 basic
2011-01-25 15:22 2304很久没用过PyQt了,以前也没怎么学,现在我打算从新学习Qt。 ... -
Open Project Folder (python in maya)
2011-01-12 18:17 5838在realflow里有个Open Project Folder ...
相关推荐
OpenGL的软件包freeglut、glfw、glew、SDK,都在这里
opengl中的freeglut 64位版本,结合我之前的文章,亲测可用。
openGL glut freeglut glew opengl开发库 包含了openGL GLAux glut freeglut glew opengl开发库,有它基本OpenGL就可以配置好了。
基于VS的opengl示例。freeglut库。对于opengl入门很好。对于opengl矩阵变换有很多大帮助
openGL开发教程(入门教程+freeglut包) freeglut类同glut,freeglut是开源的,
opengl工具包 freeglut glut glew gl opengl32 .h文件 .dll文件 .lib文件
OpenGL的新开源库FreeGLUT2.8版本,其中头文件以及静态链接库和动态链接库已经编译好,只需要放到ide对应的文件夹当中即可使用
本函数库包含glew2.1、glfw3.2、及freeglut3的库函数及lib文件,还有一个配置方法的网址https://blog.csdn.net/ideallic/article/details/52836425。
freeglut3.2.1正式版,内含代码库,cmake文件,安卓开发库,doc文档。可用于opengl开发
OpenGL所有库(OpenGL,freeglut、glu、glut、glew、glfw等)的头文件、库文件和dll文件。都包含在内了。如果需要使用,在vs项目属性中添加包含即可。
QtCreator开发环境下(minGW编译器),进行OpenGL编程时使用的第三方库,使用时只需将压缩包内文件夹内容复制到Qt安装目录下的minGW目录下的对应文件夹内,如:D:\Qt5.4\5.4\mingw491_32\bin;并在新建工程的.pro...
Opengl(1.1+freeglut+glew+glfw库),多种版本(32\64),收集整理这些版本没少花心思。
OpenGL配置freeglut3.0。包括 freeglut.lib和freeglut.dll和*.h头文件
工具库:freeglut 窗口:winform 主要实现:将OpenGL绘图窗口嵌入Winform窗口,在OpenGL窗口中导入事先准备好的obj模型,并通过winform窗口上的控件对导入的两关节机械臂进行简单操作并输出结果。
自己编译的freeglut和glew,直接放到vs库里就ok了,具体可见本人的文章:https://blog.csdn.net/tabkill1994/article/details/79867551
glew 2.0 glfw 3.2 soil 以及 freeglut 3.0,下载后放到VS2015安装目录下的VC目录即可
opengl环境配置(freeglut+glew+project),配置教程地址:blog.liujunliang.com.cn
最新版opengl开发库freeglut3.0+vs2015编译,包涵所用到的头文件,lib库。dll等
OpenGl库工具包,其中包括freeglut,glew,gltools,glut,glaux的配置文件,还有一个Demo的小例子,配置参考:https://www.cnblogs.com/zpcdbky/p/6724772.html