hlg

package module
v0.0.0-...-4142f2f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 14 Imported by: 0

README

hlg (High Level Graphics)

This project is a WIP. The goal is to make a high level graphics api for golang.

Go Reference Documentation: https://dfirebaugh.github.io/hlg/

Examples

check the ./examples dir for some basic examples

Triangle
package main

import (
	"github.com/dfirebaugh/hlg"
	"golang.org/x/image/colornames"
)

func main() {
	hlg.SetWindowSize(720, 480)
	hlg.SetScreenSize(240, 160)
	t := hlg.Triangle(0, 160, 120, 0, 240, 160, colornames.Orangered)

	hlg.Update(func() {
		hlg.Clear(colornames.Skyblue)
		t.Render()
	})
}

triangle_example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Circle

func Circle(x, y int, radius float32, c color.Color) graphics.Shape

Circle creates a circle shape with specified center, radius, and color. x, y define the center of the circle. radius defines the radius of the circle. c specifies the color of the circle.

func Clear

func Clear(c color.RGBA)

Clear clears the screen with the specified color.

func DisableFPS

func DisableFPS()

DisableFPS disables the FPS counter in the window title.

func EnableFPS

func EnableFPS()

EnableFPS enables the FPS counter in the window title.

func GetCursorPosition

func GetCursorPosition() (int, int)

func GetFPS

func GetFPS() float64

func GetScreenSize

func GetScreenSize() (int, int)

func GetWindowPosition

func GetWindowPosition() (int, int)

func GetWindowSize

func GetWindowSize() (int, int)

GetWindowSize retrieves the current window size.

func IsButtonPressed

func IsButtonPressed(buttonCode input.MouseButton) bool

func IsKeyPressed

func IsKeyPressed(keyCode input.Key) bool

func Line

func Line(x1, y1, x2, y2 int, width float32, c color.Color) graphics.Shape

Line creates a line with specified start and end points, width, and color. x1, y1 define the start point of the line. x2, y2 define the end point of the line. width defines the thickness of the line. c specifies the color of the line.

func Polygon

func Polygon(x, y int, width float32, sides int, c color.Color) graphics.Shape

Polygon creates a polygon shape with a specified number of sides, position, width, and color. x, y define the center of the polygon. width defines the diameter of the circumcircle of the polygon. sides specify the number of sides (vertices) of the polygon. c specifies the color of the polygon.

func PressButton

func PressButton(buttonCode input.MouseButton)

func PressKey

func PressKey(keyCode input.Key)

func PrintAt

func PrintAt(s string, x int, y int, c color.Color)

PrintAt renders text at a specified position with a specified color. s is the string to be rendered. x, y define the position where the text will be rendered. c specifies the color of the text.

func Rectangle

func Rectangle(x, y, width, height int, c color.Color) graphics.Shape

Rectangle creates a rectangle shape with specified position, dimensions, and color. x, y define the top-left corner of the rectangle. width, height define the dimensions of the rectangle. c specifies the color of the rectangle.

func ReleaseButton

func ReleaseButton(buttonCode input.MouseButton)

func ReleaseKey

func ReleaseKey(keyCode input.Key)

func SetScreenSize

func SetScreenSize(width, height int)

SetScreenSize sets the size of the screen.

func SetScrollCallback

func SetScrollCallback(cb func(x float64, y float64))

func SetTitle

func SetTitle(title string)

SetTitle sets the title of the window.

func SetWindowSize

func SetWindowSize(width, height int)

SetWindowSize sets the size of the window.

func Triangle

func Triangle(x1, y1, x2, y2, x3, y3 int, c color.Color) graphics.Shape

Triangle creates a triangle shape with specified vertices and color. x1, y1, x2, y2, x3, y3 define the coordinates of the three vertices of the triangle. c specifies the color of the triangle.

func Update

func Update(updateFn func())

Update is the main update function called to refresh the engine state.

Types

type Shape

type Shape interface {
	graphics.Shape
}

type Sprite

type Sprite struct {
	*Texture
	// contains filtered or unexported fields
}

func NewSprite

func NewSprite(img image.Image, frameSize, sheetSize image.Point) *Sprite

func (*Sprite) NextFrame

func (s *Sprite) NextFrame()

type Texture

type Texture struct {
	graphics.Texture
}

func CreateTexture

func CreateTexture(x, y, w, h int) (*Texture, error)

func CreateTextureFromImage

func CreateTextureFromImage(img image.Image) (*Texture, error)

func (Texture) Destroy

func (t Texture) Destroy()

Destroy removes the texture from the renderer

func (*Texture) UpdateTextureFromImage

func (t *Texture) UpdateTextureFromImage(img image.Image)

Directories

Path Synopsis
examples
Package graphics provides functionality for 2D graphics rendering, including textures, sprites, text, and shapes.
Package graphics provides functionality for 2D graphics rendering, including textures, sprites, text, and shapes.
webgpu/internal/surface
The surface package provides a virtual screen to render things to.
The surface package provides a virtual screen to render things to.
pkg
component
The component package has some basic structs that are common in games (e.g.
The component package has some basic structs that are common in games (e.g.
draw
draw is a package from drawing with the cpu
draw is a package from drawing with the cpu
fb
The fb package provides a framebuffer abstraction.
The fb package provides a framebuffer abstraction.
math/geom
The geom package provides basic geometry types and functions.
The geom package provides basic geometry types and functions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL