本文整理汇总了Python中pygame.OPENGL属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.OPENGL属性的具体用法?Python pygame.OPENGL怎么用?Python pygame.OPENGL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pygame
的用法示例。
在下文中一共展示了pygame.OPENGL属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_pygame
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def main_pygame():
pygame.init()
size = 800, 600
pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL)
io = imgui.get_io()
io.fonts.add_font_default()
io.display_size = size
renderer = PygameRenderer()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
renderer.process_event(event)
imgui.new_frame()
on_frame()
# note: cannot use screen.fill((1, 1, 1)) because pygame's screen
# does not support fill() on OpenGL sufraces
gl.glClearColor(1, 1, 1, 1)
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
imgui.render()
pygame.display.flip()
示例2: todo_test_flip
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def todo_test_flip(self):
# __doc__ (as of 2008-08-02) for pygame.display.flip:
# pygame.display.flip(): return None
# update the full display Surface to the screen
#
# This will update the contents of the entire display. If your display
# mode is using the flags pygame.HWSURFACE and pygame.DOUBLEBUF, this
# will wait for a vertical retrace and swap the surfaces. If you are
# using a different type of display mode, it will simply update the
# entire contents of the surface.
#
# When using an pygame.OPENGL display mode this will perform a gl buffer swap.
self.fail()
示例3: todo_test_gl_set_attribute
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def todo_test_gl_set_attribute(self):
# __doc__ (as of 2008-08-02) for pygame.display.gl_set_attribute:
# pygame.display.gl_set_attribute(flag, value): return None
# request an opengl display attribute for the display mode
#
# When calling pygame.display.set_mode() with the pygame.OPENGL flag,
# Pygame automatically handles setting the OpenGL attributes like
# color and doublebuffering. OpenGL offers several other attributes
# you may want control over. Pass one of these attributes as the flag,
# and its appropriate value. This must be called before
# pygame.display.set_mode()
#
# The OPENGL flags are;
# GL_ALPHA_SIZE, GL_DEPTH_SIZE, GL_STENCIL_SIZE, GL_ACCUM_RED_SIZE,
# GL_ACCUM_GREEN_SIZE, GL_ACCUM_BLUE_SIZE, GL_ACCUM_ALPHA_SIZE,
# GL_MULTISAMPLEBUFFERS, GL_MULTISAMPLESAMPLES, GL_STEREO
self.fail()
示例4: displayMode
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def displayMode():
return pygame.OPENGL | pygame.RESIZABLE | pygame.DOUBLEBUF
示例5: _make_context
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def _make_context(self, width, height):
"""Create the ModernGL context."""
glconfig = {
'GL_CONTEXT_MAJOR_VERSION': 4,
'GL_CONTEXT_PROFILE_MASK': pygame.GL_CONTEXT_PROFILE_CORE,
}
for k, v in glconfig.items():
k = getattr(pygame, k)
pygame.display.gl_set_attribute(k, v)
dims = width, height
flags = pygame.OPENGL | pygame.DOUBLEBUF
if self.fullscreen:
# SDL's detection for "legacy" fullscreen seems to fail on
# Ubuntu 16.04 at least. Set an environment variable so that it
# asks the Window Manager for full screen mode instead.
# https://github.com/spurious/SDL-mirror/blob/c8b01e282dfd49ea8bbf1faec7fd65d869ea547f/src/video/x11/SDL_x11window.c#L1468
os.environ['SDL_VIDEO_X11_LEGACY_FULLSCREEN'] = "0"
flags |= pygame.FULLSCREEN
if not self._scaler:
self._scaler = 'linear'
dims = 0, 0
elif self._scaler:
flags |= pygame.SCALED
pygame.display.set_mode(
dims,
flags=flags,
depth=24
)
ctx = moderngl.create_context(require=410)
self._real_size = pygame.display.get_window_size()
if self._real_size != (width, height):
self.drawer = self._make_scaler(ctx, (width, height))
return ctx
示例6: setWindowSize
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def setWindowSize(self, width, height):
self.screenSize = (width, height)
self.displayFlags = pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE
self.screen = pygame.display.set_mode( self.screenSize, self.displayFlags )
# implement by extending class
示例7: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def __init__(self, **kwargs):
super().__init__(**kwargs)
pygame.display.init()
pygame.display.gl_set_attribute(pygame.GL_CONTEXT_MAJOR_VERSION, self.gl_version[0])
pygame.display.gl_set_attribute(pygame.GL_CONTEXT_MINOR_VERSION, self.gl_version[1])
pygame.display.gl_set_attribute(pygame.GL_CONTEXT_PROFILE_MASK, pygame.GL_CONTEXT_PROFILE_CORE)
pygame.display.gl_set_attribute(pygame.GL_CONTEXT_FORWARD_COMPATIBLE_FLAG, 1)
pygame.display.gl_set_attribute(pygame.GL_DOUBLEBUFFER, 1)
pygame.display.gl_set_attribute(pygame.GL_DEPTH_SIZE, 24)
if self.samples > 1:
pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLEBUFFERS, 1)
pygame.display.gl_set_attribute(pygame.GL_MULTISAMPLESAMPLES, self.samples)
self._depth = 24
self._flags = pygame.OPENGL | pygame.DOUBLEBUF
if self.fullscreen:
self._flags |= pygame.FULLSCREEN
info = pygame.display.Info()
desktop_size = info.current_w, info.current_h
self._width, self._height = desktop_size
self._buffer_width, self._buffer_height = self._width, self._height
else:
if self.resizable:
self._flags |= pygame.RESIZABLE
self._set_mode()
self.title = self._title
self.cursor = self._cursor
self.init_mgl_context()
self.set_default_viewport()
示例8: todo_test_gl_get_attribute
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def todo_test_gl_get_attribute(self):
# __doc__ (as of 2008-08-02) for pygame.display.gl_get_attribute:
# pygame.display.gl_get_attribute(flag): return value
# get the value for an opengl flag for the current display
#
# After calling pygame.display.set_mode() with the pygame.OPENGL flag,
# it is a good idea to check the value of any requested OpenGL
# attributes. See pygame.display.gl_set_attribute() for a list of
# valid flags.
#
self.fail()
示例9: main
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def main():
pygame.init()
size = 800, 600
pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE)
imgui.create_context()
impl = PygameRenderer()
io = imgui.get_io()
io.display_size = size
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
impl.process_event(event)
imgui.new_frame()
if imgui.begin_main_menu_bar():
if imgui.begin_menu("File", True):
clicked_quit, selected_quit = imgui.menu_item(
"Quit", 'Cmd+Q', False, True
)
if clicked_quit:
exit(1)
imgui.end_menu()
imgui.end_main_menu_bar()
imgui.show_test_window()
imgui.begin("Custom window", True)
imgui.text("Bar")
imgui.text_colored("Eggs", 0.2, 1., 0.)
imgui.end()
# note: cannot use screen.fill((1, 1, 1)) because pygame's screen
# does not support fill() on OpenGL sufraces
gl.glClearColor(1, 1, 1, 1)
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
imgui.render()
impl.render(imgui.get_draw_data())
pygame.display.flip()
示例10: display_cube
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import OPENGL [as 别名]
def display_cube():
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 600
pygame.init()
pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), pygame.DOUBLEBUF | pygame.OPENGL)
OpenGL.GLU.gluPerspective(45, (WINDOW_WIDTH/WINDOW_HEIGHT), 0.1, 50.0)
OpenGL.GL.glTranslatef(0.0, 0.0, -10)
show_cube_1 = True
show_cube_2 = True
show_lines = True
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
elif event.key == pygame.K_1:
show_cube_1 = not show_cube_1
elif event.key == pygame.K_2:
show_cube_2 = not show_cube_2
elif event.key == pygame.K_0:
show_lines = not show_lines
OpenGL.GL.glRotate(1, 3, 10, 10) # (angle,x,y,z)
OpenGL.GL.glClear(OpenGL.GL.GL_COLOR_BUFFER_BIT | OpenGL.GL.GL_DEPTH_BUFFER_BIT)
if show_cube_1:
cube(vertices1, edges) # large cube
if show_cube_2:
cube(vertices2, edges) # small cube
if show_lines:
lines(vertices1, vertices2)
pygame.display.flip()
pygame.time.wait(10)
pygame.quit()
# ---