- All Known Implementing Classes:
SoftwareRenderer
@NullMarked
public interface Renderer
Renderer defines the API for a sola game engine renderer.
SoftwareRenderer is the default implementation but
each SolaPlatform can implement their own as well to take advantage of the GPU.-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclear()Sets all pixels toColor.BLACKvoidSets all pixels to desiredColor.default voidcreateLayers(String... layerNames) Creates new layers for drawing on.createRendererForImage(SolaImage solaImage) Creates a new Renderer instance that draws to aSolaImageinstead of the screen.voiddrawCircle(float x, float y, float radius, Color color) Draws an unfilled circle.voidDraws aSolaImageat desired coordinate.voidDraws aSolaImagescaled to fit within a rectangle specified by x,y, width and height.voiddrawImage(SolaImage solaImage, AffineTransform affineTransform) Draws aSolaImagewithAffineTransformapplied.voidDraws a line.default voiddrawPolygon(Vector2D[] points, Color color) Draws a polygon.voidDraws an unfilled rectangle.default voiddrawString(String text, float x, float y, Color color) Draws a string of text using the currentFont.default voiddrawString(String text, AffineTransform affineTransform, Color color) Draws a string of text using the currentFontand applies the desiredAffineTransformto the rendered string.default voiddrawToLayer(String layerName, int order, DrawItem drawItem) Adds aDrawItemto a layer at desired order.default voiddrawToLayer(String layerName, DrawItem drawItem) Adds aDrawItemto a layer at default order.default voiddrawTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Color color) Draws a triangle.voidfillCircle(float x, float y, float radius, Color color) Draws a filled circle.voidfillPolygon(Vector2D[] points, Color color) Draws a filled polygon.voidDraws a filled rectangle.voidfillTriangle(float x1, float y1, float x2, float y2, float x3, float y3, Color color) Draws a filled triangle.getFont()intdefault LayerGets aLayerby name.intgetWidth()default voidResets the rendering clamp to the full size of theRenderer.voidsetBlendFunction(BlendFunction blendFunction) Sets theBlendFunctionthat should be used.voidsetClamp(int x, int y, int width, int height) Restricts rendering of pixels within a rectangle.voidSets theFontto use when drawing text.default voidsetPixel(int x, int y, int color) Sets theColorof a pixel at coordinate.voidSets theColorof a pixel at coordinate.
-
Method Details
-
setBlendFunction
Sets theBlendFunctionthat should be used.- Parameters:
blendFunction- the newBlendModeto use
-
getBlendFunction
BlendFunction getBlendFunction()- Returns:
- the current
BlendFunctionbeing used when drawing
-
getFont
Font getFont()- Returns:
- the current
Fontbeing used for drawing text
-
setFont
Sets theFontto use when drawing text.- Parameters:
font- the newFontto use
-
getWidth
int getWidth()- Returns:
- the width of the
Renderer
-
getHeight
int getHeight()- Returns:
- the height of the
Renderer
-
createRendererForImage
Creates a new Renderer instance that draws to aSolaImageinstead of the screen.- Parameters:
solaImage- the image to draw to- Returns:
- a new renderer instance drawing to an image
-
createLayers
Creates new layers for drawing on.- Parameters:
layerNames- the names of the layers to create
-
getLayers
-
getLayer
Gets aLayerby name.- Parameters:
name- the name of the layer to get- Returns:
- the layer
-
drawToLayer
Adds aDrawItemto a layer at default order.- Parameters:
layerName- name of the layer to add draw item todrawItem- the draw item
-
drawToLayer
Adds aDrawItemto a layer at desired order. Higher order render later.- Parameters:
layerName- name of the layer to add draw item toorder- the order of the draw itemdrawItem- the draw item
-
setClamp
void setClamp(int x, int y, int width, int height) Restricts rendering of pixels within a rectangle. Any setPixel call outside of this rectangle will be ignored.- Parameters:
x- top left coordinate xy- top left coordinate ywidth- width of the rectangleheight- height of the rectangle
-
resetClamp
default void resetClamp()Resets the rendering clamp to the full size of theRenderer. -
clear
default void clear()Sets all pixels toColor.BLACK -
clear
Sets all pixels to desiredColor.- Parameters:
color- theColorto set all pixels to
-
setPixel
Sets theColorof a pixel at coordinate.- Parameters:
x- the x coordinate of the pixely- the y coordinate of the pixelcolor- the newColor
-
setPixel
default void setPixel(int x, int y, int color) Sets theColorof a pixel at coordinate.- Parameters:
x- the x coordinate of the pixely- the y coordinate of the pixelcolor- the newColor
-
drawString
Draws a string of text using the currentFont.- Parameters:
text- the text to drawx- the x coordinate to draw it aty- the y coordinate to draw it atcolor- theColorof the text
-
drawString
Draws a string of text using the currentFontand applies the desiredAffineTransformto the rendered string.- Parameters:
text- the text to drawaffineTransform- the transform to applycolor- theColorof the text
-
drawLine
Draws a line.- Parameters:
x- the x coordinate of the first pointy- the y coordinate of the first pointx2- the x coordinate of the second pointy2- the y coordinate of the second pointcolor- theColorof the line
-
drawRect
Draws an unfilled rectangle.- Parameters:
x- top left coordinate xy- top left coordinate ywidth- width of the rectangleheight- height of the rectanglecolor-Colorof the rectangle
-
fillRect
Draws a filled rectangle.- Parameters:
x- top left coordinate xy- top left coordinate ywidth- width of the rectangleheight- height of the rectanglecolor-Colorof the rectangle
-
drawCircle
Draws an unfilled circle. Uses Bresenham's circle drawing algorithm.- Parameters:
x- top left coordinate xy- top left coordinate yradius- radius of the circlecolor-Colorof the circle
-
fillCircle
Draws a filled circle.- Parameters:
x- top left coordinate xy- top left coordinate yradius- radius of the circlecolor-Colorof the circle
-
drawTriangle
Draws a triangle.- Parameters:
x1- x coordinate for the first pointy1- y coordinate for the first pointx2- x coordinate for the second pointy2- y coordinate for the second pointx3- x coordinate for the third pointy3- y coordinate for the third pointcolor-Colorof the triangle
-
fillTriangle
Draws a filled triangle.- Parameters:
x1- x coordinate for the first pointy1- y coordinate for the first pointx2- x coordinate for the second pointy2- y coordinate for the second pointx3- x coordinate for the third pointy3- y coordinate for the third pointcolor-Colorof the triangle
-
drawPolygon
Draws a polygon.- Parameters:
points- the points of the polygoncolor- theColorof the polygon
-
fillPolygon
Draws a filled polygon.- Parameters:
points- the points of the polygoncolor- theColorof the polygon
-
drawImage
Draws aSolaImageat desired coordinate. The coordinate will be the top-left of the image drawn.- Parameters:
solaImage- theSolaImageto drawx- top left coordinate xy- top left coordinate y
-
drawImage
Draws aSolaImagewithAffineTransformapplied.- Parameters:
solaImage- theSolaImageto drawaffineTransform- the transform to apply
-
drawImage
Draws aSolaImagescaled to fit within a rectangle specified by x,y, width and height.- Parameters:
solaImage- theSolaImageto drawx- top left coordinate x of the scaling rectangley- top left coordinate y of the scaling rectanglewidth- the width of the scaling rectangleheight- the height of the scaling rectangle
-