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
- func ActiveTexture(unit int)
- func BlendFunc(srcFactor, dstFactor BlendFunction)
- func BufferData(targ BufferTarget, data interface{}, usage BufferDataUsage)
- func BufferSubData(targ BufferTarget, offs int, data interface{})
- func Clear(bits ClearFlags)
- func ClearColor(col color.Color)
- func ClearDepth(d float32)
- func ClearStencil(s int)
- func DeleteBuffers(bufs []Buffer)
- func DeleteTextures(texs []Texture)
- func Disable(c Capability)
- func DrawArrays(mode DrawMode, first, count int)
- func Enable(c Capability)
- func Finish()
- func Flush()
- func GetError() error
- func LineWidth(w float32)
- func TexImage2D(targ TextureTarget, lvl int, ifmt TextureFormat, w, h, border int, ...)
- func TexParameter(targ TextureTarget, parm TexParam, val interface{})
- type BlendFunction
- type Buffer
- type BufferDataUsage
- type BufferTarget
- type Capability
- type ClearFlags
- type DataType
- type DrawMode
- type Program
- func (p Program) AttachShader(s Shader)
- func (p Program) Delete()
- func (p Program) DetachShader(s Shader)
- func (p Program) Get(parm ProgramParameter) int
- func (p Program) GetAttribLocation(name string) VertexAttribArray
- func (p Program) GetInfoLog() string
- func (p Program) GetUniformLocation(name string) Uniform
- func (p Program) Link()
- func (p Program) Use()
- type ProgramParameter
- type Shader
- type ShaderKind
- type ShaderParameter
- type TexParam
- type Texture
- type TextureFormat
- type TextureTarget
- type Uniform
- type VertexAttribArray
Constants ¶
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 ClearColor ¶
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 DrawArrays ¶
DrawArrays renders primitives from array data.
func GetError ¶
func GetError() error
GetError returns error information: an error if one occurred or nil.
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 ¶
BlendFunction specifies how either source or destination colors are blended.
const ( Zero BlendFunction = C.GL_ZERO One BlendFunction = C.GL_ONE SrcColor BlendFunction = C.GL_SRC_COLOR OneMinusSrcColor BlendFunction = C.GL_ONE_MINUS_SRC_COLOR SrcAlpha BlendFunction = C.GL_SRC_ALPHA OneMinusSrcAlpha BlendFunction = C.GL_ONE_MINUS_SRC_ALPHA DstColor BlendFunction = C.GL_DST_COLOR OneMinusDstColor BlendFunction = C.GL_ONE_MINUS_DST_COLOR DstAlpha BlendFunction = C.GL_DST_ALPHA OneMinusDstAlpha BlendFunction = C.GL_ONE_MINUS_DST_ALPHA ConstantColor BlendFunction = C.GL_CONSTANT_COLOR OneMinusConstantColor BlendFunction = C.GL_ONE_MINUS_CONSTANT_COLOR ConstantAlpha BlendFunction = C.GL_CONSTANT_ALPHA OneMinusConstantAlpha BlendFunction = C.GL_ONE_MINUS_CONSTANT_ALPHA )
type Buffer ¶
A Buffer is an OpenGL buffer object.
func GenBuffers ¶
GenBuffers generates and returns n named buffer objects.
type BufferDataUsage ¶
const ( StaticDraw BufferDataUsage = C.GL_STATIC_DRAW StreamDraw BufferDataUsage = C.GL_STREAM_DRAW DynamicDraw BufferDataUsage = C.GL_DYNAMIC_DRAW )
type BufferTarget ¶
const ( ArrayBuffer BufferTarget = C.GL_ARRAY_BUFFER ElementArrayBuffer BufferTarget = C.GL_ELEMENT_ARRAY_BUFFER )
type Capability ¶
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 DrawMode ¶
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 ¶
A Program is a set of linked shaders that can be loaded onto the graphics card.
func (Program) AttachShader ¶
AttachShader attaches a shader object to a program object.
func (Program) DetachShader ¶
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 ¶
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 ¶
GetUniformLocation returns the location of a uniform variable.
type ProgramParameter ¶
A ProgramParameter is a gettable parameter of a program.
const ( ProgramDeleteStatus ProgramParameter = C.GL_DELETE_STATUS LinkStatus ProgramParameter = C.GL_LINK_STATUS ValidateStatus ProgramParameter = C.GL_VALIDATE_STATUS ProgramInfoLogLength ProgramParameter = C.GL_INFO_LOG_LENGTH AttachedShaders ProgramParameter = C.GL_ATTACHED_SHADERS ActiveAttributes ProgramParameter = C.GL_ACTIVE_ATTRIBUTES ActiveAttributeMaxLength ProgramParameter = C.GL_ACTIVE_ATTRIBUTE_MAX_LENGTH ActiveUniforms ProgramParameter = C.GL_ACTIVE_UNIFORMS ActiveUniformMaxLength ProgramParameter = C.GL_ACTIVE_UNIFORM_MAX_LENGTH )
type Shader ¶
func (Shader) Get ¶
func (s Shader) Get(parm ShaderParameter) int
Get returns a parameter from a shader object
func (Shader) GetInfoLog ¶
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.
type ShaderKind ¶
A ShaderKind specifies the type of shader.
const ( VertexShader ShaderKind = C.GL_VERTEX_SHADER FragmentShader ShaderKind = C.GL_FRAGMENT_SHADER )
type ShaderParameter ¶
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 ¶
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 ¶
A Texture is the name of a texture object.
func (Texture) Bind ¶
func (tex Texture) Bind(targ TextureTarget)
Bind binds a named texture to a texturing target.
type TextureFormat ¶
A TextureFormat specifies how to interpret texture data.
const ( Alpha TextureFormat = C.GL_ALPHA Luminance TextureFormat = C.GL_LUMINANCE LuminanceAlpha TextureFormat = C.GL_LUMINANCE_ALPHA RGB TextureFormat = C.GL_RGB RGBA TextureFormat = C.GL_RGBA )
type TextureTarget ¶
A TextureTarget is a texturing target to which a texture can be bound.
const (
Texture2D TextureTarget = C.GL_TEXTURE_2D
)
type VertexAttribArray ¶
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.