opala

package
v0.0.0-...-cf82ea8 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Opala is a 2d render engine.

The engine don't handle physics, sounds, etc.., just how you put rectangles with textures on the screen

This engine uses opengl and a orthographic camera, ie, no visible z difference, only rectangles can be placed on screen but you can use any image as texture, so you can draw circles, triangles, etc...

Index

Constants

View Source
const (
	AtlasIsFull         = Error("atlas is full")
	CountMustBePositive = Error("count must be positive")
	GlfwUnableToInit    = Error("unable to initialize glfw. check the log")
)

Variables

This section is empty.

Functions

func AcquireInput

func AcquireInput()

AcquireInput read input from the user devices (keyboards, mouse, gampepads).

The input handling isn't done via triggers or channels but instead should be checked each frame.

This function should be called at least one time each frame.

func Vsync

func Vsync(vsync bool)

Types

type Atlas

type Atlas struct {
	// contains filtered or unexported fields
}

Atlas holds a large texture in memory and enable users to ask for chunks of the image.

The size of each chunk is fixed, this might require more atlases to be created bug makes the code here much more easier to understand.

TODO: maybe this should be more generic and work with other image formats, but at this moment just image.RGBA is supported

func NewAtlas

func NewAtlas(width, height, nRows, nColumns int) *Atlas

NewAtlas will create a new atlas with enough space to at least nRows X nColumns chunks of widthXheight size. The total number of chunks are determinated by the power of two rule below.

The actual memory used might be larger since all atlas MUST BE a power of 2 rect (16, 32, 64, 128...). But the rectangle used by the chunk is limited to width/height.

func (*Atlas) AllocateDefault

func (a *Atlas) AllocateDefault(name string) (*AtlasChunk, error)

func (*Atlas) AllocateMany

func (a *Atlas) AllocateMany(prefix string, count int) ([]*AtlasChunk, error)

AllocateMany will try to allocate at most count chunks and return the slice with allocated chunks.

If an error happens the slice will hold the chunks that could be allocated before the error.

Chunks are named by concatenating prefix + "-" + index

func (*Atlas) ChunkAt

func (a *Atlas) ChunkAt(row, column int) *AtlasChunk

ChunkAt returns the chunk at the given row and column if no chunk is found, returns nil

type AtlasChunk

type AtlasChunk struct {
	// contains filtered or unexported fields
}

hold the information about a chunk of an atlas

func (*AtlasChunk) Fill

func (ic *AtlasChunk) Fill(c color.Color)

func (*AtlasChunk) FromPNG

func (ic *AtlasChunk) FromPNG(file string) error

func (*AtlasChunk) Size

func (ic *AtlasChunk) Size() (w, h int)

func (*AtlasChunk) Sizef

func (ic *AtlasChunk) Sizef() (w, h float32)

func (*AtlasChunk) String

func (ic *AtlasChunk) String() string

func (*AtlasChunk) UVRect

func (ic *AtlasChunk) UVRect() UVRect

type ClearCmd

type ClearCmd struct{}

func (ClearCmd) Name

func (c ClearCmd) Name() string

func (ClearCmd) Render

func (c ClearCmd) Render(d *Display) error

type Display

type Display struct {
	// contains filtered or unexported fields
}

Display is where the interaction between player and game happens.

A display usually renders a world that is composed by objects.

func NewDisplay

func NewDisplay(width, height int, title string) (*Display, error)

func (*Display) Close

func (d *Display) Close()

func (*Display) Render

func (d *Display) Render()

Render will read the renderQueue and redraw them on the screen after this the renderQueue is empty.

func (*Display) SendDraw

func (d *Display) SendDraw(cmd DrawCmd)

SendDraw receives a DrawCmd and enqueue for later rendering.

The order of rendering is determinated by the Render function and it might or might not be the order of SendDraw.

This method is safe to be used by multiple threads.

func (*Display) ShouldClose

func (d *Display) ShouldClose() bool

ShouldClose returns true when the window should be closed. This is usually a result of the user pressing the close button.

type DisplayList

type DisplayList []*Display

func NewDisplayList

func NewDisplayList() *DisplayList

func (*DisplayList) Push

func (dl *DisplayList) Push(d ...*Display)

func (*DisplayList) Remove

func (dl *DisplayList) Remove(d *Display)

func (*DisplayList) Render

func (dl *DisplayList) Render()

func (*DisplayList) ShouldClose

func (dl *DisplayList) ShouldClose() bool

ShouldClose returns true when every window on this display is should be closed.

Windows marked to be closed are removed from this list

type DrawCmd

type DrawCmd interface {
	Name() string
	Render(d *Display) error
}

type DrawImage

type DrawImage struct {
	Image *AtlasChunk
	// contains filtered or unexported fields
}

func (*DrawImage) Name

func (d *DrawImage) Name() string

func (*DrawImage) Render

func (d *DrawImage) Render(display *Display) error

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type Object

type Object struct {
	// The piece of the atlas that should
	// be used to render this object
	Atlas *AtlasChunk

	// A color to paint over the texture
	Tint color.Color
	// contains filtered or unexported fields
}

Object is a object that can be renderd at a give location

type Tick

type Tick struct {
	// contains filtered or unexported fields
}

Tick holds information about display rendering times

type UVRect

type UVRect struct {
	// TopLeft (TL), TopRigth (TR), BottomLeft (BL), BottomRight (BR)
	TL, TR, BL, BR glm.Vector2
}

UVRect represent the coordinate system for used by OpenGL

Jump to

Keyboard shortcuts

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