Statements: OpenGL statement for the “with” keyword

Statements: OpenGL statement for the “with” keyword

Save and restore the matrix

with gx_matrix:
    glTranslatef(55, 34, 0)
    # draw stuff
# here, the matrix will be restored as previous state

Modify a display list (compiled OpenGL operations)

dl = GlDisplayList()
with dl:
    # draw stuff
# here you can call the display list
dl.draw()

Bind a texture and draw with OpenGL

with DO(gx_texture(my_texture), gx_begin(GL_TRIANGLE_FAN)):
    # call multiple time glVertex2f()

Save and restore the color after drawing

set_color(1, 0, 0) # color is red.
with gx_color(0, 1, 0):
    # here the color is green
    # draw stuff
    pass
# here the color is restored back to red
class pymt.graphx.statement.DO(*args)

A way to do multiple action in with statement

with DO(stmt1, stmt2):
    print 'something'
class pymt.graphx.statement.GlDisplayList(**kwargs)

Abstraction to opengl display-list usage. Here is an example of usage

dl = GlDisplayList()
with dl:
    # do draw function, like drawLabel etc...
dl.draw()
Parameters :
mode : str, default to ‘compile’

If mode is ‘execute’, the code in with will be also compiled + executed.

clear()

Clear compiled flag

draw()

Call the list only if it’s compiled

is_compiled()

Return compiled flag

start()

Start recording GL operation

stop()

Stop recording GL operation

class pymt.graphx.statement.GlBlending(sfactor=GL_SRC_ALPHA, dfactor=GL_ONE_MINUS_SRC_ALPHA)

Abstraction to use blending ! Don’t use directly this class. We’ve got an alias you can use

with gx_blending:
    # do draw function
class pymt.graphx.statement.GlMatrix(matrixmode=GL_MODELVIEW, do_loadidentity=False)

Statement of glPushMatrix/glPopMatrix, designed to be use with “with” keyword.

Alias: gx_matrix, gx_matrix_identity

with gx_matrix:
    # do draw function

with gx_matrix_identity:
    # do draw function
class pymt.graphx.statement.GlEnable(flag)

Statement of glEnable/glDisable, designed to be use with “with” keyword.

Alias: gx_enable.

class pymt.graphx.statement.GlBegin(flag)

Statement of glBegin/glEnd, designed to be use with “with” keyword

Alias: gx_begin.

class pymt.graphx.statement.GlAttrib(flag)

Statement of glPushAttrib/glPopAttrib, designed to be use with “with” keyword

Alias: gx_attrib.

class pymt.graphx.statement.GlColor(r, g, b, a=None)

Statement of glPushAttrib/glPopAttrib on COLOR BUFFER + color, designed to be use with “with” keyword

Alias: gx_color.

class pymt.graphx.statement.GlTexture(texture)

Statement of setting a texture

Alias: gx_texture.

bind()

Bind the texture on the current context / texture unit

get_id()

Return the GL id of texture

get_target()

Get the GL target of the texture

release()

Release the current attribute from the binded texture

pymt.graphx.statement.gx_blending

Alias to GlBlending()

pymt.graphx.statement.gx_alphablending

Alias to GlBlending(sfactor=GL_DST_COLOR, dfactor=GL_ONE_MINUS_SRC_ALPHA)

pymt.graphx.statement.gx_matrix

Alias to GlMatrix()

pymt.graphx.statement.gx_matrix_identity

Alias to GlMatrix(do_loadidentity=True)

pymt.graphx.statement.gx_enable

alias of GlEnable

pymt.graphx.statement.gx_begin

Alias to GlBegin

alias of GlBegin

pymt.graphx.statement.gx_attrib

Alias to GlAttrib

alias of GlAttrib

pymt.graphx.statement.gx_color

Alias to GlColor

alias of GlColor

pymt.graphx.statement.gx_texture

Alias to GlTexture

alias of GlTexture

pymt.graphx.statement.gx_blending_replace

Repalce the content with the source content

Previous topic

Shader: abstract compilation and usage

Next topic

Stencil: use stencil for mask drawing

This Page