本文整理匯總了Golang中github.com/chsc/gogl/gl21.Pointer函數的典型用法代碼示例。如果您正苦於以下問題:Golang Pointer函數的具體用法?Golang Pointer怎麽用?Golang Pointer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Pointer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Render
func (vb *VertexBuffer) Render(position Point3) {
gl.PushMatrix()
gl.Translated(
gl.Double(position.X),
gl.Double(position.Y),
gl.Double(position.Z))
gl.VertexPointer(
gl.Int(3),
gl.DOUBLE,
0,
gl.Pointer(&vb.VertexData[0]))
gl.ColorPointer(
gl.Int(4),
gl.DOUBLE,
0,
gl.Pointer(&vb.ColorData[0]))
gl.TexCoordPointer(
gl.Int(2),
gl.DOUBLE,
0,
gl.Pointer(&vb.TexCoordData[0]))
for i := range vb.RenderSteps {
rs := &vb.RenderSteps[i]
gl.DrawElements(
rs.Mode,
gl.Sizei(len(rs.Indices)),
gl.UNSIGNED_INT,
gl.Pointer(&rs.Indices[0]))
}
gl.PopMatrix()
}
示例2: Draw
func (ms *ManaSource) Draw(local *LocalData, zoom float64, dx float64, dy float64) {
if local.nodeTextureData == nil {
// gl.Enable(gl.TEXTURE_2D)
local.nodeTextureData = make([]byte, ms.options.NumNodeRows*ms.options.NumNodeCols*3)
gl.GenTextures(1, &local.nodeTextureId)
gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
gl.TexImage2D(
gl.TEXTURE_2D,
0,
gl.RGB,
gl.Sizei(ms.options.NumNodeRows),
gl.Sizei(ms.options.NumNodeCols),
0,
gl.RGB,
gl.UNSIGNED_BYTE,
gl.Pointer(&local.nodeTextureData[0]))
}
for i := range ms.rawNodes {
for c := 0; c < 3; c++ {
color_frac := ms.rawNodes[i].Mana[c] * 1.0 / ms.options.NodeMagnitude
color_range := float64(ms.options.MaxNodeBrightness - ms.options.MinNodeBrightness)
local.nodeTextureData[i*3+c] = byte(
color_frac*color_range + float64(ms.options.MinNodeBrightness))
}
}
gl.Enable(gl.TEXTURE_2D)
//gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
gl.TexSubImage2D(
gl.TEXTURE_2D,
0,
0,
0,
gl.Sizei(ms.options.NumNodeRows),
gl.Sizei(ms.options.NumNodeCols),
gl.RGB,
gl.UNSIGNED_BYTE,
gl.Pointer(&local.nodeTextureData[0]))
base.EnableShader("nodes")
base.SetUniformI("nodes", "width", ms.options.NumNodeRows*3)
base.SetUniformI("nodes", "height", ms.options.NumNodeCols*3)
base.SetUniformI("nodes", "drains", 1)
base.SetUniformI("nodes", "tex0", 0)
base.SetUniformI("nodes", "tex1", 1)
base.SetUniformF("nodes", "zoom", float32(zoom))
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, local.nodeTextureId)
// I have no idea why this value for move works, but it does. So, hooray.
move := (dx - dy) / 2
texture.RenderAdvanced(move, -move, dy, dx, 3.1415926535/2, true)
base.EnableShader("")
gl.Disable(gl.TEXTURE_2D)
}
示例3: NewSprite
// NewSprite creates a new Sprite object using the given data, which is
// expected to be in RGBA format. If you use PNG image files, you can use the
// NewSpriteFromImage shortcut function instead.
func NewSprite(x, y, width, height float64, data []byte, clip int) (*Sprite, error) {
verticies := []float64{
x, y,
x + width, y,
x, y + height,
x + width, y + height,
x + width, y,
x, y + height}
shape, err := NewShape(gl.TRIANGLES, verticies)
if err != nil {
return nil, err
}
sprite := &Sprite{texcoordBuffer: 0, texture: nil, shape: shape}
texCoords := []float32{
0, 0,
1, 0,
0, 1,
1, 1,
1, 0,
0, 1}
gl.GenBuffers(1, &sprite.texcoordBuffer)
gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(sprite.texcoordBuffer))
gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(len(texCoords)*4), gl.Pointer(&texCoords[0]), gl.STREAM_DRAW)
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
sprite.texture = make([]gl.Uint, clip)
gl.GenTextures(gl.Sizei(clip), &sprite.texture[0])
clips := make([][]byte, clip)
for i := range clips {
clips[i] = data[i*(len(data)/len(clips)) : (i+1)*(len(data)/len(clips))]
gl.BindTexture(gl.TEXTURE_2D, sprite.texture[len(clips)-1-i])
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA,
gl.Sizei(width), gl.Sizei(height),
0, gl.RGBA, gl.UNSIGNED_BYTE,
gl.Pointer(&clips[i][0]))
}
gl.BindTexture(gl.TEXTURE_2D, 0)
return sprite, checkForErrors()
}
示例4: draw
func (m *Model) draw() {
m.shader.use()
gl.ActiveTexture(gl.TEXTURE0)
gl.BindTexture(gl.TEXTURE_2D, m.texture_id)
gl.Uniform1i(m.shader.uniform_texture, 0)
//texcoord
if m.has_uv {
gl.BindBuffer(gl.ARRAY_BUFFER, m.texcoord)
gl.EnableVertexAttribArray(m.shader.attribute_texcoord)
gl.VertexAttribPointer(
m.shader.attribute_texcoord,
2,
gl.FLOAT,
gl.FALSE,
0,
gl.Pointer(nil))
}
gl.BindBuffer(gl.ARRAY_BUFFER, m.buffer)
gl.EnableVertexAttribArray(m.shader.attribute_vertex)
gl.VertexAttribPointer(
m.shader.attribute_vertex,
3,
gl.FLOAT,
gl.FALSE,
0,
gl.Pointer(nil))
gl.BindBuffer(gl.ARRAY_BUFFER, m.normal_buf)
gl.EnableVertexAttribArray(m.shader.attribute_normal)
gl.VertexAttribPointer(
m.shader.attribute_normal,
3,
gl.FLOAT,
gl.FALSE,
0,
gl.Pointer(nil))
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, m.index)
gl.DrawElements(gl.TRIANGLES, gl.Sizei(len(m.indices)), gl.UNSIGNED_INT, gl.Pointer(nil))
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, 0)
gl.DisableVertexAttribArray(m.shader.attribute_vertex)
gl.DisableVertexAttribArray(m.shader.attribute_normal)
if m.has_uv {
gl.DisableVertexAttribArray(m.shader.attribute_texcoord)
}
}
示例5: initquad
func initquad() {
ver := []gl.Float{-1, 1, 1, 1, -1, -1, 1, -1}
gl.BindBuffer(gl.ARRAY_BUFFER, 1)
gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(4*len(ver)),
gl.Pointer(&ver[0]), gl.STATIC_DRAW)
gl.VertexPointer(2, gl.FLOAT, 0, nil)
tex := []gl.Float{0, 0, 1, 0, 0, 1, 1, 1}
gl.BindBuffer(gl.ARRAY_BUFFER, 2)
gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(4*len(tex)),
gl.Pointer(&tex[0]), gl.STATIC_DRAW)
gl.TexCoordPointer(2, gl.FLOAT, 0, nil)
gl.EnableClientState(gl.VERTEX_ARRAY)
gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
}
示例6: createTexture
/*
Uses the image library to turn a PNG into a gl texture
*/
func createTexture(r io.Reader) (textureId gl.Uint, err error) {
img, err := png.Decode(r)
if err != nil {
return 0, err
}
rgbaImg, ok := img.(*image.RGBA)
if !ok {
return 0, errors.New("texture must be an RGBA image")
}
gl.GenTextures(1, &textureId)
gl.BindTexture(gl.TEXTURE_2D, textureId)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
// flip image: first pixel is lower left corner
imgWidth, imgHeight := img.Bounds().Dx(), img.Bounds().Dy()
data := make([]byte, imgWidth*imgHeight*4)
lineLen := imgWidth * 4
dest := len(data) - lineLen
for src := 0; src < len(rgbaImg.Pix); src += rgbaImg.Stride {
copy(data[dest:dest+lineLen], rgbaImg.Pix[src:src+rgbaImg.Stride])
dest -= lineLen
}
gl.TexImage2D(gl.TEXTURE_2D, 0, 4, gl.Sizei(imgWidth), gl.Sizei(imgHeight), 0, gl.RGBA,
gl.UNSIGNED_BYTE, gl.Pointer(&data[0]))
return textureId, nil
}
示例7: Move
// Move moves the Shape object a specified distance.
func (shape *Shape) Move(x, y float64) {
var verticies []float32
for i := 0; i < len(shape.verticies); i += 2 {
shape.verticies[i] += float32(x)
shape.verticies[i+1] += float32(y)
}
if shape.scaleX != 1 || shape.scaleY != 1 {
verticies = make([]float32, len(shape.verticies))
xTransform := shape.verticies[0] - (shape.verticies[0] * float32(shape.scaleX))
yTransform := shape.verticies[1] - (shape.verticies[1] * float32(shape.scaleY))
for i := range verticies {
if i%2 == 0 {
verticies[i] = shape.verticies[i] * float32(shape.scaleX)
verticies[i] += xTransform
} else {
verticies[i] = shape.verticies[i] * float32(shape.scaleY)
verticies[i] += yTransform
}
}
} else {
verticies = shape.verticies
}
gl.BindBuffer(gl.ARRAY_BUFFER, shape.vertexBuffer)
gl.BufferSubData(gl.ARRAY_BUFFER, 0, gl.Sizeiptr(len(verticies)*4), gl.Pointer(&verticies[0]))
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
}
示例8: loadCubeToGPU
func loadCubeToGPU() {
newNormal(0, 0, 1)
newVertex(-1, -1, 1)
newVertex(1, -1, 1)
newVertex(1, 1, 1)
newVertex(-1, 1, 1)
newNormal(0, 0, -1)
newVertex(-1, -1, -1)
newVertex(-1, 1, -1)
newVertex(1, 1, -1)
newVertex(1, -1, -1)
newNormal(0, 1, 0)
newVertex(-1, 1, -1)
newVertex(-1, 1, 1)
newVertex(1, 1, 1)
newVertex(1, 1, -1)
newNormal(0, -1, 0)
newVertex(-1, -1, -1)
newVertex(1, -1, -1)
newVertex(1, -1, 1)
newVertex(-1, -1, 1)
newNormal(1, 0, 0)
newVertex(1, -1, -1)
newVertex(1, 1, -1)
newVertex(1, 1, 1)
newVertex(1, -1, 1)
newNormal(-1, 0, 0)
newVertex(-1, -1, -1)
newVertex(-1, -1, 1)
newVertex(-1, 1, 1)
newVertex(-1, 1, -1)
gl.GenBuffers(1, &gVBO)
gl.BindBuffer(gl.ARRAY_BUFFER, gVBO)
gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(unsafe.Sizeof(Vertex{})*24), gl.Pointer(&Vertices[0]), gl.STATIC_DRAW)
gl.EnableClientState(gl.VERTEX_ARRAY)
gl.EnableClientState(gl.NORMAL_ARRAY)
gl.VertexPointer(3, gl.FLOAT, 24, nil)
tmpStruct := Vertex{}
gl.NormalPointer(gl.FLOAT, gl.Sizei(unsafe.Sizeof(Vertex{})), gl.Pointer(unsafe.Offsetof(tmpStruct.normal)))
}
示例9: upload
func upload(id gl.Uint, data []byte, stride int, w int, h int) {
gl.BindTexture(gl.TEXTURE_2D, id)
gl.PixelStorei(gl.UNPACK_ROW_LENGTH, gl.Int(stride))
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE,
gl.Sizei(w), gl.Sizei(h), 0,
gl.LUMINANCE, gl.UNSIGNED_BYTE, gl.Pointer(&data[0]))
}
示例10: init
func (m *Model) init() (err error) {
m.shader.init("shader/simple.vert", "shader/simple.frag")
/*
gl.GenBuffers(1, &m.buffer)
gl.BindBuffer(gl.ARRAY_BUFFER, m.buffer);
gl.BufferData(
gl.ARRAY_BUFFER,
gl.Sizeiptr(len(m.vertices)* int(unsafe.Sizeof(m.vertices[0]))),
gl.Pointer(&m.vertices[0]),
gl.STATIC_DRAW);
*/
m.initBufferFloat(&m.buffer, gl.ARRAY_BUFFER, &m.vertices)
gl.GenBuffers(1, &m.index)
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, m.index)
gl.BufferData(
gl.ELEMENT_ARRAY_BUFFER,
gl.Sizeiptr(len(m.indices)*int(unsafe.Sizeof(m.indices[0]))),
gl.Pointer(&m.indices[0]),
gl.STATIC_DRAW)
gl.GenBuffers(1, &m.normal_buf)
gl.BindBuffer(gl.ARRAY_BUFFER, m.normal_buf)
gl.BufferData(
gl.ARRAY_BUFFER,
gl.Sizeiptr(len(m.normals)*int(unsafe.Sizeof(m.normals[0]))),
gl.Pointer(&m.normals[0]),
gl.STATIC_DRAW)
m.initTexture()
if m.has_uv {
gl.GenBuffers(1, &m.texcoord)
gl.BindBuffer(gl.ARRAY_BUFFER, m.texcoord)
gl.BufferData(
gl.ARRAY_BUFFER,
gl.Sizeiptr(len(m.uvs)*int(unsafe.Sizeof(m.uvs[0]))),
gl.Pointer(&m.uvs[0]),
gl.STATIC_DRAW)
}
return
}
示例11: initBufferFloat
func (m *Model) initBufferFloat(buffer *gl.Uint, t gl.Enum, data *[]gl.Float) {
gl.GenBuffers(1, buffer)
gl.BindBuffer(t, *buffer)
gl.BufferData(
t,
gl.Sizeiptr(len(*data)*int(unsafe.Sizeof((*data)[0]))),
gl.Pointer(&(*data)[0]),
gl.STATIC_DRAW)
}
示例12: glInit
func glInit(width, height int) {
gl.Init()
gl.Enable(gl.TEXTURE_2D)
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1)
gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, gl.Double(width), gl.Double(height), 0, -1, 1)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.EnableClientState(gl.VERTEX_ARRAY)
gl.EnableClientState(gl.COLOR_ARRAY)
gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
gl.VertexPointer(2, gl.FLOAT, 0, gl.Pointer(&vs[0]))
gl.ColorPointer(3, gl.UNSIGNED_BYTE, 0, gl.Pointer(&cs[0]))
gl.TexCoordPointer(2, gl.FLOAT, 0, gl.Pointer(&ts[0]))
}
示例13: makeErrorTexture
func makeErrorTexture() {
gl.Enable(gl.TEXTURE_2D)
gl.GenTextures(1, (*gl.Uint)(&error_texture))
gl.BindTexture(gl.TEXTURE_2D, error_texture)
gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
pink := []byte{255, 0, 255, 255}
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.BYTE, gl.Pointer(&pink[0]))
}
示例14: reuploadTexture
func reuploadTexture(tex *gl.Uint, w, h int, data []byte) {
if *tex > 0 {
gl.BindTexture(gl.TEXTURE_2D, *tex)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.Sizei(w), gl.Sizei(h), 0,
gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&data[0]))
if gl.GetError() != gl.NO_ERROR {
gl.DeleteTextures(1, tex)
panic("Failed to reupload texture")
}
return
}
*tex = uploadTexture_RGBA32(w, h, data)
}
示例15: NewShapeFromShape
// NewShapeFromShape creates a copy of an existing Shape object.
func NewShapeFromShape(copyShape *Shape) (*Shape, error) {
shape := &Shape{mode: copyShape.mode, size: copyShape.size, verticies: make([]float32, len(copyShape.verticies)),
scaleX: copyShape.scaleX, scaleY: copyShape.scaleY}
copy(shape.verticies, copyShape.verticies)
gl.GenBuffers(1, &shape.vertexBuffer)
gl.BindBuffer(gl.ARRAY_BUFFER, shape.vertexBuffer)
gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(len(shape.verticies)*4), gl.Pointer(&shape.verticies[0]), gl.DYNAMIC_DRAW)
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
return shape, checkForErrors()
}