gome

package module
v0.0.0-...-1050381 Latest Latest
Warning

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

Go to latest
Published: May 7, 2017 License: MIT Imports: 12 Imported by: 11

README

Gome (Golang game engine)

Overview

Gome is a pet project of mine. I took a graphics course in college and am now re-learning by implementing it myself. This project is certainly pre-alpha so I don't recommend depending on anything in it.

I'm not attempting to develop a full featured engine like Unreal or Unity, but I hope to eventually support enough of the basics to implement a networked game with simple physics. I chose Go because I appreciate its simplicity and find it pleasant to work with. It also has GopherJS, which allows programs developed in Go to be compiled not only into regular binaries, but also into javascript. With the github.com/goxjs/gl and glfw packages, this allows the same OpenGL shaders to be compiled for both desktop and webgl (see the gome shader package).

Some of my GopherJS demos are hosted at https://omustardo.github.io/ but note that not all of them were made using gome.

Usage

I recommend looking in the demos folder. To run a demo:

go get github.com/omustardo/gome

Then for GopherJS:

gopherjs serve
# In your browser, navigate to http://localhost:8080/github.com/omustardo/gome/demos
# Open any demo subfolder

For Desktop:

cd <path/to/workspace>/github.com/omustardo/gome/demos/<demo>
go build
./<demo_name.exe> --base_dir=.

To use go run you need to provide the base_dir flag with the full path to the assets folder. This is due to an ugly hack to load local files while maintaining the ability to load files via the same relative paths on the web. I explain the issue in more depth in https://github.com/Omustardo/gome/blob/master/asset/asset.go

If anyone has suggestions to improve file loading, I'm very open to them.

Glossary

  • Mesh: a bunch of 3d points are read in and stored in buffers on the GPU, and references to these buffers are put into mesh objects. Meshes can be loaded from file by the asset package, or created dynamically like in the mesh package.

  • Entity: information about an object in the world. Position, Rotation, Scale.

  • Model: The combination of a Mesh and Entity. Uses the world information from the entity, and the graphics information from the mesh to render.

  • NRGBA: non-premultiplied RGBA color. In a premultiplied RGBA color, the RGB values are always between 0 and the Alpha value, since they've been scaled down. For example, if your NRGBA color is red and a bit transparent [200,0,0,100] then the premultiplied RGBA version is [200*(100/255),0,0,100] = [78,0,0,100]. I believe users will find NRGBA more natural to work with so that's the default. Note that you should access the color values directly, i.e. color.R, rather than using the RGBA() function. Also note that RGBA is commonly used without multiplying the alpha value, but I chose NRGBA so it's explicit.

Tips

  • When reading the code, I recommend starting with the file that has the same name as the folder and package. For example, in the gome/camera folder, start with camera.go and the camera.Camera struct. If anything is confusing, please submit an issue and I'll make it easier to understand.
  • The built in axis rendering functions color them RGB for XYZ, in that order.
  • When working with Entity rotation, note that the default rotation considers up to be {0, 1, 0} and forward to be {0, 0, -1}. These are constants and you may need to adapt your meshes to be oriented in those directions or they may be more difficult to work with. This depends on your use case; if you only care about rotating and displaying a model then it shouldn't matter. You just apply an initial rotation when you load the model and go from there. On the other hand, if you want to have a spaceship that shoots forward, it's confusing if the model is loaded in an orientation where the front of the ship isn't towards the negative Z axis.

Gotcha's

  • The scale of models in the game is up to the user to set via entity.Entity's Scale field. Note that leaving it empty will mean your model has no physical size and so won't be shown. If you want your model to not be rendered, it's more effective to set model.Hidden = true

  • Be careful when using mgl32. Its functions tend to return new structs rather than modifying the caller. For example, you might be tempted to modify an Entity's position using e.Position.Add(mgl32.Vec3{1,1,0}) but this doesn't modify e.Position. It just returns a new vector. Instead, use e.Position = e.Position.Add(mgl32.Vec3{1,1,0}) or e.ModifyPosition(1,1,0)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(windowTitle string, windowWidth, windowHeight int, baseDir string) func()

Init should be called near the start of the main method. It sets up the glfw window, shaders, input, and basic meshes among other things. It returns a function which should be deferred, to cleanly close everything at the end.

Types

This section is empty.

Directories

Path Synopsis
Package asset provides tools to manage loading, use, and unloading of assets, such as images and audio.
Package asset provides tools to manage loading, use, and unloading of assets, such as images and audio.
zoom
zoom is a handler for dealing with zoom.
zoom is a handler for dealing with zoom.
core
entity
Package entity contains the Entity struct, which is the most basic physical world information attached to an object.
Package entity contains the Entity struct, which is the most basic physical world information attached to an object.
demos
mandelbrot
demo showing use of gome to set up a window, but to draw in it with completely custom shaders.
demo showing use of gome to set up a window, but to draw in it with completely custom shaders.
meshes
Demo of loading and displaying various meshes.
Demo of loading and displaying various meshes.
simple_text
Basic text rendering demo, based closely on https://github.com/golang/freetype/tree/master/example/freetype
Basic text rendering demo, based closely on https://github.com/golang/freetype/tree/master/example/freetype
input
keyboard
keyboard handles keyboard interaction with a glfw window.
keyboard handles keyboard interaction with a glfw window.
mouse
mouse handles mouse interaction with a glfw window.
mouse handles mouse interaction with a glfw window.
fps
Package fps can be used to keep track of framerate and delta time.
Package fps can be used to keep track of framerate and delta time.
glutil
glutil contains common functions to deal with OpenGl and WebGL, such as loading data into Buffers and Textures.
glutil contains common functions to deal with OpenGl and WebGL, such as loading data into Buffers and Textures.
view sets up and handles a glfw window.
view sets up and handles a glfw window.

Jump to

Keyboard shortcuts

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