gosgl

package module
v0.0.0-...-0305e6a Latest Latest
Warning

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

Go to latest
Published: May 7, 2014 License: BSD-3-Clause Imports: 9 Imported by: 3

README

GosGL

Modern OpenGL GPU-based resolution-independent graphics library. Written in Go.

Rendering vector-like graphics using shaders on the modern GPU pipeline is extremely efficient: hardware-accelerated, way faster, energy-saving and no heavy cpu computation is needed. This new wave of technology has been developed by multiple parties over the years and it's working now. Some major popular graphics library, namely Skia has already adopted the technique in the new accelerated version. Nvidia also released the Nv_path_rendering API using this technique.

This project tries to implement a near pure Go graphics library using new resolution-independent techniques.

Here's a screenshot demoing the current stage of the project:
screenshot

It can already render smooth quadratic and cubic curves forming paths with antialiasing working, using a technique based on [Loop/Blinn] and some stencil magic. Talking about filling, these are the hardest to implement and they're working. It needs one more big thing to be basically usable: stroking. Stroking, especially dashed stroking involving curves is a difficult problem to solve. I found published papers by masterminds describing exactly the techniques to do these though, therefore it's not that far-fetched.

So I put my work here in the hope of finding someone, someone mathematically inclined to move it forward, become a real thing, it may create a brand new world or not in what way you may imagine. I feel like I'm not intelligent enough or something, it's just hard to grasp the mathematics involved. Nevertheless, I learned a great deal while tinkering with all the stuff about graphics and OpenGL involved, acquired quite some knowledge and experience in the process, so I could help with the foundation.

Drop me an email if you're interested. Would be a pleasure to work with you. I'm at phaikawl[at]gmail[dot]com.

Questions? Ideas? Come here: google group

#Building It's a Go project so building is straightforward, the only non-go dependencies are OpenGL and Glfw3. Their installation instructions are here:

  • Go-gl
  • Go-glfw3
    After installing these, just go get github.com/phaikawl/gosgl.

Documentation

Overview

Package gosgl is package gosgl

Index

Constants

This section is empty.

Variables

View Source
var (
	Black = color.RGBA{0, 0, 0, 255}
)

Functions

func Init

func Init()

func ShaderFromFile

func ShaderFromFile(stype gl.GLenum, filename string) (shader glh.Shader)

func Vector

func Vector(p Point) mathgl.Vec2d

Types

type BezierCurve

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

func NewBezierCurve

func NewBezierCurve(p1, c1, c2, p2 Point) (bc *BezierCurve)

func (*BezierCurve) Draw

func (c *BezierCurve) Draw(canv *Canvas)

func (*BezierCurve) Points

func (c *BezierCurve) Points() (l []Point)

func (*BezierCurve) ToQuadratics

func (c *BezierCurve) ToQuadratics() []QuadraticCurve

ToQuadratics approximates a cubic bezier curve with quadratics. Algorithm by Adrian Colomitchi at http://www.caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html

type Canvas

type Canvas struct {
	W, H int
	// contains filtered or unexported fields
}

func NewCanvas

func NewCanvas(w, h int) *Canvas

type Config

type Config interface {
	Apply()
}

type GLPoint

type GLPoint struct {
	X, Y float32
}

type GlColorConfig

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

func (*GlColorConfig) Apply

func (conf *GlColorConfig) Apply()

func (*GlColorConfig) Program

func (pi *GlColorConfig) Program() gl.Program

func (*GlColorConfig) Reset

func (conf *GlColorConfig) Reset()

func (*GlColorConfig) SetColor

func (conf *GlColorConfig) SetColor(color color.Color)

func (*GlColorConfig) SetProgram

func (pi *GlColorConfig) SetProgram(p gl.Program)

type GlDrawer

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

GlDrawer represents an OpenGl program and shader, like an opengl draw mode

func NewGlDrawer

func NewGlDrawer(vshader, fshader string) *GlDrawer

func (*GlDrawer) Activate

func (dr *GlDrawer) Activate()

func (*GlDrawer) AddConfig

func (dr *GlDrawer) AddConfig(conf drawConfig)

type OpenGL

type OpenGL struct {
	QuadraticDrawer *GlDrawer
	TriangleDrawer  *GlDrawer
	FillDrawer      *GlDrawer

	QuadraticDrawConfig *QuadraticDrawConfig
	GlColorConfig       *GlColorConfig
	// contains filtered or unexported fields
}

Describe opengl state object

func OpenGLInit

func OpenGLInit() *OpenGL

func (*OpenGL) Activate

func (g *OpenGL) Activate(dr *GlDrawer)

type Paint

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

func NewPaint

func NewPaint() *Paint

func (*Paint) SetFill

func (p *Paint) SetFill(color color.Color) *Paint

type Path

type Path struct {
	Segs *list.List
	// contains filtered or unexported fields
}

func NewPath

func NewPath() *Path

func (*Path) BezierTo

func (p *Path) BezierTo(p2, c1, c2 Point) *Path

func (*Path) DrawFill

func (p *Path) DrawFill(canv *Canvas, paint *Paint)

func (*Path) EndPoint

func (p *Path) EndPoint() Point

func (*Path) NewEnd

func (p *Path) NewEnd(pt Point)

func (*Path) QuadraticTo

func (p *Path) QuadraticTo(p2, c Point) *Path

func (*Path) StartAt

func (p *Path) StartAt(pt Point) *Path

type PathSegment

type PathSegment interface {
	Draw(*Canvas)
	Points() []Point //May be unnecessary
}

type Point

type Point struct {
	X float64
	Y float64
}

func GetPt

func GetPt(pt *list.Element) Point

func Pt

func Pt(x, y float64) Point

func ToPoint

func ToPoint(v mathgl.Vec2d) Point

func (Point) Add

func (pt Point) Add(pt2 Point) Point

func (Point) Mathgl

func (p Point) Mathgl() mathgl.Vec2d

func (Point) Mul

func (pt Point) Mul(ratio float64) Point

func (Point) Sub

func (pt Point) Sub(pt2 Point) Point

type QuadraticCurve

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

func NewQuadraticCurve

func NewQuadraticCurve(p1, c, p2 Point) *QuadraticCurve

func (*QuadraticCurve) Draw

func (c *QuadraticCurve) Draw(canv *Canvas)

func (*QuadraticCurve) Points

func (c *QuadraticCurve) Points() []Point

func (*QuadraticCurve) SetPoints

func (c *QuadraticCurve) SetPoints(pts [3]Point)

type QuadraticDrawConfig

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

func (*QuadraticDrawConfig) Apply

func (conf *QuadraticDrawConfig) Apply()

func (*QuadraticDrawConfig) Program

func (pi *QuadraticDrawConfig) Program() gl.Program

func (*QuadraticDrawConfig) SetExcludeTransluFrags

func (conf *QuadraticDrawConfig) SetExcludeTransluFrags(v bool)

func (*QuadraticDrawConfig) SetProgram

func (pi *QuadraticDrawConfig) SetProgram(p gl.Program)

type Rectangle

type Rectangle struct {
	Min Point
	Max Point
}

func (Rectangle) Dx

func (r Rectangle) Dx() float64

func (Rectangle) Dy

func (r Rectangle) Dy() float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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