gl

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

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

Go to latest
Published: Jul 10, 2013 License: MIT Imports: 5 Imported by: 0

README

OpenGL ES bindings for Go.

Documentation

Overview

Package gl provides a set of bindings for OpenGL ES.

The intent of this package is to provide a very simple one-to-one set of bindings, but with some small modification to be more Go-friendly, and to take advantage of some of the niceties available in Go (extra type safety, reflection, methods, color.Color, etc.). With very few exceptions, each function or method in this package corresponds directly to a single OpenGL ES function. The exceptions to this rule are noted explicitly in their documentation.

A Note on Naming

Enum names are the same as their corresponding name in C, but they are in CamlCase and have the "GL" prefix removed. For example: GL_COLOR_BUFFER_BIT is ColorBufferBit. In a very small number of cases the names needed an extra prefix to disambiguate constants of different types that would otherwise have the same name. For example, GL_DELETE_STATUS is both ShaderDeleteStatus or ProgramDeleteStatus. One can be used when getting properties from shaders, and the other when getting properties from programs. This provides better type safety and is not expected to lead to any confusion. Additionally, godoc should make it trivial to find the avaliable enum values for differenc functions since they are associated with parameters via their types.

Function names are the same as their corresponding name in C but with the "gl" prefix and all size and type suffixes removed. Functions whose C equivalents operate on objects (such as buffers, shaders, programs, textures, etc.) have been converted to methods.

Method names are the same as their corresponding function names in C but with the "gl" prefix, all size and type suffixes, and the object name removed where possible. In cases where these removals results in an empty identifier (e.g., glUniform) then the object name is not removed. For example:

glShaderCompile is Shader.Compile
glGetProgram  is Program.Get
glEnableVertexAttribArray is VertexAttribArray.Enable()
glUniform is Uniform.Uniform

This should save typing in many places and be, overall, more pleasent.

