本文整理汇总了Golang中github.com/go-gl/gl.Color4f函数的典型用法代码示例。如果您正苦于以下问题:Golang Color4f函数的具体用法?Golang Color4f怎么用?Golang Color4f使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Color4f函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: drawString
// drawString draws the same string twice with a colour and location offset,
// to simulate a drop-shadow. It does so for each loaded font.
func drawString(x, y float32, str string) error {
for i := range fonts {
if fonts[i] == nil {
continue
}
// We need to offset each string by the height of the
// font. To ensure they don't overlap each other.
_, h := fonts[i].GlyphBounds()
y := y + float32(i*h)
gl.Color4f(0.1, 0.1, 0.1, 0.7)
err := fonts[i].Printf(x+2, y+2, str)
if err != nil {
return err
}
gl.Color4f(1, 1, 1, 1)
err = fonts[i].Printf(x, y, str)
if err != nil {
return err
}
}
return nil
}
示例2: drawInfoBox
func drawInfoBox(x, y float64, fontSize, iteration, nThreads int, execTime string) {
// TODO
font, err := loadFont("/Users/nils/tmp/DejaVuSansMono.ttf", int32(fontSize))
if err != nil {
log.Printf("LoadFont: %v", err)
return
}
firstLine := fmt.Sprintf("Iteration nr %d", iteration)
secondLine := fmt.Sprintf("Took %s using %d threads.", execTime, nThreads)
w1, h1 := font.Metrics(firstLine)
w2, h2 := font.Metrics(secondLine)
var w int
if w1 > w2 {
w = w1
} else {
w = w2
}
w += 3
h := h1 + h2
gl.Color4f(1, 1, 1, 0.7)
gl.Rectd(x, y, x+float64(w), y+float64(h))
gl.Color4f(0, 0, 0, 1)
err = font.Printf(float32(x)+3, float32(y), firstLine)
if err != nil {
log.Printf("Something went wrong when drawing fonts: %v", err)
return
}
err = font.Printf(float32(x)+3, float32(y+float64(h1)), secondLine)
if err != nil {
log.Printf("Something went wrong when drawing fonts: %v", err)
return
}
}
示例3: 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
}
示例4: 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()
}
}
示例5: 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)
}
示例6: Draw
func (m *Map) Draw() {
gl.PushMatrix()
gl.PushAttrib(gl.CURRENT_BIT | gl.ENABLE_BIT | gl.LIGHTING_BIT | gl.POLYGON_BIT | gl.LINE_BIT)
gl.EnableClientState(gl.VERTEX_ARRAY)
gl.VertexPointer(3, gl.FLOAT, 0, m.vertices)
gl.EnableClientState(gl.NORMAL_ARRAY)
gl.NormalPointer(gl.FLOAT, 0, m.normals)
// gl.EnableClientState(gl.TEXTURE_COORD_ARRAY)
// gl.TexCoordPointer(2, gl.FLOAT, 0, m.texcoords)
gl.EnableClientState(gl.COLOR_ARRAY)
gl.ColorPointer(3, gl.FLOAT, 0, m.colors)
// draw solids
gl.Enable(gl.COLOR_MATERIAL)
// gl.DrawArrays(gl.TRIANGLE_STRIP, 0, len(m.vertices)/3)
gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
gl.LineWidth(1.0)
gl.Color4f(1, 1, 1, 1)
gl.DrawArrays(gl.TRIANGLE_STRIP, 0, len(m.vertices)/3)
gl.PopAttrib()
gl.PopMatrix()
}
示例7: Render
func (p *Pipe) Render() {
gl.Color4f(0.0, 255.0, 0.0, 1.0)
rimHeight := 20
utils.TexturedQuad(p.pipe, p.X, 0, p.Width, p.Y-rimHeight)
utils.TexturedQuad(p.rim, p.X, p.Y-rimHeight, p.Width, rimHeight)
utils.TexturedQuad(p.rim, p.X, p.Y+p.Height, p.Width, rimHeight)
utils.TexturedQuad(p.pipe, p.X, p.Y+p.Height+rimHeight, p.Width, p.ScreenHeight-p.Height)
}
示例8: Printf
func (f *Font) Printf(x float64, y float64, format string, a ...interface{}) (err error) {
var (
str string
//sw int
//sh int
)
str = fmt.Sprintf(format, a...)
gl.Color4f(1, 1, 1, 1)
err = f.font.Printf(float32(x), float32(y), str)
return
}
示例9: drawHex
func drawHex(x, y, kind int, alpha float32) {
if kind == 6 {
gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.REPLACE)
starTex.Bind(gl.TEXTURE_2D)
gl.Begin(gl.QUADS)
gl.TexCoord2f(0, 0)
gl.Vertex2i(x, y)
gl.TexCoord2f(0, 1)
gl.Vertex2i(x, y+HEX_HEIGHT)
gl.TexCoord2f(1, 1)
gl.Vertex2i(x+HEX_WIDTH, y+HEX_HEIGHT)
gl.TexCoord2f(1, 0)
gl.Vertex2i(x+HEX_WIDTH, y)
gl.End()
} else {
gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
var r, g, b float32
switch kind {
case 0:
r = 1
case 1:
g = 1
case 2:
b = 1
case 3:
r = 1
g = 1
case 4:
r = 1
b = 1
case 5:
g = 1 - 222/255
b = 1
}
hexTex.Bind(gl.TEXTURE_2D)
gl.Begin(gl.QUADS)
if alpha < 1 {
gl.Color4f(r, g, b, alpha)
} else {
gl.Color3f(r, g, b)
}
gl.TexCoord2f(0, 0)
gl.Vertex2i(x, y)
gl.TexCoord2f(0, 1)
gl.Vertex2i(x, y+HEX_HEIGHT)
gl.TexCoord2f(1, 1)
gl.Vertex2i(x+HEX_WIDTH, y+HEX_HEIGHT)
gl.TexCoord2f(1, 0)
gl.Vertex2i(x+HEX_WIDTH, y)
gl.End()
}
}
示例10: draw
func (rw *RenderWindow) draw() {
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Enable(gl.LINE_SMOOTH)
for chanIdx, channel := range rw.Channels {
color := channel.GetColor()
gl.Color4f(color[0], color[1], color[2], color[3])
gl.Begin(gl.LINES)
lastY := int64(0)
for i := 0; i < len(rw.renderBuffers[chanIdx]); i += 1 {
y := rw.Height - (rw.renderBuffers[chanIdx][i] * rw.Height / 1024)
gl.Vertex2i(i-1, int(lastY))
gl.Vertex2i(i, int(y))
lastY = y
}
gl.Flush()
gl.End()
}
glfw.SwapBuffers()
}
示例11: TexturedQuad
func TexturedQuad(t *glh.Texture, x, y, w, h int) {
glh.With(t, func() {
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Color4f(255.0, 255.0, 255.0, 1.0)
gl.Begin(gl.TRIANGLE_FAN)
gl.TexCoord2f(0, 0)
gl.Vertex2i(x, y)
gl.TexCoord2f(1, 0)
gl.Vertex2i(x+w, y)
gl.TexCoord2f(1, 1)
gl.Vertex2i(x+w, y+h)
gl.TexCoord2f(0, 1)
gl.Vertex2i(x, y+h)
gl.End()
})
}
示例12: TestWindowCoordsA
// Draw a test pattern
func TestWindowCoordsA(t *testing.T) {
gltest.OnTheMainThread(func() {
gltest.SetWindowSize(40, 5)
w, h := GetViewportWH()
With(WindowCoords{}, func() {
// So that we draw in the middle of the pixel
gl.Translated(0.5, 0.5, 0)
gl.Color4f(1, 1, 1, 1)
With(Primitive{gl.POINTS}, func() {
for i := 0; i < w+1; i += 2 {
gl.Vertex2i(i, h/2)
}
})
})
}, func() {
CaptureToPng("TestWindowCoordsA.png")
})
}
示例13: 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)
gl.Color4f(1, 1, 1, 0.5)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)
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
}
示例14: Text
func (sg *OpenGLGraphics) Text(x, y int, t string, align string, rot int, f chart.Font) {
if len(align) == 1 {
align = "c" + align
}
_, fh, _ := sg.FontMetrics(f)
tex := glh.MakeText(t, float64(fh))
tex.Flipped = true
defer tex.Destroy()
switch align[0] {
case 'b':
case 'c':
y += fh / 2
case 't':
y += fh
default:
log.Panicf("Unknown alignment: ", align)
}
switch align[1] {
case 'l':
case 'c':
x -= tex.W / 2
case 'r':
x -= tex.W
default:
log.Panicf("Unknown alignment: ", align)
}
if f.Color == nil {
gl.Color4f(1, 1, 1, 1)
} else {
glh.ColorC(f.Color)
}
glh.With(tex, func() {
tex.Draw(x, y)
})
}
示例15: color
// Used in classic render mode.
// Defines vertex colors.
func (a *Attr) color(i int) {
i *= a.size
switch a.size {
case 3:
switch v := a.data.(type) {
case []int8:
gl.Color3b(v[i], v[i+1], v[i+2])
case []uint8:
gl.Color3ub(v[i], v[i+1], v[i+2])
case []int16:
gl.Color3s(v[i], v[i+1], v[i+2])
case []int32:
gl.Color3i(int(v[i]), int(v[i+1]), int(v[i+2]))
case []float32:
gl.Color3f(v[i], v[i+1], v[i+2])
case []float64:
gl.Color3d(v[i], v[i+1], v[i+2])
}
case 4:
switch v := a.data.(type) {
case []int8:
gl.Color4b(v[i], v[i+1], v[i+2], v[i+3])
case []uint8:
gl.Color4ub(v[i], v[i+1], v[i+2], v[i+3])
case []int16:
gl.Color4s(v[i], v[i+1], v[i+2], v[i+3])
case []int32:
gl.Color4i(int(v[i]), int(v[i+1]), int(v[i+2]), int(v[i+3]))
case []float32:
gl.Color4f(v[i], v[i+1], v[i+2], v[i+3])
case []float64:
gl.Color4d(v[i], v[i+1], v[i+2], v[i+3])
}
}
}