本文整理汇总了Python中pyglet.gl.gluOrtho2D函数的典型用法代码示例。如果您正苦于以下问题:Python gluOrtho2D函数的具体用法?Python gluOrtho2D怎么用?Python gluOrtho2D使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gluOrtho2D函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _layerProjectLocalToScreen
def _layerProjectLocalToScreen(self):
"""Maps self.coordLocal to self.coordScreen within OpenGL."""
if self._scissorBox is None and self.localBounds is None:
return
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glPushMatrix()
gl.glLoadIdentity()
# gluOrtho2D declares the render space for the corners of the window.
# So, we want to set it up in such a way that our layer renders in
# the right place. In other words, determine window corners that
# map cl -> cs. All clipping, etc is already handled by the coordsLocal
# getter.
cs = self.coordsScreen
cl = self.coordsLocal
sw = self.scene.width
sh = self.scene.height
# Determine the window width and height. We want a local-sized chunk
# of this to correspond to a screen-sized chunk of the screen. That is,
# cl[2] / ww == cs[2] / sw
ww = cl[2] * sw / cs[2]
wh = cl[3] * sh / cs[3]
# cs[0] / sw = (x - nx) / ww
nx = cl[0] - cs[0] * ww / sw
ny = cl[1] - cs[1] * wh / sh
gl.gluOrtho2D(nx, nx+ww, ny, ny+wh)
gl.glMatrixMode(gl.GL_MODELVIEW)
示例2: world_projection
def world_projection(self):
"""
Sets OpenGL projection and modelview matrices such that the window
is centered on self.(x,y), shows at least 'scale' world units in every
direction, and is oriented by rot.
"""
left = bottom = -self.scale
right = top = self.scale
aspect = self.width / self.height
if aspect >= 1:
# landscape
left *= aspect
right *= aspect
else:
# portrait
bottom /= aspect
top /= aspect
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(left, right, bottom, top)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(
self.x, self.y, +1.0,
self.x, self.y, -1.0,
sin(self.rot), cos(self.rot), 0.0)
示例3: _set_texture
def _set_texture(self, t):
self._texture = t
from pyglet import gl
try:
gl.glFramebufferTexture2DEXT(
gl.GL_FRAMEBUFFER_EXT,
gl.GL_COLOR_ATTACHMENT0_EXT,
t.target, t.id, 0,
)
except gl.GLException:
# HACK: Some Intel card return errno == 1286L
# which means GL_INVALID_FRAMEBUFFER_OPERATION_EXT
# but IT ACTUALLY WORKS FINE!!
pass
gl.glViewport(0, 0, t.width, t.height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.gluOrtho2D(0, t.width, 0, t.height)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
# ATI cards hack
gl.glBegin(gl.GL_LINES)
gl.glEnd()
示例4: hud_mode
def hud_mode(self):
"Set matrices ready for drawing HUD, like fps counter"
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0, self.win_width, 0, self.win_height)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
示例5: get_vlist
def get_vlist(geom, batch=None, group=None, data=None):
"""Get a "new" C{pyglet.graphics.VertexList} for this
geometry. If a batch is given, vertex list will be added to the batch
"""
# projection with one world coordinate unit equal to one screen pixel
# glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, windowWidth, 0, windowHeight);
window = pyglet.window.get_platform().get_default_display().get_windows()[0]
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.gluOrtho2D(0,
window.width,
0,
window.height)
_data = [('v3f', geom.vertex_data)]
if hasattr(geom, 'normal_data'):
_data.append(('n3f', geom.normal_data))
if hasattr(geom, 'texcoord_data'):
_data.append(('t2f', geom.texcoord_data))
if data:
_data.extend(data)
count = len(geom.vertex_data) // geom.vertex_pitch
indexed = hasattr(geom, 'indices')
if batch:
if indexed:
return batch.add_indexed( count,
geom.drawing_mode, group, geom.indices, *_data)
return batch.add( count,
geom.drawing_mode, group, *_data)
if indexed:
return pyglet.graphics.vertex_list_indexed( count, geom.indices, *_data )
return pyglet.graphics.vertex_list( count, *_data)
示例6: world_projection
def world_projection(self, aspect):
"""
Sets OpenGL projection and modelview matrices such that the window
is centered on self.(x,y), shows at least scale world units in every
direction, and is oriented by angle.
"""
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
if aspect < 1:
gluOrtho2D(
-self.scale,
+self.scale,
-self.scale / aspect,
+self.scale / aspect)
else:
gluOrtho2D(
-self.scale * aspect,
+self.scale * aspect,
-self.scale,
+self.scale)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(
self.x, self.y, +1.0,
self.x, self.y, -1.0,
sin(self.angle), cos(self.angle), 0.0)
示例7: paint
def paint(self, func):
gl.glEnable(gl.GL_BLEND)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.gluOrtho2D(
0,
self.width,
0,
self.height
)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
gl.glViewport(0, 0, self.width, self.height)
gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT,
self.col_buffer.gl_buffer)
gl.glFramebufferTexture2DEXT(
gl.GL_DRAW_FRAMEBUFFER_EXT,
gl.GL_COLOR_ATTACHMENT0_EXT,
self.texture.target, self.texture.id, 0)
func()
gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, 0)
示例8: gl_setup
def gl_setup(): # general GL setup
glMatrixMode(GL_PROJECTION)
glMatrixMode(GL_MODELVIEW)
gluOrtho2D(0, WIDTH, 0, HEIGHT) # dont understand, check this # TODO
glLoadIdentity()
glTranslatef(CENTX, CENTY, 0)
glClear(GL_COLOR_BUFFER_BIT)
示例9: update
def update(self):
self.x += (self.target_x - self.x) * 0.1
self.y += (self.target_y - self.y) * 0.1
self.scale += (self.target_scale - self.scale) * 0.1
self.angle += (self.target_angle - self.angle) * 0.1
"Set projection and modelview matrices ready for rendering"
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(
-self.scale * self.aspect,
+self.scale * self.aspect,
-self.scale,
+self.scale)
# Set modelview matrix to move, scale & rotate to camera position"
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(
self.x, self.y, +1.0,
self.x, self.y, -1.0,
sin(self.angle), cos(self.angle), 0.0)
print 'gluLookAt:', self.x,self.y, self.angle
示例10: enable_2d
def enable_2d(self):
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.gluOrtho2D(0.0, self.width, 0.0, self.height)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
gl.glDisable(gl.GL_DEPTH_TEST)
gl.glDisable(gl.GL_CULL_FACE)
gl.glDisable(gl.GL_LIGHTING)
示例11: set_state
def set_state(self):
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glPushMatrix()
gl.glLoadIdentity()
gl.gluOrtho2D(0, self.window.width, 0, self.window.height)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glPushMatrix()
gl.glLoadIdentity()
示例12: bind_window
def bind_window(w, h):
gl.glBindFramebufferEXT(gl.GL_DRAW_FRAMEBUFFER_EXT, 0)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
gl.glViewport(0, 0, w, h)
gl.glScissor(0, 0, w, h);
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.gluOrtho2D(0, w, h, 0)
示例13: worldProjection
def worldProjection(self):
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
widthRatio = self.win.width / self.win.height
gluOrtho2D(
-self.zoom * widthRatio,
self.zoom * widthRatio,
-self.zoom,
self.zoom)
示例14: focus
def focus(self):
try:
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.gluOrtho2D(0, settings.GAME_WIDTH + PANEL_WIDTH, 0, settings.GAME_HEIGHT + HUD_HEIGHT)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
except Exception, e:
time.sleep(0.0001)
print(e, traceback.print_exc())
示例15: __enter__
def __enter__(self):
w, h = self.size
cx, cy = self.center
dx, dy = 0.5*self.get_pixel_extent()*(w, h)
gl.glViewport(0, 0, w, h)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.gluOrtho2D(cx-dx, cx+dx, cy-dy, cy+dy)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()