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 ¶
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.
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 ¶
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 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 (*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 ¶
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 ¶
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 DrawImage ¶
type DrawImage struct { Image *AtlasChunk // contains filtered or unexported fields }
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