本文整理汇总了Python中texture.Texture.load方法的典型用法代码示例。如果您正苦于以下问题:Python Texture.load方法的具体用法?Python Texture.load怎么用?Python Texture.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类texture.Texture
的用法示例。
在下文中一共展示了Texture.load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GlutWindow
# 需要导入模块: from texture import Texture [as 别名]
# 或者: from texture.Texture import load [as 别名]
class GlutWindow(WindowCallback):
def __init__(self, screen_size: tuple, screen_pos: tuple=(0, 0),
game_mode: bool=False, title: str='Default Title', **params):
width, height = screen_size
self.screen_size = screen_size
self.screen_pos = screen_pos
self.width = width
self.height = height
self.z_near = 1.0
self.z_far = 100.0
self.fov = 60.0
self.game_mode = game_mode
self.title = title
self._vbo = None
self._vao = None
self._ibo = None
self._program = None
self._texture = None
self._vertices = None
self._indexes = None
self._camera = None
self._pipeline = None
self._scale = 0.0
self._dir_light_color = 1.0, 1.0, 1.0
self._dir_light_ambient_intensity = 0.5
self._projection = ProjParams(
self.width, self.height, self.z_near, self.z_far, self.fov)
self._log = params.get("log", print)
self._clear_color = params.get("clearcolor", (0, 0, 0, 0))
self._vertex_attributes = {"Position": -1, "TexCoord": -1}
self._init_glut()
self._init_gl()
self._create_vertex_buffer()
self._create_index_buffer()
self._effect = LightingTechnique("shaders/vs.glsl", "shaders/fs_lighting.glsl")
self._effect.init()
self._effect.enable()
self._effect.set_texture_unit(0)
self._texture = Texture(GL_TEXTURE_2D, "resources/test.png")
if not self._texture.load():
raise ValueError("cannot load texture")
def _init_glut(self):
"""
Basic GLUT initialization and callbacks binding
"""
glutInit(sys.argv[1:])
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_3_2_CORE_PROFILE)
glutInitWindowSize(self.width, self.height)
if self.game_mode:
glutGameModeString("{}x{}@32".format(self.width, self.height))
glutEnterGameMode()
else:
glutCreateWindow(self.title.encode())
glutInitWindowPosition(*self.screen_pos)
# callbacks binding
glutDisplayFunc(self.on_display)
glutIdleFunc(self.on_display)
glutPassiveMotionFunc(self.on_mouse)
glutSpecialFunc(self.on_keyboard)
def _init_gl(self):
"""
OpenGL initialization
"""
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glClearColor(*self._clear_color)
# seems strange because should be GL_BACK... maybe something with camera?
glCullFace(GL_FRONT)
glFrontFace(GL_CW)
glEnable(GL_CULL_FACE)
def _create_vertex_buffer(self):
"""
Creates vertex array and vertex buffer and fills last one with data.
"""
self._vertices = np.array([
-1.0, -1.0, 0.5773, 0.0, 0.0,
0.0, -1.0, -1.15475, 0.5, 0.0,
1.0, -1.0, 0.5773, 1.0, 0.0,
0.0, 1.0, 0.0, 0.5, 1.0
], dtype=np.float32)
self._vao = glGenVertexArrays(1)
glBindVertexArray(self._vao)
self._vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, self._vbo)
glBufferData(GL_ARRAY_BUFFER, self._vertices.nbytes, self._vertices, GL_STATIC_DRAW)
def _create_index_buffer(self):
"""
Creates index buffer.
"""
#.........这里部分代码省略.........