本文整理汇总了Golang中github.com/go-gl/gl/v2/1/gl.Begin函数的典型用法代码示例。如果您正苦于以下问题:Golang Begin函数的具体用法?Golang Begin怎么用?Golang Begin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Begin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: drawInnerSlicedBox
func drawInnerSlicedBox(pos, size mgl64.Vec2, borderColor, backgroundColor mgl64.Vec3) {
if size[0] == 0 || size[1] == 0 {
return
}
const OuterDistance = 2.5
gl.Begin(gl.POLYGON)
gl.Color3dv((*float64)(&borderColor[0]))
gl.Vertex2d(float64(pos[0]+OuterDistance), float64(pos[1]))
gl.Vertex2d(float64(pos[0]), float64(pos[1]+OuterDistance))
gl.Vertex2d(float64(pos[0]), float64(pos[1]-OuterDistance+size[1]))
gl.Vertex2d(float64(pos[0]+OuterDistance), float64(pos[1]+size[1]))
gl.Vertex2d(float64(pos[0]-OuterDistance+size[0]), float64(pos[1]+size[1]))
gl.Vertex2d(float64(pos[0]+size[0]), float64(pos[1]-OuterDistance+size[1]))
gl.Vertex2d(float64(pos[0]+size[0]), float64(pos[1]+OuterDistance))
gl.Vertex2d(float64(pos[0]-OuterDistance+size[0]), float64(pos[1]))
gl.End()
const InnerDistance = OuterDistance + (math.Sqrt2 - 1)
gl.Begin(gl.POLYGON)
gl.Color3dv((*float64)(&backgroundColor[0]))
gl.Vertex2d(float64(pos[0]+InnerDistance), float64(pos[1]+1))
gl.Vertex2d(float64(pos[0]+1), float64(pos[1]+InnerDistance))
gl.Vertex2d(float64(pos[0]+1), float64(pos[1]-InnerDistance+size[1]))
gl.Vertex2d(float64(pos[0]+InnerDistance), float64(pos[1]-1+size[1]))
gl.Vertex2d(float64(pos[0]-InnerDistance+size[0]), float64(pos[1]-1+size[1]))
gl.Vertex2d(float64(pos[0]-1+size[0]), float64(pos[1]-InnerDistance+size[1]))
gl.Vertex2d(float64(pos[0]-1+size[0]), float64(pos[1]+InnerDistance))
gl.Vertex2d(float64(pos[0]-InnerDistance+size[0]), float64(pos[1]+1))
gl.End()
}
示例2: drawRoom
func drawRoom(room *Room) {
h := float64(room.Box.GetAsBox().Height)
w := float64(room.Box.GetAsBox().Width)
x1 := float64(0 - w*0.5)
y1 := float64(0 - h*0.5)
x2 := float64(0 + w*0.5)
y2 := float64(0 - h*0.5)
x3 := float64(0 + w*0.5)
y3 := float64(0 + h*0.5)
x4 := float64(0 - w*0.5)
y4 := float64(0 + h*0.5)
gl.Begin(gl.POLYGON)
gl.Color4f(
room.Color.X(),
room.Color.Y(),
room.Color.Z(),
room.Color.W(),
)
gl.Vertex2d(x1, y1)
gl.Vertex2d(x2, y2)
gl.Vertex2d(x3, y3)
gl.Vertex2d(x4, y4)
gl.End()
gl.Begin(gl.LINE_LOOP)
gl.Color4f(.3, .3, 1, .9)
gl.LineWidth(1.0)
gl.Vertex2d(x1, y1)
gl.Vertex2d(x2, y2)
gl.Vertex2d(x3, y3)
gl.Vertex2d(x4, y4)
gl.End()
}
示例3: drawScene
func drawScene(w *glfw.Window) {
width, height := w.GetFramebufferSize()
ratio := float32(width) / float32(height)
var x1, x2, y1, y2 float32
if ratio > 1 {
x1, x2, y1, y2 = -ratio, ratio, -1, 1
} else {
x1, x2, y1, y2 = -1, 1, -1/ratio, 1/ratio
}
gl.Viewport(0, 0, int32(width), int32(height))
gl.Clear(gl.COLOR_BUFFER_BIT)
// Applies subsequent matrix operations to the projection matrix stack
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity() // replace the current matrix with the identity matrix
gl.Ortho(float64(x1), float64(x2), float64(y1), float64(y2), 1, -1) // multiply the current matrix with an orthographic matrix
// Applies subsequent matrix operations to the modelview matrix stack
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.LineWidth(1)
gl.Begin(gl.LINE) // delimit the vertices of a primitive or a group of like primitives
gl.Color3f(0, 0, 0) // set the current color
gl.Vertex3f(0, y1, 0)
gl.Vertex3f(0, y2, 0)
gl.Vertex3f(x1, 0, 0)
gl.Vertex3f(x2, 0, 0)
gl.End()
gl.Rotatef(float32(glfw.GetTime()*50), 0, 0, 1) // multiply the current matrix by a rotation matrix
s := float32(.95)
gl.Begin(gl.TRIANGLES)
gl.Color3f(1, 0, 0) // set the current color
gl.Vertex3f(0, s, 0) // specify a vertex
gl.Color3f(0, 1, 0)
gl.Vertex3f(s*.866, s*-0.5, 0)
gl.Color3f(0, 0, 1)
gl.Vertex3f(s*-.866, s*-0.5, 0)
gl.End()
gl.LineWidth(5)
gl.Begin(gl.LINE_LOOP)
for i := float64(0); i < 2*math.Pi; i += .05 {
r, g, b := hsb2rgb(float32(i/(2*math.Pi)), 1, 1)
gl.Color3f(r, g, b)
gl.Vertex3f(s*float32(math.Sin(i)), s*float32(math.Cos(i)), 0)
}
gl.End()
}
示例4: drawHud
func (ctx *DrawContext) drawHud(o *orrery.Orrery, frametime time.Duration) {
txt, size, err := ctx.createHudTexture(o, frametime)
if err != nil {
log.Fatalf(`can't create texture from text surface: %s`, err)
}
defer gl.DeleteTextures(1, &txt)
gl.MatrixMode(gl.PROJECTION)
gl.PushMatrix()
gl.LoadIdentity()
gl.Ortho(0.0, float64(ctx.width), float64(ctx.height), 0.0, -1.0, 1.0)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Clear(gl.DEPTH_BUFFER_BIT)
gl.BindTexture(gl.TEXTURE_2D, txt)
gl.Enable(gl.TEXTURE_2D)
defer gl.Disable(gl.TEXTURE_2D)
gl.Color3f(1, 1, 1)
gl.Begin(gl.QUADS)
gl.TexCoord2f(0, 0)
gl.Vertex2f(0.0, 0.0)
gl.TexCoord2f(1, 0)
gl.Vertex2f(float32(size[0]), 0.0)
gl.TexCoord2f(1, 1)
gl.Vertex2f(float32(size[0]), float32(size[1]))
gl.TexCoord2f(0, 1)
gl.Vertex2f(0.0, float32(size[1]))
gl.End()
gl.PopMatrix()
}
示例5: DrawColoredAtXY
func (img *glImage) DrawColoredAtXY(x, y int, color [4]float32) {
// TODO have the state knwon globally somewhere so this does not need to be
// called all the time
gl.Enable(gl.TEXTURE_2D)
gl.BindTexture(gl.TEXTURE_2D, img.id)
gl.Begin(gl.QUADS)
gl.Color4f(color[0], color[1], color[2], color[3])
gl.TexCoord2f(img.left, img.top)
gl.Vertex2i(int32(x), int32(y))
gl.Color4f(color[0], color[1], color[2], color[3])
gl.TexCoord2f(img.right, img.top)
gl.Vertex2i(int32(x+img.Width), int32(y))
gl.Color4f(color[0], color[1], color[2], color[3])
gl.TexCoord2f(img.right, img.bottom)
gl.Vertex2i(int32(x+img.Width), int32(y+img.Height))
gl.Color4f(color[0], color[1], color[2], color[3])
gl.TexCoord2f(img.left, img.bottom)
gl.Vertex2i(int32(x), int32(y+img.Height))
gl.End()
}
示例6: drawSlide
func drawSlide() {
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Translatef(0, 0, -3.0)
gl.Begin(gl.QUADS)
//top left
gl.TexCoord2f(0, 0)
gl.Vertex3f(-1, 1, 0)
//top right
gl.TexCoord2f(1, 0)
gl.Vertex3f(1, 1, 0)
//bottom right
gl.TexCoord2f(1, 1)
gl.Vertex3f(1, -1, 0)
//bottom left
gl.TexCoord2f(0, 1)
gl.Vertex3f(-1, -1, 0)
gl.End()
}
示例7:
func piirräPisteetSiirrolla(pisteet []vec2.Vector, siirto vec2.Vector) {
gl.Begin(gl.LINE_STRIP)
for _, p := range pisteet {
piirräPiste(p.Plus(siirto))
}
gl.End()
}
示例8: MakePolygon
func MakePolygon(points ...Vertex) Polygon {
gl.Begin(gl.POLYGON)
for _, p := range points {
gl.Vertex2i(p.X, p.Y)
}
return Polygon{}
}
示例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()
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()
}
}
示例10: drawCircle
// drawCircle draws a circle for the specified radius, rotation angle, and the specified number of sides
func drawCircle(radius float64, sides int) {
gl.Begin(gl.LINE_LOOP)
for a := 0.0; a < 2*math.Pi; a += (2 * math.Pi / float64(sides)) {
gl.Vertex2d(math.Sin(a)*radius, math.Cos(a)*radius)
}
gl.Vertex3f(0, 0, 0)
gl.End()
}
示例11: drawCircle
// drawCircle draws a circle for the specified radius, rotation angle, and the specified number of sides
func drawCircle(radius float64, sides int) {
gl.Begin(gl.TRIANGLE_FAN)
for a := 0.0; a < 2*math.Pi; a += (2 * math.Pi / float64(70)) {
gl.Vertex2d(math.Sin(a)*radius, math.Cos(a)*radius)
}
gl.Vertex3f(0, 0, 0)
gl.End()
}
示例12: drawInnerRoundedBox
func drawInnerRoundedBox(pos, size mgl64.Vec2, borderColor, backgroundColor mgl64.Vec3) {
if size[0] == 0 || size[1] == 0 {
return
}
const totalSlices = 4 * 16
const borderWidth = 1
const radius = 2.5 + borderWidth
var x = float64(totalSlices)
gl.Color3dv((*float64)(&backgroundColor[0]))
gl.Begin(gl.TRIANGLE_STRIP)
for i := 0; i <= totalSlices/4; i++ {
gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(totalSlices-i)/x)*(radius-borderWidth), pos[1]+radius-math.Cos(Tau*float64(totalSlices-i)/x)*(radius-borderWidth))
}
for i := totalSlices / 4; i <= totalSlices/2; i++ {
gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(totalSlices-i)/x)*(radius-borderWidth), pos[1]+size[1]-radius-math.Cos(Tau*float64(totalSlices-i)/x)*(radius-borderWidth))
}
gl.End()
gl.Color3dv((*float64)(&borderColor[0]))
gl.Begin(gl.TRIANGLE_STRIP)
gl.Vertex2d(pos[0]+radius, pos[1])
gl.Vertex2d(pos[0]+radius, pos[1]+borderWidth)
for i := 0; i <= totalSlices/4; i++ {
gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*radius, pos[1]+radius-math.Cos(Tau*float64(i)/x)*radius)
gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
}
for i := totalSlices / 4; i <= totalSlices/2; i++ {
gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*radius, pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*radius)
gl.Vertex2d(pos[0]+size[0]-radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
}
for i := totalSlices / 2; i <= totalSlices*3/4; i++ {
gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(i)/x)*radius, pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*radius)
gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+size[1]-radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
}
for i := totalSlices * 3 / 4; i <= totalSlices; i++ {
gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(i)/x)*radius, pos[1]+radius-math.Cos(Tau*float64(i)/x)*radius)
gl.Vertex2d(pos[0]+radius+math.Sin(Tau*float64(i)/x)*(radius-borderWidth), pos[1]+radius-math.Cos(Tau*float64(i)/x)*(radius-borderWidth))
}
gl.End()
}
示例13: drawSelection
func drawSelection(x, y, p, w float32) {
gl.LineWidth(w)
gl.Begin(gl.LINE_STRIP)
gl.Vertex2f(x-p, y-p)
gl.Vertex2f(x+256+p, y-p)
gl.Vertex2f(x+256+p, y+240+p)
gl.Vertex2f(x-p, y+240+p)
gl.Vertex2f(x-p, y-p)
gl.End()
}
示例14: Render
func (this *Pointer) Render() {
switch {
case this.VirtualCategory == POINTING && len(this.State.Axes) >= 2:
// Prevent pointer from being drawn when the OS mouse pointer is visible.
{
// HACK
var windowSize [2]int
if globalWindow != nil {
windowSize[0], windowSize[1] = globalWindow.GetSize()
}
// HACK: OS X specific.
const border = 3
if this.State.Axes[1] < 0 || this.State.Axes[0] < border || this.State.Axes[0] >= float64(windowSize[0])-border || this.State.Axes[1] >= float64(windowSize[1])-border {
break
}
}
gl.PushMatrix()
defer gl.PopMatrix()
gl.Translated(float64(NearInt64(this.State.Axes[0]))+0.5, float64(NearInt64(this.State.Axes[1]))+0.5, 0)
const size float64 = 12 * 40 / 40
gl.Color3d(1, 1, 1)
gl.Begin(gl.TRIANGLE_FAN)
gl.Vertex2d(0, 0)
gl.Vertex2d(0, size)
gl.Vertex2d(size*0.85*math.Sin(math.Pi/8), size*0.85*math.Cos(math.Pi/8))
gl.Vertex2d(size/math.Sqrt2, size/math.Sqrt2)
gl.End()
gl.Begin(gl.LINE_LOOP)
gl.Color3d(0, 0, 0)
gl.Vertex2d(0, 0)
gl.Vertex2d(0, size)
gl.Color3d(0.75, 0.75, 0.75)
gl.Vertex2d(size*0.85*math.Sin(math.Pi/8), size*0.85*math.Cos(math.Pi/8))
gl.Color3d(0, 0, 0)
gl.Vertex2d(size/math.Sqrt2, size/math.Sqrt2)
gl.End()
}
}
示例15: Fill
func (back *glbackend) Fill(b Bounds) {
gl.Color4ub(back.current.back.RGBA())
gl.Begin(gl.QUADS)
{
gl.Vertex2f(b.Min.X, b.Min.Y)
gl.Vertex2f(b.Max.X, b.Min.Y)
gl.Vertex2f(b.Max.X, b.Max.Y)
gl.Vertex2f(b.Min.X, b.Max.Y)
}
gl.End()
}