Artenus 2D Framework
Artenus Reference

Interface for a rendering context. It provides methods to control the state of the graphics engine, and draw sprites. Methods in this interface are meant for a 2-dimensional environment.

This interface is used internally by entities and textures to render graphics. There are rare cases where game developers need to make use of this interface. These rare cases include developing a new type of sprite which is not provided by the framework, or a new post-processing filter. In such scenarios it is necessary to use this class instead of calling OpenGL ES functions directly. This ensures that your sprite implementation is compatible with the rest of the framework. Only call OpenGL functions if what you intend to do cannot be done using the methods in this class.

public interface RenderingContext

Method Summary

Modifier and TypeMethod and Description
public voidbindTarget(RenderTarget target)
Binds a render target to this context to receive the output image.
public voidclear(float r, float g, float b)
Clears the the current render target and fills it with the specified color.
public floatgetHeight()
Gets the logical height of the context.
public floatgetMatrix()
Gets the current transformation matrix that is used for drawing.
public intgetScreenHeight()
Gets the real and unscaled height of the rendering area, which is normally the screen height in a full-screen application.
public intgetScreenWidth()
Gets the real and unscaled width of the rendering area, which is normally the screen width in a full-screen application.
public ShaderProgramgetShader()
Gets the shader program currently assigned to the rendering context.
public floatgetWidth()
Gets the logical width of the context.
public voididentity()
Sets the current matrix to identity, canceling any previous transformation.
public voidpopMatrix()

Pops the matrix at the top of the transformation matrix stack.

public voidpushMatrix()
Pushes a matrix on top of the transformation matrix stack.
public voidpushMatrix(float[] mat)
Pushes a pre-computed matrix on top of the transformation matrix stack.
public voidrect()
Draws the default rectangular primitive with the given state of the rendering context.
public voidrotate(float angle)
Rotates the current matrix with the given angle.
public voidscale(float x, float y)
Scales the current matrix with given factors.
public voidsetColorFilter(float r, float g, float b, float a)
Sets the color filter for the given context.
public voidsetShader(ShaderProgram shader)

Sets the shader program for the rendering context.

public voidtranslate(float x, float y)
Translates the current matrix the given distance.

Method Detail

bindTarget
public void bindTarget(
    RenderTarget target
)
Binds a render target to this context to receive the output image. If no render target is specified, the target will be set to the screen. Binding render targets is an advanced feature which is usually not needed in a game.
Parameters:
targetThe render target, or null to switch to screen rendering
clear
public void clear(
    float r,
    float g,
    float b
)
Clears the the current render target and fills it with the specified color.
Parameters:
rRed component of the clear color
gGreen component of the clear color
bBlue component of the clear color
getHeight
public float getHeight()
Gets the logical height of the context. Artenus unifies provides uniform graphics on various screen sizes. The logical screen dimensions are device-independent.
Returns:
The height in texels
getMatrix
public float getMatrix()
Gets the current transformation matrix that is used for drawing. This is a low-level method and is usually not needed for a game.
Returns:
The transformation matrix
getScreenHeight
public int getScreenHeight()
Gets the real and unscaled height of the rendering area, which is normally the screen height in a full-screen application.
Returns:
The height of the rendering area
getScreenWidth
public int getScreenWidth()
Gets the real and unscaled width of the rendering area, which is normally the screen width in a full-screen application.
Returns:
The width of the rendering area
getShader
public ShaderProgram getShader()
Gets the shader program currently assigned to the rendering context.
Returns:
The active shader program
getWidth
public float getWidth()
Gets the logical width of the context. Artenus unifies provides uniform graphics on various screen sizes. The logical screen dimensions are device-independent.
Returns:
The width in texels
identity
public void identity()
Sets the current matrix to identity, canceling any previous transformation. Calling this method is useful only in rare cases. It is normally enough to use the matrix stack to revert transformations.
popMatrix
public void popMatrix()

Pops the matrix at the top of the transformation matrix stack. The effective matrix will be the one underneath. Calling this method when there is only one matrix in the stack has no effect, and does not throw any exceptions.

You need to be careful to pop as many matrices as you push. The framework and all renderables share the same rendering context. An imbalanced stack usage may cause unexpected rendering results.

pushMatrix
public void pushMatrix()
Pushes a matrix on top of the transformation matrix stack. Subsequent transformation calls will only affect the top of the stack, leaving the rest of the matrices in the stack intact.
pushMatrix
public void pushMatrix(
    float[] mat
)
Pushes a pre-computed matrix on top of the transformation matrix stack. The argument can be the return value of getMatrix().
Parameters:
matThe new transformation matrix
rect
public void rect()
Draws the default rectangular primitive with the given state of the rendering context. It is up to the shader program to decide where and how this rectangle is drawn, given the state of the rendering context.
rotate
public void rotate(
    float angle
)
Rotates the current matrix with the given angle.
Parameters:
angleRotation angle in degrees
scale
public void scale(
    float x,
    float y
)
Scales the current matrix with given factors.
Parameters:
xScaling factor along the x axis
yScaling factor along the y axis
setColorFilter
public void setColorFilter(
    float r,
    float g,
    float b,
    float a
)
Sets the color filter for the given context. The behavior of this method depends on the shader program. But all shader programs in Artenus are required to accept color filters in some way.
Parameters:
rThe red component of the color filter
gThe green component of the color filter
bThe blue component of the color filter
aThe alpha component of the color filter, which determines the transparency
setShader
public void setShader(
    ShaderProgram shader
)

Sets the shader program for the rendering context. All graphical method calls after calling this method will work with the shader specified. Using this method correctly is crucial to compatibility with the framework. The following are the rules that apply to all renderables using this method:

  • All renderables need to set the program shader before drawing anything.
  • Some aspects of the rendering context are reset after setting a shader, so it is recommended to be the first call in render(RenderingContext, int).
  • If the render method is called with FLAG_PRESERVE_SHADER_PROGRAM filter, no shader program should be applied. The system uses this flag to render objects in plain graphics, for effects or touch maps. Setting a shader when this flag is on causes instability in the system.
  • As all renderables are required to set their own shader programs in the beginning of the rendering process, there is no need to reset the program when rendering is finished.
Parameters:
shaderThe shader program, or null to use the default program
translate
public void translate(
    float x,
    float y
)
Translates the current matrix the given distance.
Parameters:
xThe distance along the x axis
yThe distance along the y axis