luapixels

package module
v0.0.0-...-48757e5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: BSD-3-Clause Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

luapixels

The beginnings of what could be a game engine for using GLFW + Go + Lua.

Example use

main.go:

package main

import (
    "log"

    _ "embed"

    "github.com/xyproto/luapixels"
)

//go:embed game.lua
var luaCode string

func main() {
    if err := luapixels.Run(luaCode); err != nil {
        log.Fatalln(err)
    }
}

game.lua:

window_title = "Simple Example"

function at_start()
  print("hi")
  -- Set color at palette index 7 to red (RGB 255, 0, 0)
  setpal(7, 255, 0, 0)
end

function at_every_frame()
  -- Set the background color to blue (RGB 0, 128, 255)
  background(0, 128, 255)
  -- At (100, 100), draw a red pixel (index 7 in the palette)
  plot(100, 100, 7)
end

function at_key_pressed()
  quit()
end

function at_end()
  print("bye!")
end
Performance

There is a lot of room for improvements when it comes to performance, since this implementation is fresh and not yet optimized.

The pixels are quads right now, but a texture could be used instead. This would require no changes from the Lua code, though.

General info
  • License: BSD-3
  • Version: 0.0.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallLuaFunction

func CallLuaFunction(L *lua.LState, funcName string) error

CallLuaFunction calls a Lua function by name.

func ClearScreen

func ClearScreen()

ClearScreen clears the window.

func DrawBackground

func DrawBackground(r, g, b byte)

DrawBackground sets the entire background to a specified color

func GLSetColor

func GLSetColor(c color.RGBA)

glSetColor will set the current OpenGL color

func GetLuaGlobalString

func GetLuaGlobalString(L *lua.LState, variableName string) (string, error)

GetLuaGlobalString fetches the value of a global Lua variable as a string.

func GetPaletteColor

func GetPaletteColor(colorIndex byte) (byte, byte, byte)

GetPaletteColor retrieves the r,g,b colors of a given palette index.

func GetPixel

func GetPixel(x, y int) byte

GetPixel returns the color index of the given (x,y) position

func InitAudio

func InitAudio() error

InitAudio initializes the miniaudio context.

func InitGL

func InitGL(window *glfw.Window) error

func PlaySound

func PlaySound(frequency float32, duration int) error

func PutPixel

func PutPixel(x, y int, colorIndex byte)

PutPixel places a pixel with the given colorIndex

func Run

func Run(luaCode string) error

Run is for running luapixel Lua code, given as a string

func RunFile

func RunFile(luaFilename string) error

RunFile is for running luapixel Lua code, given a filename

func SetPaletteColor

func SetPaletteColor(colorIndex, r, g, b byte)

SetPaletteColor sets a color in the palette.

func UpdateScreen

func UpdateScreen(window *glfw.Window)

UpdateScreen swaps the buffers and displays the rendered frame.

Types

type PixelSlice

type PixelSlice [width * height]byte

Directories

Path Synopsis
cmd
audio command
classic command
getpixel command
multijump command
simple command

Jump to

Keyboard shortcuts

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