- 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 void
clear()
Sets all pixels toColor.BLACK
void
Sets all pixels to desiredColor
.default void
createLayers
(String... layerNames) Creates new layers for drawing on.createRendererForImage
(SolaImage solaImage) Creates a new Renderer instance that draws to aSolaImage
instead of the screen.void
drawCircle
(float x, float y, float radius, Color color) Draws an unfilled circle.void
Draws aSolaImage
at desired coordinate.void
Draws aSolaImage
scaled to fit within a rectangle specified by x,y, width and height.void
drawImage
(SolaImage solaImage, AffineTransform affineTransform) Draws aSolaImage
withAffineTransform
applied.void
Draws a line.void
Draws an unfilled rectangle.default void
drawString
(String text, float x, float y, Color color) Draws a string of text using the currentFont
.default void
drawString
(String text, AffineTransform affineTransform, Color color) Draws a string of text using the currentFont
and applies the desiredAffineTransform
to the rendered string.default void
drawToLayer
(String layerName, int order, DrawItem drawItem) Adds aDrawItem
to a layer at desired order.default void
drawToLayer
(String layerName, DrawItem drawItem) Adds aDrawItem
to a layer at default order.default void
drawTriangle
(float x1, float y1, float x2, float y2, float x3, float y3, Color color) Draws a triangle.void
fillCircle
(float x, float y, float radius, Color color) Draws a filled circle.void
Draws a filled rectangle.void
fillTriangle
(float x1, float y1, float x2, float y2, float x3, float y3, Color color) Draws a filled triangle.getFont()
int
default Layer
Gets aLayer
by name.int
getWidth()
default void
Resets the rendering clamp to the full size of theRenderer
.void
setBlendFunction
(BlendFunction blendFunction) Sets theBlendFunction
that should be used.void
setClamp
(int x, int y, int width, int height) Restricts rendering of pixels within a rectangle.void
Sets theFont
to use when drawing text.default void
setPixel
(int x, int y, int color) Sets theColor
of a pixel at coordinate.void
Sets theColor
of a pixel at coordinate.
-
Method Details
-
setBlendFunction
Sets theBlendFunction
that should be used.- Parameters:
blendFunction
- the newBlendMode
to use
-
getBlendFunction
BlendFunction getBlendFunction()- Returns:
- the current
BlendFunction
being used when drawing
-
getFont
Font getFont()- Returns:
- the current
Font
being used for drawing text
-
setFont
Sets theFont
to use when drawing text.- Parameters:
font
- the newFont
to 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 aSolaImage
instead 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 aLayer
by name.- Parameters:
name
- the name of the layer to get- Returns:
- the layer
-
drawToLayer
Adds aDrawItem
to a layer at default order.- Parameters:
layerName
- name of the layer to add draw item todrawItem
- the draw item
-
drawToLayer
Adds aDrawItem
to 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
- theColor
to set all pixels to
-
setPixel
Sets theColor
of 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 theColor
of 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
- theColor
of the text
-
drawString
Draws a string of text using the currentFont
and applies the desiredAffineTransform
to the rendered string.- Parameters:
text
- the text to drawaffineTransform
- the transform to applycolor
- theColor
of 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
- theColor
of 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
-Color
of 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
-Color
of 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
-Color
of the circle
-
fillCircle
Draws a filled circle.- Parameters:
x
- top left coordinate xy
- top left coordinate yradius
- radius of the circlecolor
-Color
of 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
-Color
of 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
-Color
of the triangle
-
drawImage
Draws aSolaImage
at desired coordinate. The coordinate will be the top-left of the image drawn.- Parameters:
solaImage
- theSolaImage
to drawx
- top left coordinate xy
- top left coordinate y
-
drawImage
Draws aSolaImage
withAffineTransform
applied.- Parameters:
solaImage
- theSolaImage
to drawaffineTransform
- the transform to apply
-
drawImage
Draws aSolaImage
scaled to fit within a rectangle specified by x,y, width and height.- Parameters:
solaImage
- theSolaImage
to 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
-