glman

package
v0.0.0-...-944e809 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package glman is manage complex 3D objects for render with opengl. for example font, text, shapes and particle system.

the standard coordinate system is left-handed, the floor plane is x-y, the above is negtive z.

    |/                 0 ---------- x+
  - 0 ------- x+       |
   /|                  |
  / |                  |
 /  z+                 |
y+                     y+

the standard culling settings is front=CW, back=CCW

1 -- 3 -- 5 --
| \  | \  | \
|  \ |  \ |  \
0 -- 2 -- 4 --

Index

Constants

This section is empty.

Variables

View Source
var (
	// StackMatP is matrix stack for projection
	StackMatP = geom.Mat4Stack{geom.Mat4Ident()}
	// StackMatV is matrix stack for view/camera
	StackMatV = geom.Mat4Stack{geom.Mat4Ident()}
	// StackMatM is matrix stack for model
	StackMatM = geom.Mat4Stack{geom.Mat4Ident()}
	// StackClip2D is stack for 2D clipping
	StackClip2D = Clip2DStack([]Rect{infClipRect})
)
View Source
var (
	// MtlIndex is index of materials
	MtlIndex = make(map[string]*MtlInfo)
)

Functions

func DbgCheckError

func DbgCheckError()

DbgCheckError invoke glGetError and verify the return code, panic if got a error

func DynDrawImageRect

func DynDrawImageRect(rect Rect, color Color)

DynDrawImageRect fill rectangle

func DynDrawRect

func DynDrawRect(rect Rect, color Color, lineWidth float32)

DynDrawRect draw rectangle

func DynDrawRectEx

func DynDrawRectEx(rect Rect, color Color, szLeft, szRight, szTop, szBottom float32)

DynDrawRectEx draw rectangle

func DynDrawText

func DynDrawText(s string, rect Rect, font Font, color Color, options OptionDrawText)

DynDrawText draw text

func DynFillRect

func DynFillRect(rect Rect, color Color)

DynFillRect fill rectangle

func OSVersion

func OSVersion() (s string)

OSVersion return the version of operating system

func Routine

func Routine()

Routine will destory all pending object

func SetViewport

func SetViewport(rc Rect)

SetViewport is convenience wrapper for gl.Viewport

Types

type Clip2DStack

type Clip2DStack []Rect

Clip2DStack stack type for 2D clipping

func (*Clip2DStack) Load

func (s *Clip2DStack) Load(rect Rect)

Load rect into stack top

func (*Clip2DStack) LoadInf

func (s *Clip2DStack) LoadInf(rect Rect)

LoadInf load a very large rect, make it act as no clip at all. the components is large numbers, not realy INF.

func (*Clip2DStack) Peek

func (s *Clip2DStack) Peek() Rect

Peek stack top

func (*Clip2DStack) Pop

func (s *Clip2DStack) Pop() error

Pop stack

func (*Clip2DStack) Push

func (s *Clip2DStack) Push()

Push stack, new top is a very large rect.

type Color

type Color [4]float32

Color is floating point color

func MkRGBAF

func MkRGBAF(r, g, b, a byte) (c Color)

MkRGBAF make a Color form r,g,b,a component

func (*Color) Copy

func (c *Color) Copy(s imageColor.Color)

Copy from a image/color.Color

func (*Color) Parse

func (c *Color) Parse(s string)

Parse color form string

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

RGBA returns the alpha-premultiplied red, green, blue and alpha values for the color. Each value ranges within [0, 0xffff], but is represented by a uint32 so that multiplying by a blend factor up to 0xffff will not overflow.

An alpha-premultiplied color component c has been scaled by alpha (a), so has valid values 0 <= c <= a.

implement image/color.Color interface.

func (*Color) SetBytes

func (c *Color) SetBytes(r, g, b, a byte)

SetBytes set color from r, g, b, a components

type Font

type Font string

Font descriptor, i.e."Arial(Bold) 20", "Monospace 24". if the program don't know such font, it will fallback to default font. it's discourage make Font from a string by hand, use LoadFont instead.

func LoadFont

func LoadFont(name string, size int) Font

LoadFont load a font, if failed it will match a near font

func (Font) MkMText

func (f Font) MkMText(s string, width, height float32, options uint32) MText

MkMText create text model

func (Font) Name

func (f Font) Name() string

Name the font name, i.e. "Arial"

func (Font) Size

func (f Font) Size() int

Size is the font size

type Image

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

Image quad

type MText

type MText interface {
	Render()
	Colors() []Color
	SetColors(c ...Color)
	DrawEdge() bool
	SetDrawEdge(b bool)
	Text() string
}

MText is text model

type Mat4

type Mat4 = geom.Mat4

Mat4 type

type Model

type Model interface {
	Render()
}

Model interface for 3D model object

type Mtl

type Mtl struct {
	MtlInfo
	TexMapDiffuse  *Res
	TexMapSpecular *Res
	TexMapBump     *Res
	TexMapAlpha    *Res
}

Mtl is material loaded into memory

func LoadMtl

func LoadMtl(name string) *Mtl

LoadMtl load material

type MtlInfo

