本文整理汇总了Golang中github.com/go-gl/gl.BlendFunc函数的典型用法代码示例。如果您正苦于以下问题:Golang BlendFunc函数的具体用法?Golang BlendFunc怎么用?Golang BlendFunc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BlendFunc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: applyBlendMode
func (r *RenderTarget) applyBlendMode(mode BlendMode) {
switch mode {
// glBlendFuncSeparateEXT is used when available to avoid an incorrect alpha value when the target
// is a RenderTexture -- in this case the alpha value must be written directly to the target buffer
// Alpha blending
default:
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
case BlendAlpha:
/*if (GLEW_EXT_blend_func_separate) {
glBlendFuncSeparateEXT(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
} else {*/
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
//}
// Additive blending
case BlendAdd:
/*if GLEW_EXT_blend_func_separate {
gl.BlendFuncSeparateEXT(gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE)
} else {*/
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)
//}
// Multiplicative blending
case BlendMultiply:
gl.BlendFunc(gl.DST_COLOR, gl.ZERO)
// No blending
case BlendNone:
gl.BlendFunc(gl.ONE, gl.ZERO)
}
r.lastBlendMode = mode
}
示例2: Rect
func (sg *OpenGLGraphics) Rect(x, y, w, h int, style chart.Style) {
// log.Panicf("Unimplemented: %s", whoami())
x, y, w, h = chart.SanitizeRect(x, y, w, h, style.LineWidth)
defer glh.OpenGLSentinel()()
//
glh.With(glh.Attrib{gl.ENABLE_BIT | gl.COLOR_BUFFER_BIT}, func() {
glh.ColorC(style.FillColor)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Begin(gl.QUADS)
glh.Squarei(x, y, w, h)
gl.End()
})
if style.LineWidth != 0 {
gl.LineWidth(float32(style.LineWidth))
//log.Print("Linewidth: ", float32(style.LineWidth))
glh.With(glh.Attrib{gl.ENABLE_BIT | gl.COLOR_BUFFER_BIT}, func() {
glh.ColorC(style.LineColor)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Begin(gl.LINE_LOOP)
glh.Squarei(x, y, w, h)
gl.End()
})
}
// linecol := style.LineColor
// if linecol != "" {
// s = fmt.Sprintf("stroke:%s; ", linecol)
// } else {
// linecol = "#808080"
// }
// s += fmt.Sprintf("stroke-width: %d; ", style.LineWidth)
// s += fmt.Sprintf("opacity: %.2f; ", 1-style.Alpha)
// if style.FillColor != "" {
// s += fmt.Sprintf("fill: %s; fill-opacity: %.2f", style.FillColor, 1-style.Alpha)
// } else {
// s += "fill-opacity: 0"
// }
// sg.svg.Rect(x, y, w, h, s)
// GenericRect(sg, x, y, w, h, style) // TODO
}
示例3: main
func main() {
if !glfw.Init() {
log.Fatal("glfw failed to initialize")
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(640, 480, "Deformable", nil, nil)
if err != nil {
log.Fatal(err.Error())
}
window.MakeContextCurrent()
glfw.SwapInterval(1)
window.SetMouseButtonCallback(handleMouseButton)
window.SetKeyCallback(handleKeyDown)
window.SetInputMode(glfw.Cursor, glfw.CursorHidden)
gl.Init()
initGL()
i := 16
m = GenerateMap(1600/i, 1200/i, i)
for running && !window.ShouldClose() {
x, y := window.GetCursorPosition()
if drawing != 0 {
m.Add(int(x)+int(camera[0]), int(y)+int(camera[1]), drawing, brushSizes[currentBrushSize])
}
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.LoadIdentity()
gl.PushMatrix()
gl.PushAttrib(gl.CURRENT_BIT | gl.ENABLE_BIT | gl.LIGHTING_BIT | gl.POLYGON_BIT | gl.LINE_BIT)
gl.Translatef(-camera[0], -camera[1], 0)
m.Draw()
gl.PopAttrib()
gl.PopMatrix()
gl.PushAttrib(gl.COLOR_BUFFER_BIT)
gl.LineWidth(2)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.ONE_MINUS_DST_COLOR, gl.ZERO)
// gl.Enable(gl.LINE_SMOOTH)
// gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)
gl.Translatef(float32(x), float32(y), 0)
gl.EnableClientState(gl.VERTEX_ARRAY)
gl.VertexPointer(2, gl.DOUBLE, 0, cursorVerts)
gl.DrawArrays(gl.LINE_LOOP, 0, 24)
gl.PopAttrib()
window.SwapBuffers()
glfw.PollEvents()
}
}
示例4: Draw
func (m *Map) Draw() {
// gl.Enable(gl.PRIMITIVE_RESTART)
// gl.PrimitiveRestartIndex(PRIMITIVE_RESTART)
gl.EnableClientState(gl.VERTEX_ARRAY)
gl.Translatef(float32(m.gridSize/2), float32(m.gridSize/2), 0)
if m.renderSmooth {
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Enable(gl.POLYGON_SMOOTH)
gl.Hint(gl.POLYGON_SMOOTH_HINT, gl.NICEST)
}
if m.renderMode == 1 {
gl.LineWidth(1)
gl.VertexPointer(2, gl.FLOAT, 0, m.gridLines)
gl.Color3f(0.2, 0.2, 0.2)
gl.DrawArrays(gl.LINES, 0, len(m.gridLines)/2)
gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
}
for _, vl := range m.vl {
if len(vl.vertices) > 0 {
gl.VertexPointer(2, gl.FLOAT, 0, vl.vertices)
gl.Color3f(vl.colors[0], vl.colors[1], vl.colors[2])
gl.DrawElements(gl.TRIANGLES, len(vl.indices), gl.UNSIGNED_INT, vl.indices)
}
}
}
示例5: initGL
func initGL() (err error) {
goph, err := os.Open(texturefiles[0])
if err != nil {
panic(err)
}
defer goph.Close()
texture, err = createTexture(goph)
gl.ShadeModel(gl.SMOOTH)
gl.ClearColor(0, 0, 0, 0.5)
gl.ClearDepth(1)
gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE) // 设置混色函数取得半透明效果
gl.Enable(gl.BLEND)
gl.Enable(gl.TEXTURE_2D)
rand.Seed(time.Now().Unix())
for loop = 0; loop < num; loop++ {
star[loop].angle = 0.0
star[loop].dist = float32(loop) / num * 5
//fmt.Println(loop, star[loop].dist)
star[loop].r = uint8(rand.Int() % 256)
star[loop].g = uint8(rand.Int() % 256)
star[loop].b = uint8(rand.Int() % 256)
}
return
}
示例6: lineTo
func (pen *Pen) lineTo(x, y int) {
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.Color4f(0.0, 0.0, 0.0, 0.1)
gl.Begin(gl.LINES)
var p [2]int
for i := range pen.points {
p = pen.points[i]
if p[0] == 0 && p[1] == 0 {
continue
}
if distanceTo(x, y, p[0], p[1]) < 10.0 {
gl.Vertex2i(x, y)
gl.Vertex2i(p[0], p[1])
}
}
gl.End()
pen.n = (pen.n + 1) % len(pen.points)
pen.points[pen.n][0] = x
pen.points[pen.n][1] = y
pen.moveTo(x, y)
}
示例7: Open
// Opens a new window.
func (c *Controller) Open(win *Window) (err error) {
c.Win = win
mode := glfw.Windowed
if win.Fullscreen {
mode = glfw.Fullscreen
}
if win.Resize == false {
glfw.OpenWindowHint(glfw.WindowNoResize, 1)
}
if err = glfw.OpenWindow(win.Width, win.Height, 0, 0, 0, 0, 0, 0, mode); err != nil {
return
}
gl.Init()
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
v1, v2, v3 := glfw.GLVersion()
log.Printf("OpenGL version: %v %v %v\n", v1, v2, v3)
fb_supported := glfw.ExtensionSupported("GL_EXT_framebuffer_object")
log.Printf("Framebuffer supported: %v\n", fb_supported)
c.SetClearColor(0, 0, 0, 0)
if win.VSync == true {
glfw.SetSwapInterval(1) // Limit to refresh
}
glfw.SetWindowTitle(win.Title)
glfw.SetWindowSizeCallback(func(w, h int) {
log.Printf("Resizing window to %v, %v\n", w, h)
c.resize()
})
err = c.resize()
return
}
示例8: Line
func (sg *OpenGLGraphics) Line(x0, y0, x1, y1 int, style chart.Style) {
//log.Panicf("Unimplemented: %s", whoami())
defer glh.OpenGLSentinel()()
gl.LineWidth(float32(style.LineWidth))
// TODO: line stipple?
//sc := chart.Color2RGBA(style.LineColor, uint8(style.Alpha*255))
//log.Printf("color: %s %d %d %d %d", style.FillColor, sc.R, sc.G, sc.B, sc.A)
glh.ColorC(style.LineColor)
//sc := style.LineColor
//gl.Color4ub(sc.R, sc.G, sc.B, sc.A)
// TODO: Check this works
glh.With(glh.Attrib{gl.ENABLE_BIT | gl.COLOR_BUFFER_BIT}, func() {
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
glh.With(glh.Primitive{gl.LINES}, func() {
gl.Vertex2i(x0, y0)
gl.Vertex2i(x1, y1)
})
})
}
示例9: initGL
// initGL initializes GLFW and OpenGL.
func initGL(c *cpu.CPU, width, height int) error {
err := glfw.Init()
if err != nil {
return err
}
glfw.OpenWindowHint(glfw.WindowNoResize, 1)
err = glfw.OpenWindow(width, height, 8, 8, 8, 8, 8, 0, glfw.Windowed)
if err != nil {
glfw.Terminate()
return err
}
glfw.SetWindowTitle("DCPU")
glfw.SetSwapInterval(1)
glfw.SetWindowSizeCallback(onResize)
gl.Init()
err = glh.CheckGLError()
if err != nil {
return err
}
gl.Disable(gl.LIGHTING)
gl.Disable(gl.DEPTH_TEST)
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.ClearColor(0, 0, 0, 1)
return err
}
示例10: draw
func (s *System) draw() {
s.cmds <- func() {
gl.Enable(gl.DEPTH_TEST)
gl.Enable(gl.BLEND)
gl.DepthFunc(gl.LEQUAL)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
//s.shader.Use()
//s.shader.AssignUniforms(uniforms)
}
for _, _ = range s.meshes.layouts {
s.submit(renderState{})
}
for i := range s.buckets {
list := &s.buckets[i]
list.sort()
s.cmds <- list.execute
}
return
/*
s.cmds <- func() {
for _, geom := range geoms {
// gl state
// texture units
// uniforms
//shader.AssignUniforms()
shader.SetGeometry(&geom)
shader.Draw()
}
}
*/
}
示例11: initGL
func initGL() (err error) {
if err = loadTextures(); err != nil {
return
}
gl.ShadeModel(gl.SMOOTH)
gl.ClearColor(0, 0, 0, 0)
gl.ClearDepth(1)
gl.DepthFunc(gl.LEQUAL)
gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.DEPTH_TEST)
//alpha通道的值为 0.0意味着物体材质是完全透明的。1.0 则意味着完全不透明
//以全亮度绘制此物体,并对其进行50%的alpha混合(半透明)。
//当混合选项打开时,此物体将会产生50%的透明效果
gl.Color4f(1, 1, 1, 0.5) //全亮度, 50% Alpha 混合
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE) //基于源象素alpha通道值的半透明混合函数
gl.Lightfv(gl.LIGHT1, gl.AMBIENT, ambient)
gl.Lightfv(gl.LIGHT1, gl.AMBIENT, diffuse)
gl.Lightfv(gl.LIGHT1, gl.POSITION, lightpos)
gl.Enable(gl.LIGHT1)
return
}
示例12: initGL
// initGL initializes GLFW and OpenGL.
func initGL() error {
err := glfw.Init()
if err != nil {
return err
}
err = glfw.OpenWindow(AtlasSize, AtlasSize, 8, 8, 8, 8, 0, 0, glfw.Windowed)
if err != nil {
glfw.Terminate()
return err
}
glfw.SetWindowTitle("Texture atlas example")
glfw.SetSwapInterval(1)
glfw.SetWindowSizeCallback(onResize)
glfw.SetKeyCallback(onKey)
gl.Init()
if err = glh.CheckGLError(); err != nil {
return err
}
gl.Disable(gl.DEPTH_TEST)
gl.Disable(gl.LIGHTING)
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.ClearColor(0.2, 0.2, 0.23, 1.0)
return nil
}
示例13: 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()
}
}
示例14: Bind
// Binds the framebuffer for drawing.
func (fb *Framebuffer) Bind() {
fb.Buffer.Bind()
gl.Viewport(0, 0, fb.Width, fb.Height)
gl.Enable(gl.TEXTURE_2D)
gl.Disable(gl.DEPTH_TEST)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Enable(gl.BLEND)
}
示例15: main
func main() {
_ = fmt.Sprint()
if !glfw.Init() {
panic("Can't init glfw!")
}
defer glfw.Terminate()
// antialiasing
//glfw.WindowHint(glfw.Samples, 4)
window, err = glfw.CreateWindow(WindowWidth, WindowHeight, "Mozaik", nil, nil)
if err != nil {
panic(err)
}
defer window.Destroy()
// Ensure thread context
window.MakeContextCurrent()
//glfw.SwapInterval(1)
window.SetKeyCallback(keyCb)
window.SetMouseButtonCallback(mouseCb)
gl.Init()
gl.ClearColor(0.9, 0.85, 0.46, 0.0)
// useless in 2D
gl.Disable(gl.DEPTH_TEST)
// antialiasing
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Enable(gl.LINE_SMOOTH)
for i := int32(32); i < 72; i++ {
font := loadFonts(i)
defer font.Release()
fonts = append(fonts, font)
}
// Compute window radius
windowRadius = math.Sqrt(math.Pow(WindowHeight, 2) + math.Pow(WindowWidth, 2))
// Use window coordinates
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, WindowWidth, WindowHeight, 0, 0, 1)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
g = NewGame()
g.Start()
go eventLoop(g)
go renderLoop(g)
Main()
g.Stop()
}