我想从一些PyOpenGL开始,所以我启动进入Mac Osx尝试它.我去了PyOpenGl网站,下载了PyOpenGl和PyOpenGl_accelerate tars,cd进了我的下载目录,然后在终端输入这些命令进行安装:
tar -zxvf PyOpenGL-3.0.2.tar.gz
cd PyOpenGL-3.0.2
python3 setup.py install #I changed 'python' to 'python3' to install it to my python3.
Run Code Online (Sandbox Code Playgroud)
接下来,我键入这些来安装加速包
tar -zxvf PyOpenGL-accelerate-3.0.2.tar.gz
cd PyOpenGL-accelerate-3.0.2
python3 setup.py install #Again, 'python' replaced with 'python3'
Run Code Online (Sandbox Code Playgroud)
最后,我运行此代码来测试安装
python3
>>>from OpenGL.GL import *
Run Code Online (Sandbox Code Playgroud)
这给了我这一串可爱的错误
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/PyOpenGL-3.0.2-py3.3.egg/OpenGL/GL/__init__.py", line 3, in <module>
from OpenGL.GL.VERSION.GL_1_1 import *
File "/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/PyOpenGL-3.0.2-py3.3.egg/OpenGL/GL/VERSION/GL_1_1.py", line 10, in <module>
from OpenGL import platform, constants, constant, arrays
File "/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/PyOpenGL-3.0.2-py3.3.egg/OpenGL/arrays/__init__.py", line …Run Code Online (Sandbox Code Playgroud) 我在python中需要一个过剩的窗口.我使用Python 3.5和PyOpenGL.GLUT有以下异常
Traceback (most recent call last):
File "D:\...\Test.py", line 47, in <module>
if __name__ == '__main__': main()
File "D:\...\Test.py", line 9, in main
glutInit(sys.argv)
File "C:\...\OpenGL\GLUT\special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )
File "C:\...\OpenGL\platform\baseplatform.py", line 407, in __call__
self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit,
check for bool(glutInit) before calling
Run Code Online (Sandbox Code Playgroud)
平台:Windows
为什么我会收到此错误?
这是我的代码:
from OpenGL.GLUT import *
import sys
glutInit(sys.argv)
Run Code Online (Sandbox Code Playgroud) 我目前正在研究用pygame编写的游戏引擎,我想添加OpenGL支持.
我写了一个测试,看看如何让pygame和OpenGL一起工作,当它在窗口模式下运行时,它运行在150到200 fps之间.当我全屏运行时(我所做的就是在设置窗口时添加FULLSCREEN标志),它下降到60 fps.我添加了更多绘图功能,看它是否只是一个巨大的性能下降,但它总是以60 fps运行.
我需要做些什么来告诉OpenGL它是全屏运行还是这是OpenGL的限制?
(我在Windows XP中运行)
我一直在研究一个使用Python和OpenGL的项目.我之前发布了类似的问题,但我已经做了一些研究并转而使用了不推荐的函数.按照本教程(显然将其翻译成Python版本),我最终得到了这段代码:
import sys
import OpenGL
from OpenGL.GL import *
from OpenGL.GL.shaders import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from OpenGL.GLUT.freeglut import *
from OpenGL.arrays import vbo
import pygame
import Image
import numpy
class AClass:
def __init__(self):
self.Splash = True #There's actually more here, but it's impertinent
def TexFromPNG(self, filename):
img = Image.open(filename) # .jpg, .bmp, etc. also work
img_data = numpy.array(list(img.getdata()), 'B')
texture = glGenTextures(1)
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glBindTexture(GL_TEXTURE_2D, texture)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
glTexParameterf(GL_TEXTURE_2D, …Run Code Online (Sandbox Code Playgroud) 我一直在用Python和PyOpenGL练习,但我似乎无法用Python打开.OFF文件(目标文件格式).
如果您想知道,.OFF文件是包含3D对象位置的文件.
OFF
8 6 0
-0.500000 -0.500000 0.500000
0.500000 -0.500000 0.500000
-0.500000 0.500000 0.500000
0.500000 0.500000 0.500000
-0.500000 0.500000 -0.500000
0.500000 0.500000 -0.500000
-0.500000 -0.500000 -0.500000
0.500000 -0.500000 -0.500000
4 0 1 3 2
4 2 3 5 4
4 4 5 7 6
4 6 7 1 0
4 1 7 5 3
4 6 0 2 4
Run Code Online (Sandbox Code Playgroud)
我想读取这个文件并让它出现在python上.
示例应该是这样的:http: //people.sc.fsu.edu/~jburkardt/data/off/box.png
到目前为止,我必须手动编写.OFF文件中的每个坐标.但是程序需要能够读取你给它的每个.OFF文件.
我只能制作我给出的例子,因为我为verticies和surface创建了一个元组元组:
verticiesCube = (
(-0.5,-0.5,0.5),
(0.5,-0.5,0.5),
(-0.5,0.5,0.5),
...
)
Run Code Online (Sandbox Code Playgroud)
和
surfacesCube = …Run Code Online (Sandbox Code Playgroud) 我正在使用 python3
我刚刚开始学习 openGL,我需要一些帮助用鼠标转动你的视图的相机(就像 FPS 游戏)。现在我的程序看起来像是在移动,但我只是在移动对象,所以如果你能告诉我如何移动相机(向前、向后等),那就太好了。提前致谢
我的代码:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
vertices = (
(1, -1, -1),
(1, 1, -1),
(-1, 1, -1),
(-1, -1, -1),
(1, -1, 1),
(1, 1, 1, ),
(-1, -1, 1),
(-1, 1, 1),
)
edges = (
(0,1),
(0,3),
(0,4),
(2,1),
(2,3),
(2,7),
(6,3),
(6,4),
(6,7),
(5,1),
(5,4),
(5,7),
)
surfaces = (
(0,1,2,3),
(3,2,7,6),
(6,7,5,4),
(4,5,1,0),
(1,5,7,2),
(4,0,3,6),
)
colors = (
(1,1,1), …Run Code Online (Sandbox Code Playgroud) 我将Python 3与PyOpenGL结合使用,我需要在空间中绘制单个点。我知道一个点没有体积,但是我不知道是否有一种简单的方法可以在某些坐标处绘制点/球。编辑:我在pygame和tkinter gui内使用opengl
我尝试了以下代码:
glEnable(GL_POINT_SMOOTH)
glBegin(GL_POINTS)
glColor3d(1, 1, 1)
glPointSize(200)
glVertex3d(1, 1, 1)
glEnd() # This throws an error
Run Code Online (Sandbox Code Playgroud)
错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:/Users/reas/Desktop/Programación/Dibujo/Dibujo.py", line 65, in vista_alzado
glEnd()
File "C:\Program Files (x86)\Python37-32\lib\site-packages\OpenGL\latebind.py", line 61, in __call__
return self.wrapperFunction( self.baseFunction, *args, **named )
File "C:\Program Files (x86)\Python37-32\lib\site-packages\OpenGL\GL\exceptional.py", line 45, in glEnd
return baseFunction( )
File "C:\Program Files (x86)\Python37-32\lib\site-packages\OpenGL\platform\baseplatform.py", line 409, in __call__
return …Run Code Online (Sandbox Code Playgroud) 我编写了以下 Python 代码,它将在使用 GLFW 创建的窗口中绘制一个三角形:
import glfw
from OpenGL.GL import *
from OpenGL.GL.shaders import compileProgram, compileShader
import numpy as np
vertex_src = """
# version 330 core
in vec3 a_position;
void main() {
gl_position = vec4(a_position, 1.0);
}
"""
fragment_src = """
# version 330 core
out vec4 out_color;
void main() {
out_color = vec4(1.0, 0.0, 0.0, 1.0);
}
"""
if not glfw.init():
print("Cannot initialize GLFW")
exit()
window = glfw.create_window(320, 240, "OpenGL window", None, None)
if not window:
glfw.terminate()
print("GLFW …Run Code Online (Sandbox Code Playgroud) 我正在学习现代 openGL,目前我在渲染文本方面遇到了麻烦。我正在遵循C++教程,但我正在尝试用 python 实现。
这是我的代码:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GL import shaders
import glfw
import freetype
import glm
import numpy as np
from PIL import Image
import math
import time
class CharacterSlot:
def __init__(self, texture, glyph):
self.texture = texture
self.textureSize = (glyph.bitmap.width, glyph.bitmap.rows)
if isinstance(glyph, freetype.GlyphSlot):
self.bearing = (glyph.bitmap_left, glyph.bitmap_top)
self.advance = glyph.advance.x
elif isinstance(glyph, freetype.BitmapGlyph):
self.bearing = (glyph.left, glyph.top)
self.advance = None
else:
raise RuntimeError('unknown glyph type')
def _get_rendering_buffer(xpos, ypos, w, h, …Run Code Online (Sandbox Code Playgroud) 我需要执行以下操作。我使用OBJFileLoader加载了 obj 模型并将其渲染到窗口中。如何将渲染的场景保存为图片?是否可以在不显示窗口的情况下执行此操作?