It should be noted that these rules make for some non-idiomatic names. For example, getter methods have a "Get" prefix (Shader.GetInfoLog) and setter methods have no prefix (Shader.Source); Go prefers the opposite: no prefix for getters, and a "Set" prefix for setters. While annoying, this wasn't reconsiled on purpose. This package doesn't provide detailed documentation, and the ability to easily go between these names iand their C equivalents in order to find the documentation is more important than idioms (even if Go's idiom is superior ☺).

An apology

I must apologize in advance for the poor godoc comments. The comments for functions and methods are straight out of the man pages and are, in most cases, completely unhelpful. On the other hand, OpenGL is fairly complex, and I am in no way qualified to write useful documentation for it. I am also not qualified to write documentation geared toward those who have never used OpenGL before, so this package's documentation assumes a user who is familiar with OpenGL from other sources. I found this tutorial helpful: http://www.arcsynthesis.org/gltut.

Index

Constants

View Source
const (
	Nearest = C.GL_NEAREST
	Linear  = C.GL_LINEAR
)

Variables

This section is empty.

Functions

func ActiveTexture

func ActiveTexture(unit int)

ActiveTexture selects active texture unit. Unit must be between 0 and the maximum supported texture units, of which there are at least 80.

func BlendFunc

func BlendFunc(srcFactor, dstFactor BlendFunction)

BlendFunc specifies pixel arithmetic

func BufferData

func BufferData(targ BufferTarget, data interface{}, usage BufferDataUsage)

BufferData creates and initializes a buffer object's data store.

func BufferSubData

func BufferSubData(targ BufferTarget, offs int, data interface{})

BufferSubData updates a subset of a buffer object's data store.

func Clear

func Clear(bits ClearFlags)

Clear clears buffers to preset values.

func ClearColor

func ClearColor(col color.Color)

ClearColor specifies clear values for the color buffers.

func ClearDepth

func ClearDepth(d float32)

ClearDepth specifies the clear value for the depth buffer.

func ClearStencil

func ClearStencil(s int)

ClearStencil specifies the clear value for the stencil buffer.

func DeleteBuffers

func DeleteBuffers(bufs []Buffer)

DeleteBuffers deletes named buffer objects.

func DeleteTextures

func DeleteTextures(texs []Texture)

DeleteTextures deletes named textures.

func Disable

func Disable(c Capability)

Disable disables OpenGL capabilities.

func DrawArrays

func DrawArrays(mode DrawMode, first, count int)

DrawArrays renders primitives from array data.

func Enable

func Enable(c Capability)

Enable enables OpenGL capabilities.

func Finish

func Finish()

Finish blocks until all GL execution is complete.

func Flush

func Flush()

Flush forces execution of GL commands in finite time.

func GetError

func GetError() error

GetError returns error information: an error if one occurred or nil.

func LineWidth

func LineWidth(w float32)

LineWidth specifies the width of rasterized lines.

func TexImage2D

func TexImage2D(targ TextureTarget, lvl int, ifmt TextureFormat, w, h, border int, fmt TextureFormat, data interface{})

TexImage2D specifies a two-dimensional texture image.

func TexParameter

func TexParameter(targ TextureTarget, parm TexParam, val interface{})

TexParameter sets texture parameters.

Types

type BlendFunction

type BlendFunction C.GLenum

BlendFunction specifies how either source or destination colors are blended.

type Buffer

type Buffer C.GLuint

A Buffer is an OpenGL buffer object.

func GenBuffers

func GenBuffers(n int) []Buffer

GenBuffers generates and returns n named buffer objects.

func (Buffer) Bind

func (b Buffer) Bind(targ BufferTarget)

Bind binds a named buffer object.

func (Buffer) Delete

func (b Buffer) Delete()

Delete deletes the named buffer object.

type BufferDataUsage

type BufferDataUsage C.GLenum

type BufferTarget

type BufferTarget C.GLenum
const (
	ArrayBuffer        BufferTarget = C.GL_ARRAY_BUFFER
	ElementArrayBuffer BufferTarget = C.GL_ELEMENT_ARRAY_BUFFER
)

type Capability

type Capability C.GLenum

A Capability is a feature of OpenGL that can be enabled or disabled.

const (
	Blend  Capability = C.GL_BLEND
	Dither Capability = C.GL_DITHER
)

type ClearFlags

type ClearFlags C.GLbitfield

ClearFlags is a bitset type for the flags to Clear.

const (
	ColorBufferBit   ClearFlags = C.GL_COLOR_BUFFER_BIT
	DepthBufferBit   ClearFlags = C.GL_DEPTH_BUFFER_BIT
	StencilBufferBit ClearFlags = C.GL_STENCIL_BUFFER_BIT
)

type DataType

type DataType C.GLenum

A DataType defines the type of data elements.

const (
	Float         DataType = C.GL_FLOAT
	Byte          DataType = C.GL_BYTE
	Short         DataType = C.GL_SHORT
	UnsignedByte  DataType = C.GL_UNSIGNED_BYTE
	UnsignedShort DataType = C.GL_UNSIGNED_SHORT
)

type DrawMode

type DrawMode C.GLenum

DrawMode specifies what to draw.

const (
	Points        DrawMode = C.GL_POINTS
	LineStrip     DrawMode = C.GL_LINE_STRIP
	LineLoop      DrawMode = C.GL_LINE_LOOP
	Lines         DrawMode = C.GL_LINES
	TriangleStrip DrawMode = C.GL_TRIANGLE_STRIP
	TriangleFan   DrawMode = C.GL_TRIANGLE_FAN
	Triangles     DrawMode = C.GL_TRIANGLES
)

type Program

type Program C.GLuint

A Program is a set of linked shaders that can be loaded onto the graphics card.

func CreateProgram

func CreateProgram() Program

CreateProgram creates a program object.

func (Program) AttachShader

func (p Program) AttachShader(s Shader)

AttachShader attaches a shader object to a program object.

func (Program) Delete

func (p Program) Delete()

Delete deletes a program object.

func (Program) DetachShader

func (p Program) DetachShader(s Shader)

DetachShader detaches a shader object from a program object to which it is attached.

func (Program) Get

func (p Program) Get(parm ProgramParameter) int

Get returns a parameter from a program object.

func (Program) GetAttribLocation

func (p Program) GetAttribLocation(name string) VertexAttribArray

GetAttribLocation returns the location of an attribute variable.

func (Program) GetInfoLog

func (p Program) GetInfoLog() string

GetInfoLog returns the information log for a program object. This method makes two OpenGL calls: one to get the info log size, and one to get the info log.

func (Program) GetUniformLocation

func (p Program) GetUniformLocation(name string) Uniform

GetUniformLocation returns the location of a uniform variable.

func (p Program) Link()

Link links a program object.

func (Program) Use

func (p Program) Use()

Use installs a program object as part of current rendering state.

type ProgramParameter

type ProgramParameter C.GLenum

A ProgramParameter is a gettable parameter of a program.

type Shader

type Shader C.GLuint

func CreateShader

func CreateShader(kind ShaderKind) Shader

CreateShader creates a shader object.

func (Shader) Compile

func (s Shader) Compile()

Compile compiles a shader object.

func (Shader) Delete

func (s Shader) Delete()

Delete deletes a shader.

func (Shader) Get

func (s Shader) Get(parm ShaderParameter) int

Get returns a parameter from a shader object

func (Shader) GetInfoLog

func (s Shader) GetInfoLog() string

GetInfoLog returns the information log for a shader object. This method makes two OpenGL calls: one to get the info log size, and one to get the info log.

func (Shader) Source

func (s Shader) Source(src ...string)

Source replaces the source code in a shader object.

type ShaderKind

type ShaderKind C.GLenum

A ShaderKind specifies the type of shader.

const (
	VertexShader   ShaderKind = C.GL_VERTEX_SHADER
	FragmentShader ShaderKind = C.GL_FRAGMENT_SHADER
)

type ShaderParameter

type ShaderParameter C.GLenum

A ShaderParameter names a gettable parameter of a shader.

const (
	CompileStatus       ShaderParameter = C.GL_COMPILE_STATUS
	ShaderInfoLogLength ShaderParameter = C.GL_INFO_LOG_LENGTH
	ShaderSourceLength  ShaderParameter = C.GL_SHADER_SOURCE_LENGTH
	ShaderType          ShaderParameter = C.GL_SHADER_TYPE
	ShaderDeleteStatus  ShaderParameter = C.GL_DELETE_STATUS
)

type TexParam

type TexParam C.GLenum

A TexParam is the name of a texture parameter.

const (
	TextureMagFilter TexParam = C.GL_TEXTURE_MAG_FILTER
	TextureMinFilter TexParam = C.GL_TEXTURE_MIN_FILTER
)

type Texture

type Texture C.GLuint

A Texture is the name of a texture object.

func GenTextures

func GenTextures(n int) []Texture

GenTextures generates texture names.

func (Texture) Bind

func (tex Texture) Bind(targ TextureTarget)

Bind binds a named texture to a texturing target.

func (Texture) Delete

func (tex Texture) Delete()

Delete deletes a named texture.

type TextureFormat

type TextureFormat C.GLenum

A TextureFormat specifies how to interpret texture data.

type TextureTarget

type TextureTarget C.GLenum

A TextureTarget is a texturing target to which a texture can be bound.

const (
	Texture2D TextureTarget = C.GL_TEXTURE_2D
)

type Uniform

type Uniform C.GLint

func (Uniform) Uniform

func (u Uniform) Uniform(vls ...interface{})

Uniform specifies the value of a uniform variable for the current program object.

type VertexAttribArray

type VertexAttribArray C.GLuint

func (VertexAttribArray) Disable

func (l VertexAttribArray) Disable()

Disable disables a generic vertex attribute array.

func (VertexAttribArray) Enable

func (l VertexAttribArray) Enable()

Enable enables a generic vertex attribute array.

func (VertexAttribArray) Pointer

func (l VertexAttribArray) Pointer(sz int, t DataType, norm bool, stride, offs int)

Pointer defines an array of generic vertex attribute data.

Jump to

Keyboard shortcuts

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