Class Renderer

java.lang.Object
dev.prozilla.pine.core.rendering.Renderer
All Implemented Interfaces:
Destructible, Initializable
Direct Known Subclasses:
HeadlessRenderer

public class Renderer extends Object implements Initializable, Destructible
Handles the rendering process.
  • Constructor Details

  • Method Details

    • init

      public void init()
      Description copied from interface: Initializable
      Initializes this object to prepare its usage.
      Specified by:
      init in interface Initializable
    • initPreview

      public void initPreview(int width, int height)
    • clear

      public void clear()
      Clears the drawing area.
    • begin

      public void begin() throws IllegalStateException
      Begin rendering.
      Throws:
      IllegalStateException
    • end

      public void end() throws IllegalStateException
      End rendering.
      Throws:
      IllegalStateException
    • flush

      public void flush()
      Flushes the data to the GPU to let it get rendered.
    • resetTransform

      public void resetTransform()
    • resetScale

      public void resetScale()
    • setScale

      public void setScale(float scale)
    • setScale

      public void setScale(Vector2f scale)
    • setMirrorHorizontally

      public void setMirrorHorizontally(boolean mirrorHorizontally)
    • setMirrorVertically

      public void setMirrorVertically(boolean mirrorVertically)
    • resetMirror

      public void resetMirror()
    • setRegion

      public void setRegion(float x, float y, float width, float height)
      Limits the rendering to the given region.
    • setRegion

      public void setRegion(int x, int y, int width, int height)
      Limits the rendering to the given region.
    • resetRegion

      public void resetRegion()
    • getDebugTextWidth

      public int getDebugTextWidth(CharSequence text)
      Calculates total width of a debug text.
      Parameters:
      text - The text
      Returns:
      Total width of the text
    • getDebugTextHeight

      public int getDebugTextHeight(CharSequence text)
      Calculates total height of a debug text.
      Parameters:
      text - The text
      Returns:
      Total width of the text
    • drawDebugText

      public void drawDebugText(CharSequence text, float x, float y)
      Draw debug text at the specified position.
      Parameters:
      text - TextRenderer to draw
      x - X coordinate of the text position
      y - Y coordinate of the text position
    • drawDebugText

      public void drawDebugText(CharSequence text, float x, float y, Color c)
      Draw debug text at the specified position and color.
      Parameters:
      text - TextRenderer to draw
      x - X coordinate of the text position
      y - Y coordinate of the text position
      c - Color to use
    • getTextSize

      public Vector2i getTextSize(CharSequence text)
    • getTextSize

      public Vector2i getTextSize(Font font, CharSequence text)
    • getTextWidth

      public int getTextWidth(CharSequence text)
    • getTextWidth

      public int getTextWidth(Font font, CharSequence text)
      Calculates total width of a text.
      Parameters:
      text - The text
      Returns:
      Total width of the text
    • getTextHeight

      public int getTextHeight(CharSequence text)
    • getTextHeight

      public int getTextHeight(Font font, CharSequence text)
      Calculates total height of a text.
      Parameters:
      text - The text
      Returns:
      Total width of the text
    • drawText

      public void drawText(CharSequence text, float x, float y, float z)
    • drawText

      public void drawText(Font font, CharSequence text, float x, float y, float z)
      Draw text at the specified position.
      Parameters:
      text - TextRenderer to draw
      x - X coordinate of the text position
      y - Y coordinate of the text position
    • drawText

      public void drawText(CharSequence text, float x, float y, float z, Color c)
    • drawText

      public void drawText(Font font, CharSequence text, float x, float y, float z, Color c)
      Draw text at the specified position and color.
      Parameters:
      text - TextRenderer to draw
      x - X coordinate of the text position
      y - Y coordinate of the text position
      c - Color to use
    • drawRect

      public void drawRect(float x, float y, float z, float width, float height)
      Draws a white rectangle at the given position.
      Parameters:
      x - X position
      y - Y position
      width - Width of the rectangle
      height - Height of the rectangle
    • drawRect

      public void drawRect(float x, float y, float z, float width, float height, Color c)
      Draws a colored rectangle at the given position.
      Parameters:
      x - X position
      y - Y position
      width - Width of the rectangle
      height - Height of the rectangle
      c - Color
    • drawRotatedTexture

      public void drawRotatedTexture(TextureAsset texture, float x, float y, float z, float r)
    • drawRotatedTexture

      public void drawRotatedTexture(TextureAsset texture, float x, float y, float z, Color c, float r)
    • drawTexture

      public void drawTexture(TextureAsset texture, float x, float y, float z)
      Draws a texture on specified coordinates.
      Parameters:
      texture - Used for getting width and height of the texture
      x - X position of the texture
      y - Y position of the texture
    • drawTexture

      public void drawTexture(TextureAsset texture, float x, float y, float z, Color c)
      Draws a texture on specified coordinates and with specified color.
      Parameters:
      texture - Used for getting width and height of the texture
      x - X position of the texture
      y - Y position of the texture
      c - The color to use
    • drawRotatedTextureRegion

      public void drawRotatedTextureRegion(TextureAsset texture, float x, float y, float z, float regX, float regY, float regWidth, float regHeight, float r)
    • drawRotatedTextureRegion

      public void drawRotatedTextureRegion(TextureAsset texture, float x, float y, float z, float regX, float regY, float regWidth, float regHeight, Color c, float r)
    • drawRotatedTextureRegion

      public void drawRotatedTextureRegion(TextureAsset texture, float x1, float y1, float x2, float y2, float z, float s1, float t1, float s2, float t2, float r)
    • drawRotatedTextureRegion

      public void drawRotatedTextureRegion(TextureAsset texture, float x1, float y1, float x2, float y2, float z, float s1, float t1, float s2, float t2, Color c, float r)
    • drawTextureRegion

      public void drawTextureRegion(TextureAsset texture, float x, float y, float z, float regX, float regY, float regWidth, float regHeight)
      Draws a texture region on specified coordinates.
      Parameters:
      texture - Used for getting width and height of the texture
      x - X position of the texture
      y - Y position of the texture
      regX - X position of the texture region
      regY - Y position of the texture region
      regWidth - Width of the texture region
      regHeight - Height of the texture region
    • drawTextureRegion

      public void drawTextureRegion(TextureAsset texture, float x, float y, float z, float regX, float regY, float regWidth, float regHeight, Color c)
      Draws a texture region on specified coordinates.
      Parameters:
      texture - Used for getting width and height of the texture
      x - X position of the texture
      y - Y position of the texture
      regX - X position of the texture region
      regY - Y position of the texture region
      regWidth - Width of the texture region
      regHeight - Height of the texture region
      c - The color to use
    • drawTextureRegion

      public void drawTextureRegion(TextureAsset texture, float x1, float y1, float x2, float y2, float z, float s1, float t1, float s2, float t2)
      Draws a texture region on specified coordinates.
      Parameters:
      x1 - Bottom left x position
      y1 - Bottom left y position
      x2 - Top right x position
      y2 - Top right y position
      s1 - Bottom left s coordinate
      t1 - Bottom left t coordinate
      s2 - Top right s coordinate
      t2 - Top right t coordinate
    • drawTextureRegion

      public void drawTextureRegion(TextureAsset texture, float x1, float y1, float x2, float y2, float z, float s1, float t1, float s2, float t2, Color c)
      Draws a texture region on specified coordinates.
      Parameters:
      x1 - Bottom left x position
      y1 - Bottom left y position
      x2 - Top right x position
      y2 - Top right y position
      s1 - Bottom left s coordinate
      t1 - Bottom left t coordinate
      s2 - Top right s coordinate
      t2 - Top right t coordinate
      c - The color to use
    • drawTextureRegion

      public void drawTextureRegion(TextureAsset texture, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float z, float s1, float t1, float s2, float t2, Color c)
      Draws a texture region on specified coordinates.
    • drawTriangles

      public void drawTriangles(TextureAsset texture, float[] vertices, float z, float[] uvArray, Color c)
      Draws multiple textured triangles using the given vertex and UV arrays.

      Each triangle is defined by 3 vertices (6 floats: x1, y1, x2, y2, x3, y3) and corresponding texture coordinates (u1, v1, u2, v2, u3, v3) from the UV array. The number of triangles drawn is determined by dividing the length of the vertex array by 6.

      Parameters:
      vertices - A flat float array containing x and y coordinates for each triangle vertex
      z - The depth value used when rendering each triangle
      uvArray - A flat float array containing the corresponding u and v texture coordinates. Must be the same length as vertices.
      Throws:
      IllegalArgumentException - if the length of vertices does not match uvArray
    • drawTriangle

      public void drawTriangle(TextureAsset texture, float x1, float y1, float x2, float y2, float x3, float y3, float z, float u1, float v1, float u2, float v2, float u3, float v3, Color c)
      Draws a single textured triangle with the given vertex coordinates, texture coordinates, depth value, and color.

      The triangle is defined by three points: (x1, y1), (x2, y2), and (x3, y3), with corresponding texture coordinates (u1, v1), (u2, v2), and (u3, v3).

      Parameters:
      x1 - The x-coordinate of the first vertex
      y1 - The y-coordinate of the first vertex
      x2 - The x-coordinate of the second vertex
      y2 - The y-coordinate of the second vertex
      x3 - The x-coordinate of the third vertex
      y3 - The y-coordinate of the third vertex
      z - The depth value
      u1 - The u texture coordinate for the first vertex
      v1 - The v texture coordinate for the first vertex
      u2 - The u texture coordinate for the second vertex
      v2 - The v texture coordinate for the second vertex
      u3 - The u texture coordinate for the third vertex
      v3 - The v texture coordinate for the third vertex
    • outOfBounds

      public boolean outOfBounds(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
      Checks if a quad is outside the screen bounds.
    • outOfBounds

      public boolean outOfBounds(float x1, float y1, float x2, float y2, float x3, float y3)
    • outOfBounds

      public boolean outOfBounds(float x1, float y1, float x2, float y2)
      Checks if a line is outside the screen bounds.
    • outOfBounds

      public boolean outOfBounds(float x, float y)
      Checks if coordinates are outside the screen bounds.
      Parameters:
      x - X position
      y - Y position
      Returns:
      True if the coordinate is outside of bounds
    • destroy

      public void destroy()
      Disposes renderer and cleans up its used data.
      Specified by:
      destroy in interface Destructible
    • resize

      public void resize()
      Updates the projection matrix according to the window's dimensions.
    • getWidth

      public int getWidth()
    • getHeight

      public int getHeight()
    • isRendering

      public boolean isRendering()
    • getFrameBufferObject

      public FrameBufferObject getFrameBufferObject()
    • getConfig

      public RenderConfig getConfig()
    • getFallbackColor

      public Color getFallbackColor()
    • getViewportCenter

      @Contract("-> new") public Vector2f getViewportCenter()
      Creates a new Vector2f that represents the center of the viewport.