本文整理汇总了Golang中github.com/chsc/gogl/gl21.Sizei函数的典型用法代码示例。如果您正苦于以下问题:Golang Sizei函数的具体用法?Golang Sizei怎么用?Golang Sizei使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sizei函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initWithString
func (s *Shader) initWithString(vert_shader string, frag_shader string) {
s.initShader(gl.VERTEX_SHADER, vert_shader, &s.vert_shader)
s.initShader(gl.FRAGMENT_SHADER, frag_shader, &s.frag_shader)
s.program = gl.CreateProgram()
gl.AttachShader(s.program, s.vert_shader)
gl.AttachShader(s.program, s.frag_shader)
gl.LinkProgram(s.program)
var (
status gl.Int
info_length gl.Int
message *gl.Char
)
gl.GetProgramiv(s.program, gl.LINK_STATUS, &status)
if status == gl.FALSE {
fmt.Println("Error linking program")
gl.GetProgramiv(s.program, gl.INFO_LOG_LENGTH, &info_length)
message = gl.GLStringAlloc(gl.Sizei(info_length))
gl.GetProgramInfoLog(s.program, gl.Sizei(info_length), nil, message)
fmt.Println(gl.GoString(message))
gl.GLStringFree(message)
}
s.initAttributes()
s.initUniforms()
}
示例2: InitViewport
func InitViewport() {
gl.Viewport(0, 0, gl.Sizei(Width), gl.Sizei(Height))
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
x := gl.Double(float64(Height) / float64(Width))
gl.Frustum(-1./2., 1./2., -x/2, x/2, 10, 100)
}
示例3: resize
// resize resizes the window to the specified dimensions.
func resize(width, height int) {
gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0)
gl.MatrixMode(gl.MODELVIEW)
}
示例4: run
func (w *Window) run() {
runtime.LockOSThread()
glfw.MakeContextCurrent(w.w)
defer glfw.MakeContextCurrent(nil)
// glfw should fire initial resize events to avoid this duplication (https://github.com/glfw/glfw/issues/62)
width, height := w.w.Size()
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, gl.Double(width), 0, gl.Double(height), -1, 1)
Resize(w, Pt(float64(width), float64(height)))
width, height = w.w.FramebufferSize()
gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
gl.Enable(gl.BLEND)
gl.Enable(gl.POINT_SMOOTH)
gl.Enable(gl.LINE_SMOOTH)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
for !w.close {
select {
case f := <-w.do:
f()
case <-w.paint:
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
w.base().paint()
w.w.SwapBuffers()
}
}
}
示例5: initShader
func (s *Shader) initShader(t gl.Enum, str string, shader *gl.Uint) {
*shader = gl.CreateShader(t)
if *shader == 0 {
fmt.Println("error creating shader of type ", t)
}
src := gl.GLStringArray(str)
defer gl.GLStringArrayFree(src)
gl.ShaderSource(*shader, 1, &src[0], nil)
gl.CompileShader(*shader)
var (
status gl.Int
info_length gl.Int
message *gl.Char
)
gl.GetShaderiv(*shader, gl.COMPILE_STATUS, &status)
if status == gl.FALSE {
fmt.Println("Error compiling shader")
gl.GetShaderiv(*shader, gl.INFO_LOG_LENGTH, &info_length)
message = gl.GLStringAlloc(gl.Sizei(info_length))
gl.GetShaderInfoLog(*shader, gl.Sizei(info_length), nil, message)
fmt.Println(gl.GoString(message))
gl.GLStringFree(message)
}
}
示例6: createTexture
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.NRGBA)
if !ok {
return 0, errors.New("texture must be an NRGBA 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: 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)
}
示例8: 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]))
}
示例9: windowResizeCallback
func windowResizeCallback(window *glfw.Window, width, height int) {
paunchWindow.width = width
paunchWindow.height = height
for _, eventManager := range paunchWindow.eventManagers {
eventManager.RunWindowResizeEvent(width, height)
}
gl.Viewport(0, 0, gl.Sizei(width), gl.Sizei(height))
}
示例10: 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()
}
示例11: RenderLocalEditor
func (g *Game) RenderLocalEditor(region g2.Region) {
g.editor.Lock()
defer g.editor.Unlock()
g.editor.region = region
g.editor.camera.regionDims = linear.Vec2{float64(region.Dims.Dx), float64(region.Dims.Dy)}
levelDims := linear.Vec2{float64(g.Level.Room.Dx), float64(g.Level.Room.Dy)}
g.editor.camera.StandardRegion(levelDims.Scale(0.5), levelDims)
g.editor.camera.approachTarget()
gl.MatrixMode(gl.PROJECTION)
gl.PushMatrix()
gl.LoadIdentity()
defer gl.PopMatrix()
gl.PushAttrib(gl.VIEWPORT_BIT)
gl.Viewport(gl.Int(region.X), gl.Int(region.Y), gl.Sizei(region.Dx), gl.Sizei(region.Dy))
defer gl.PopAttrib()
current := &g.editor.camera.current
gl.Ortho(
gl.Double(current.mid.X-current.dims.X/2),
gl.Double(current.mid.X+current.dims.X/2),
gl.Double(current.mid.Y+current.dims.Y/2),
gl.Double(current.mid.Y-current.dims.Y/2),
gl.Double(1000),
gl.Double(-1000),
)
defer func() {
gl.MatrixMode(gl.PROJECTION)
gl.PopMatrix()
gl.MatrixMode(gl.MODELVIEW)
}()
gl.MatrixMode(gl.MODELVIEW)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
g.renderWalls()
g.renderEdges()
g.renderBases()
g.renderEntsAndAbilities()
g.renderProcesses()
g.editor.renderPathing(&g.Level.Room, g.local.pathingData)
switch g.editor.action {
case editorActionNone:
case editorActionPlaceBlock:
g.editor.renderPlaceBlock(g)
default:
base.Error().Printf("Unexpected editorAction: %v", g.editor.action)
}
}
示例12: 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)
}
示例13: initScene
func initScene(width, height int, init func()) (err error) {
gl.Disable(gl.DEPTH_TEST)
gl.ClearColor(0.5, 0.5, 0.5, 0.0)
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, 0, 1)
gl.MatrixMode(gl.MODELVIEW)
init()
return
}
示例14: Draw
// Draw draws the Sprite object.
func (sprite *Sprite) Draw(frame int) error {
gl.BindBuffer(gl.ARRAY_BUFFER, sprite.shape.vertexBuffer)
gl.VertexAttribPointer(gl.Uint(0), 2, gl.FLOAT, gl.FALSE, 0, gl.Offset(nil, 0))
gl.BindAttribLocation(paunchEffect.program, gl.Uint(0), gl.GLString("position"))
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
if sprite.texcoordBuffer != 0 {
gl.ActiveTexture(gl.TEXTURE0)
gl.BindBuffer(gl.ARRAY_BUFFER, sprite.texcoordBuffer)
gl.VertexAttribPointer(gl.Uint(1), 2, gl.FLOAT, gl.FALSE, 0, gl.Offset(nil, 0))
gl.BindAttribLocation(paunchEffect.program, gl.Uint(0), gl.GLString("texcoord"))
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
gl.BindTexture(gl.TEXTURE_2D, sprite.texture[frame])
gl.EnableVertexAttribArray(gl.Uint(1))
}
gl.EnableVertexAttribArray(gl.Uint(0))
gl.DrawArrays(gl.TRIANGLES, 0, gl.Sizei(sprite.shape.size))
gl.DisableVertexAttribArray(gl.Uint(0))
gl.DisableVertexAttribArray(gl.Uint(1))
gl.BindTexture(gl.TEXTURE_2D, 0)
return checkForErrors()
}
示例15: 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()
}