type MtlInfo struct {
	Diffuse       [3]float32
	Ambient       [3]float32
	Specular      [3]float32
	Emissive      [3]float32
	SpecularPower float32
	Alpha         float32
	RenderMode    uint32
	MapDiffuse    string
	MapSpecular   string
	MapBump       string
	MapAlpha      string
}

MtlInfo is surface material

type OptionDrawText

type OptionDrawText int

OptionDrawText is options for draw text

const (
	DtTop        OptionDrawText = 0x00000000
	DtLeft       OptionDrawText = 0x00000000
	DtCenter     OptionDrawText = 0x00000001
	DtRight      OptionDrawText = 0x00000002
	DtVCenter    OptionDrawText = 0x00000004
	DtBottom     OptionDrawText = 0x00000008
	DtSingleLine OptionDrawText = 0x00000010
)

options for draw text

type Program

type Program struct {

	// ID of program
	ID uint32

	// attribute location for vertesx shader
	AttPos   int32 `attrib:"attPos"`
	AttTC    int32 `attrib:"attTC"`
	AttNorm  int32 `attrib:"attNorm"`
	AttColor int32 `attrib:"attColor"`

	// uniform location for vertesx shader
	UniMatP int32 `uniform:"uniMatP"`
	UniMatV int32 `uniform:"uniMatV"`
	UniMatM int32 `uniform:"uniMatM"`

	// sampler uniform for fragment shader
	UniTex0 int32 `uniform:"uniTex0"`
	UniTex1 int32 `uniform:"uniTex1"`

	UniColors  int32 `uniform:"uniColors"`
	UniClip2D  int32 `uniform:"uniClip2D"`
	UniTexSize int32 `uniform:"uniTexSize"`
}

Program wrap shader program

func LoadProgram

func LoadProgram(files ...string) (p *Program, err error)

LoadProgram load and link shaders into program, cached in memory.

func MustLoadProgram

func MustLoadProgram(files ...string) *Program

MustLoadProgram load and link shaders into program, cached in memory. panics if failed.

func UseProgSimpleDraw

func UseProgSimpleDraw() (p *Program)

UseProgSimpleDraw load and use the simple draw program

func UseProgTexFont

func UseProgTexFont(edge bool) (p *Program)

UseProgTexFont load and use the tex font program

func (*Program) IsCurrentProgram

func (p *Program) IsCurrentProgram() bool

IsCurrentProgram reports whether the program is in use

func (*Program) LoadClip2DStack

func (p *Program) LoadClip2DStack()

LoadClip2DStack load clip rect from StackClip2D

func (*Program) LoadMStack

func (p *Program) LoadMStack()

LoadMStack load model matrix from stack

func (*Program) LoadMVPStack

func (p *Program) LoadMVPStack()

LoadMVPStack load model, view and projection matrix from stack

func (*Program) LoadVPStack

func (p *Program) LoadVPStack()

LoadVPStack load view and projection matrix from stack

func (*Program) SetMVP

func (p *Program) SetMVP(model, view, projection Mat4, transpose bool)

SetMVP set model, view and projection matrix.

func (*Program) SetMVPfv

func (p *Program) SetMVPfv(model, view, projection *float32, transpose bool)

SetMVPfv set model, view and projection matrix. i.e. SetMVP(matModel,nil,matProj, false)

func (*Program) UseProgram

func (p *Program) UseProgram()

UseProgram use the program, same as gl.UseProgram(p.ID)

type Provider

type Provider func(name string) *Res

Provider is callback to load resources

var (
	ProvideTexture Provider
)

Providers

type Rect

type Rect = geom.Rect

Rect type

func GetViewport

func GetViewport() Rect

GetViewport is convenience wrapper for gl.Get(gl.VIEWPORT)

type Res

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

Res is pointer to resource

func GenBuffer

func GenBuffer(name string) *Res

GenBuffer is wrapper for gl.GenBuffers

func GenTexture

func GenTexture(name string) *Res

GenTexture is wrapper for gl.GenTextures

func GenVertexArray

func GenVertexArray(name string) *Res

GenVertexArray is wrapper for gl.GenVertexArrays

func LoadTexture

func LoadTexture(name string) *Res

LoadTexture load and cache texture by name, must set ProvideTexture before call this function.

func (*Res) ID

func (r *Res) ID() uint32

ID of OpenGL resource

func (*Res) Name

func (r *Res) Name() string

Name of the resource

func (*Res) NumRef

func (r *Res) NumRef() int

NumRef reports reference count

func (*Res) Release

func (r *Res) Release()

Release reference explicitly

func (*Res) String

func (r *Res) String() string

func (*Res) Type

func (r *Res) Type() string

Type of the resource, for debugging

type Vec2

type Vec2 = geom.Vec2

Vec2 type

type Vec3

type Vec3 = geom.Vec3

Vec3 type

type Vec4

type Vec4 = geom.Vec4

Vec4 type

Directories

Path Synopsis
Package t3d is utils for tetra 3d internal format
Package t3d is utils for tetra 3d internal format
Package wfobj provide interface to load Wave Front 3d models and materials
Package wfobj provide interface to load Wave Front 3d models and materials

Jump to

Keyboard shortcuts

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