本文整理汇总了Golang中github.com/go-gl/gl/v2/1/gl.BlendFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang BlendFunc函数的具体用法?Golang BlendFunc怎么用?Golang BlendFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BlendFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: draw
// OpenGL draw function
func draw() {
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Enable(gl.BLEND)
gl.Enable(gl.POINT_SMOOTH)
gl.Enable(gl.LINE_SMOOTH)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.LoadIdentity()
gl.Begin(gl.LINES)
gl.Color3f(.2, .2, .2)
for i := range staticLines {
x := staticLines[i].GetAsSegment().A.X
y := staticLines[i].GetAsSegment().A.Y
gl.Vertex3f(float32(x), float32(y), 0)
x = staticLines[i].GetAsSegment().B.X
y = staticLines[i].GetAsSegment().B.Y
gl.Vertex3f(float32(x), float32(y), 0)
}
gl.End()
gl.Color4f(.3, .3, 1, .8)
// draw balls
for _, ball := range balls {
gl.PushMatrix()
pos := ball.Body.Position()
rot := ball.Body.Angle() * chipmunk.DegreeConst
gl.Translatef(float32(pos.X), float32(pos.Y), 0.0)
gl.Rotatef(float32(rot), 0, 0, 1)
drawCircle(float64(ballRadius), 60)
gl.PopMatrix()
}
}
示例2: init
func (c *Context) init() {
if err := gl.Init(); err != nil {
panic(err)
}
// Textures' pixel formats are alpha premultiplied.
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
}
示例3: main
func main() {
err := glfw.Init()
if err != nil {
panic(err)
}
defer glfw.Terminate()
fp, err := os.Open("example.tmx")
if err != nil {
panic(err)
}
m, err := tmx.NewMap(fp)
if err != nil {
panic(err)
}
var monitor *glfw.Monitor
window, err := glfw.CreateWindow(screenWidth, screenHeight, "Map Renderer", monitor, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
if err := gl.Init(); err != nil {
panic(err)
}
width, height := window.GetFramebufferSize()
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.ClearColor(1.0, 1.0, 1.0, 1.0)
gl.Viewport(0, 0, int32(width), int32(height))
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, float64(width), float64(height), 0, -1, 1)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
canvas := newOpenGLCanvas(width, height, float32(width)/float32(screenWidth), float32(height)/float32(screenHeight))
renderer := tmx.NewRenderer(*m, canvas)
fps := 0
startTime := time.Now().UnixNano()
timer := tmx.CreateTimer()
timer.Start()
for !window.ShouldClose() {
elapsed := float64(timer.GetElapsedTime()) / (1000 * 1000)
renderer.Render(int64(math.Ceil(elapsed)))
fps++
if time.Now().UnixNano()-startTime > 1000*1000*1000 {
log.Println(fps)
startTime = time.Now().UnixNano()
fps = 0
}
window.SwapBuffers()
glfw.PollEvents()
timer.UpdateTime()
}
}
示例4: BlendFunc
func (c *Context) BlendFunc(mode CompositeMode) {
_ = c.runOnContextThread(func() error {
if c.lastCompositeMode == mode {
return nil
}
c.lastCompositeMode = mode
s, d := operations(mode)
gl.BlendFunc(uint32(s), uint32(d))
return nil
})
}
示例5: draw
func draw() {
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Enable(gl.BLEND)
gl.Enable(gl.POINT_SMOOTH)
gl.Enable(gl.LINE_SMOOTH)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.LoadIdentity()
//Transform screen to keep player in middle. Added intentation to make obvious the push matrix is like a block
gl.PushMatrix()
// gl.Translatef((1280/2)-float32(player.x), 0, 0.0)
// gl.Begin(gl.LINES)
// gl.Color3f(.2, .5, .2)
// for i := range staticLines {
// x := staticLines[i].GetAsSegment().A.X
// y := staticLines[i].GetAsSegment().A.Y
// gl.Vertex3f(float32(x), float32(y), 0)
// x = staticLines[i].GetAsSegment().B.X
// y = staticLines[i].GetAsSegment().B.Y
// gl.Vertex3f(float32(x), float32(y), 0)
// }
// gl.End()
gl.Color4f(player.color_r, player.color_g, player.color_b, player.color_a)
//Draw Player
gl.PushMatrix()
rot := player.rot
pos_x := player.x
pos_y := player.y
gl.Translatef(pos_x, pos_y, 0.0)
gl.Rotatef(float32(rot), 0, 0, 1)
drawCircle(float64(BALL_RADIUS), 20)
gl.PopMatrix()
//Draw the grapple
gl.PushMatrix()
gl.Translatef(player.hook.x_end, player.hook.y_end, 0.0)
drawCircle(float64(5), 5)
gl.PopMatrix()
//Grapple Line
gl.LineWidth(2.5)
gl.Color3f(1.0, 0.0, 0.0)
gl.Begin(gl.LINES)
gl.Vertex3f(player.x, player.y, 0.0)
gl.Vertex3f(player.hook.x_end, player.hook.y_end, 0)
gl.End()
//Second Pop
gl.PopMatrix()
}
示例6: main
func main() {
runtime.LockOSThread()
if err := glfw.Init(); err != nil {
panic(err)
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(800, 600, "fontstash example", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
glfw.SwapInterval(1)
gl.Init()
data, err := ioutil.ReadFile(filepath.Join("..", "ClearSans-Regular.ttf"))
if err != nil {
panic(err)
}
gl.Enable(gl.TEXTURE_2D)
tmpBitmap := make([]byte, 512*512)
cdata, err, _, tmpBitmap := truetype.BakeFontBitmap(data, 0, 32, tmpBitmap, 512, 512, 32, 96)
var ftex uint32
gl.GenTextures(1, &ftex)
gl.BindTexture(gl.TEXTURE_2D, ftex)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, 512, 512, 0,
gl.ALPHA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tmpBitmap[0]))
gl.ClearColor(0.3, 0.3, 0.32, 1.)
for !window.ShouldClose() {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, 800, 600, 0, 0, 1)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Disable(gl.DEPTH_TEST)
gl.Color4ub(255, 255, 255, 255)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
my_print(100, 100, "The quick brown fox jumps over the fence", ftex, cdata)
window.SwapBuffers()
glfw.PollEvents()
}
}
示例7: setModelViewOptions
func setModelViewOptions() {
gl.Enable(gl.TEXTURE_2D)
gl.Disable(gl.LIGHTING)
gl.Disable(gl.DITHER)
gl.Enable(gl.CULL_FACE)
gl.CullFace(gl.FRONT)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Enable(gl.BLEND)
gl.Enable(gl.ALPHA_TEST)
gl.DepthFunc(gl.LEQUAL)
gl.Disable(gl.DEPTH_TEST)
}
示例8: reshape
func reshape(window *glfw.Window, w, h int) {
gl.ClearColor(1, 1, 1, 1)
//fmt.Println(gl.GetString(gl.EXTENSIONS))
gl.Viewport(0, 0, int32(w), int32(h)) /* Establish viewing area to cover entire window. */
gl.MatrixMode(gl.PROJECTION) /* Start modifying the projection matrix. */
gl.LoadIdentity() /* Reset project matrix. */
gl.Ortho(0, float64(w), 0, float64(h), -1, 1) /* Map abstract coords directly to window coords. */
gl.Scalef(1, -1, 1) /* Invert Y axis so increasing Y goes down. */
gl.Translatef(0, float32(-h), 0) /* Shift origin up to upper-left corner. */
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Disable(gl.DEPTH_TEST)
width, height = w, h
}
示例9: draw
// OpenGL draw function
func draw() {
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Enable(gl.BLEND)
gl.Enable(gl.POINT_SMOOTH)
gl.Enable(gl.LINE_SMOOTH)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.LoadIdentity()
player := game.Player
//Transform screen.
gl.PushMatrix()
gl.Translatef((1280/2)-float32((player.Body.Position().X)), 0, 0.0)
gl.Begin(gl.LINES)
gl.Color3f(.2, .5, .2)
for _, segment := range game.Level.GetChipmunkSegments() {
x := segment.GetAsSegment().A.X
y := segment.GetAsSegment().A.Y
gl.Vertex3f(float32(x), float32(y), 0)
x = segment.GetAsSegment().B.X
y = segment.GetAsSegment().B.Y
gl.Vertex3f(float32(x), float32(y), 0)
}
gl.End()
gl.Color4f(.9, .1, 1, .9)
// draw balls
for _, enemy := range game.Enemies {
gl.PushMatrix()
pos := enemy.Body.Position()
rot := enemy.Body.Angle() * game.DegreeConst
gl.Translatef(float32(pos.X), float32(pos.Y), 0.0)
gl.Rotatef(float32(rot), 0, 0, 1)
drawCircle(float64(enemy.Radius), 60)
gl.PopMatrix()
}
gl.Color4f(.3, .3, 1, .8)
//Draw Player
gl.PushMatrix()
pos := player.Body.Position()
rot := player.Body.Angle() * game.DegreeConst
gl.Translatef(float32(pos.X), float32(pos.Y), 0.0)
gl.Rotatef(float32(rot), 0, 0, 1)
drawCircle(float64(player.Radius), 60)
gl.PopMatrix()
gl.PopMatrix()
}
示例10: onDisplay
func onDisplay(program uint32, coords uint32) {
gl.ClearColor(1.0, 1.0, 1.0, 1.0)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.UseProgram(program)
gl.EnableVertexAttribArray(coords)
gl.VertexAttribPointer(coords, 2, gl.FLOAT, false, 0, nil)
gl.DrawArrays(gl.TRIANGLES, 0, 3)
gl.DisableVertexAttribArray(coords)
}
示例11: Draw
func (atlas *FontAtlas) Draw(text string, b Bounds) {
atlas.LoadGlyphs(text)
gl.Enable(gl.BLEND)
defer gl.Disable(gl.BLEND)
gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
gl.Enable(gl.TEXTURE_2D)
defer gl.Disable(gl.TEXTURE_2D)
gl.BindTexture(gl.TEXTURE_2D, atlas.Texture)
x := b.Min.X + atlas.drawPadding
y := (b.Max.Y+b.Min.Y)/2 + (ceilPxf(atlas.maxBounds.Min.Y)+ceilPxf(atlas.maxBounds.Max.Y))/2
p := rune(0)
for _, r := range text {
glyph := atlas.Rendered[r]
dx := float32(glyph.Loc.Dx())
dy := float32(glyph.Loc.Dy())
px := x + ceilPxf(glyph.Bounds.Min.X) - glyphPadding
py := y + ceilPxf(glyph.Bounds.Min.Y) - glyphPadding
// this is not the ideal way of positioning the letters
// will create positioning artifacts
// but it the result is more
px = float32(math.Trunc(float64(px)))
py = float32(math.Trunc(float64(py)))
gl.Begin(gl.QUADS)
{
gl.TexCoord2f(glyph.RelLoc.Min.X, glyph.RelLoc.Min.Y)
gl.Vertex2f(px, py)
gl.TexCoord2f(glyph.RelLoc.Max.X, glyph.RelLoc.Min.Y)
gl.Vertex2f(px+dx, py)
gl.TexCoord2f(glyph.RelLoc.Max.X, glyph.RelLoc.Max.Y)
gl.Vertex2f(px+dx, py+dy)
gl.TexCoord2f(glyph.RelLoc.Min.X, glyph.RelLoc.Max.Y)
gl.Vertex2f(px, py+dy)
}
gl.End()
k := atlas.Face.Kern(p, r)
p = r
x += ceilPxf(glyph.Advance + k)
}
}
示例12: draw
func (atlas *FontAtlas) draw(rendered *image.RGBA, b Bounds) {
var texture uint32
gl.Enable(gl.TEXTURE_2D)
gl.GenTextures(1, &texture)
gl.BindTexture(gl.TEXTURE_2D, texture)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
gl.TexImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
int32(rendered.Bounds().Dx()),
int32(rendered.Bounds().Dy()),
0,
gl.RGBA,
gl.UNSIGNED_BYTE,
gl.Ptr(rendered.Pix))
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
gl.Begin(gl.QUADS)
{
gl.TexCoord2f(0, 0)
gl.Vertex2f(b.Min.X, b.Min.Y)
gl.TexCoord2f(1, 0)
gl.Vertex2f(b.Max.X, b.Min.Y)
gl.TexCoord2f(1, 1)
gl.Vertex2f(b.Max.X, b.Max.Y)
gl.TexCoord2f(0, 1)
gl.Vertex2f(b.Min.X, b.Max.Y)
}
gl.End()
gl.Disable(gl.BLEND)
gl.DeleteTextures(1, &texture)
gl.Disable(gl.TEXTURE_2D)
}
示例13: init
func (g *graphics) init() error {
if err := g.loadImages(); err != nil {
return err
}
gl.ClearColor(0, 0, 0.7, 1)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
g.fontStash = fontstash.New(512, 512)
fontID, err := g.fontStash.AddFont(resourcePath("MorrisRoman-Black.ttf"))
if err != nil {
return err
}
g.fontStash.SetYInverted(true)
g.font = NewGLFont(g.fontStash, fontID, 45, [4]float32{0, 0, 0, 1})
return nil
}
示例14: List
func List(width, height int, list *draw.List) {
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Enable(gl.SCISSOR_TEST)
defer gl.Disable(gl.SCISSOR_TEST)
gl.EnableClientState(gl.VERTEX_ARRAY)
defer gl.DisableClientState(gl.VERTEX_ARRAY)
gl.EnableClientState(gl.COLOR_ARRAY)
defer gl.DisableClientState(gl.COLOR_ARRAY)
gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
defer gl.DisableClientState(gl.TEXTURE_COORD_ARRAY)
gl.VertexPointer(2, gl.FLOAT, vertexStride, unsafe.Pointer(&(list.Vertices[0].P)))
gl.TexCoordPointer(2, gl.FLOAT, vertexStride, unsafe.Pointer(&(list.Vertices[0].UV)))
gl.ColorPointer(4, gl.UNSIGNED_BYTE, vertexStride, unsafe.Pointer(&(list.Vertices[0].Color)))
offset := 0
for _, cmd := range list.Commands {
if cmd.Count == 0 {
continue
}
if cmd.Texture == 0 {
gl.Disable(gl.TEXTURE_2D)
} else {
gl.Enable(gl.TEXTURE_2D)
gl.BindTexture(gl.TEXTURE_2D, uint32(cmd.Texture))
}
x, y, w, h := cmd.Clip.AsInt32()
gl.Scissor(x, int32(height)-y-h, w, h)
gl.DrawElements(gl.TRIANGLES, int32(cmd.Count), indexType, gl.Ptr(list.Indicies[offset:]))
offset += int(cmd.Count)
}
}
示例15: BlendFunc
func (c *Context) BlendFunc(src, dst int) {
gl.BlendFunc(uint32(src), uint32(dst))
}