• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang gl.Color4f函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/go-gl/gl.Color4f函数的典型用法代码示例。如果您正苦于以下问题:Golang Color4f函数的具体用法?Golang Color4f怎么用?Golang Color4f使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Color4f函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:jayschwa,项目名称:examples,代码行数:28,代码来源:main.go


示例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
	}

}
开发者ID:nightlifelover,项目名称:GoMandelbrot,代码行数:49,代码来源:inputoutput.go


示例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
}
开发者ID:bonly,项目名称:exercise,代码行数:25,代码来源:20110519_nehe08.go


示例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()
	}
}
开发者ID:niksaak,项目名称:chipmunk,代码行数:33,代码来源:bouncing_balls.go


示例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)
}
开发者ID:jayschwa,项目名称:examples,代码行数:28,代码来源:main.go


示例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()

}
开发者ID:sixthgear,项目名称:landscapes,代码行数:30,代码来源:map.go


示例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)
}
开发者ID:Tohie,项目名称:GoFlappyBird,代码行数:8,代码来源:pipe.go


示例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
}
开发者ID:pikkpoiss,项目名称:ld27,代码行数:11,代码来源:text.go


示例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()
	}
}
开发者ID:TheOnly92,项目名称:gexic,代码行数:53,代码来源:main.go


示例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()
}
开发者ID:jreimers,项目名称:goscilloscope,代码行数:19,代码来源:window.go


示例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()
	})
}
开发者ID:Tohie,项目名称:GoFlappyBird,代码行数:19,代码来源:tex.go


示例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")
	})
}
开发者ID:pwaller,项目名称:glh,代码行数:21,代码来源:glh_test.go


示例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
}
开发者ID:pwaller,项目名称:examples,代码行数:21,代码来源:main.go


示例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)
	})
}
开发者ID:go-gl-legacy,项目名称:glchart,代码行数:40,代码来源:openglg.go


示例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])
		}
	}
}
开发者ID:nobonobo,项目名称:glh,代码行数:38,代码来源:meshattr.go


示例16: DebugLines

// Draws a cross on the screen with known lengths, useful for understanding
// screen dimensions
func DebugLines() {
	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	//gl.LoadIdentity()
	//gl.Ortho(-2.1, 6.1, -4, 8, 1, -1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.LoadIdentity()
	gl.LineWidth(5)
	gl.Color4f(1, 1, 0, 1)
	gl.Begin(gl.LINES)
	gl.Vertex2d(0, -1.6)
	gl.Vertex2d(0, 0.8)
	gl.Vertex2d(-0.8, 0)
	gl.Vertex2d(0.8, 0)
	gl.End()
	gl.PopMatrix()

	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
}
开发者ID:jasonrpowers,项目名称:glh,代码行数:26,代码来源:util.go


示例17: TestWindowCoords

// Draw a test pattern
func TestWindowCoords(t *testing.T) {
	gltest.OnTheMainThread(func() {
		gltest.SetWindowSize(40, 40)

		w, h := GetViewportWH()
		With(WindowCoords{}, func() {
			// So that we draw in the middle of the pixel
			gl.Translated(0.5, 0.5, 0)

			// Draw stripes
			stride := 1
			internal_n := 4
			for b := 0; b < w/2-internal_n*stride; b += stride {
				if b/stride%2 == 0 {
					gl.Color4f(1, 1, 1, 1)
				} else {
					gl.Color4f(1, 0, 0, 1)
				}
				With(Primitive{gl.LINE_LOOP}, func() {
					gl.Vertex2i(b, b)
					gl.Vertex2i(w-b, b)
					gl.Vertex2i(w-b, h-b)
					gl.Vertex2i(b, h-b)
				})
			}

			// Central white, green, blue checked pattern
			gl.PointSize(2)
			With(Primitive{gl.POINTS}, func() {
				gl.Color4f(1, 1, 1, 1)
				gl.Vertex2i(w/2-2, h/2-2)
				gl.Vertex2i(w/2+2, h/2+2)

				gl.Color4f(0, 1, 0, 1)
				gl.Vertex2i(w/2+2, h/2-2)
				gl.Vertex2i(w/2-2, h/2+2)

				gl.Color4f(1, 1, 1, 1)
				gl.Vertex2i(w/2, h/2)
			})

			// Blue horizontal line to show
			With(Primitive{gl.LINE_LOOP}, func() {
				gl.Color4f(0, 0, 1, 1)
				gl.Vertex2i(0, h/2-4)
				gl.Vertex2i(w, h/2-4)

				gl.Vertex2i(w/2-4, 0)
				gl.Vertex2i(w/2-4, h)
			})

			// Remove some pixels near the boundaries
			gl.PointSize(1)
			gl.Color4f(0, 0, 0, 1)
			With(Primitive{gl.POINTS}, func() {
				// Black dot in top left
				gl.Vertex2i(0, 0)
				// Off the top right (should not be visible)
				gl.Vertex2i(w, 0)
				// Bottom left pixel (should be visible as a black dot)
				gl.Vertex2i(0, h-1)
			})
		})
	}, func() {
		CaptureToPng("TestWindowCoords.png")
	})
}
开发者ID:pwaller,项目名称:glh,代码行数:68,代码来源:glh_test.go


示例18: main_loop


//.........这里部分代码省略.........
		dpy := py - mousepy
		di := int64(-dpy * float64(*nback) / 4.)

		if lbutton {
			i += di
		}

		mousepx, mousepy = px, py
		mousex, mousey = x, y

		//log.Printf("Mouse motion: (%3d, %3d), (%f, %f), (%d, %d) dpy=%f di=%d",
		//x, y, px, py, rec, rec_actual, dpy, di)

		update_text()
	})

	glfw.SetKeyCallback(func(key, state int) {
		switch key {
		case glfw.KeyEsc:
			escape_hit = true
		}
	})

	draw_mousepoint := func() {

		// Draw the mouse point
		glh.With(glh.Matrix{gl.MODELVIEW}, func() {
			gl.Translated(0, -2, 0)
			gl.Scaled(1, 4/float64(*nback), 1)
			gl.Translated(0, float64(rec), 0)

			gl.PointSize(10)
			glh.With(glh.Primitive{gl.POINTS}, func() {
				gl.Color4f(1, 1, 1, 1)
				gl.Vertex3d(mousepx, 0, 0)
			})
		})
	}

	draw_text := func() {
		// Draw any text
		glh.With(glh.WindowCoords{}, func() {
			w, h := glh.GetViewportWHD()

			glh.With(glh.Attrib{gl.ENABLE_BIT}, func() {
				gl.Enable(gl.TEXTURE_2D)
				// text.Draw(0, 0)
				for text_idx := range stacktext {
					stacktext[text_idx].Draw(int(w*0.55), int(h)-35-text_idx*16)
				}
				for text_idx := range dwarftext {
					dwarftext[text_idx].Draw(int(w*0.55), 35+text_idx*16)
				}
				if recordtext != nil {
					recordtext.Draw(int(w*0.55), 35)
				}
			})
		})
	}

	Draw = func() {

		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

		// Draw the memory access/function data
		data.Draw(i, *nback)
开发者ID:pwaller,项目名称:mema,代码行数:67,代码来源:main.go


示例19: main


//.........这里部分代码省略.........
	stars := glh.NewMeshBuffer(
		glh.RenderArrays,
		glh.NewPositionAttr(3, gl.DOUBLE, gl.STATIC_DRAW),
		glh.NewColorAttr(3, gl.DOUBLE, gl.STATIC_DRAW))

	const Nstars = 50000
	points := make([]float64, 3*Nstars)
	colors := make([]float64, 3*Nstars)

	for i := 0; i < Nstars; i++ {
		const R = 1

		phi := rand.Float64() * 2 * math.Pi
		z := R * (2*rand.Float64() - 1)
		theta := math.Asin(z / R)

		points[i*3+0] = R * math.Cos(theta) * math.Cos(phi)
		points[i*3+1] = R * math.Cos(theta) * math.Sin(phi)
		points[i*3+2] = z

		const r = 0.8
		v := rand.Float64()*r + (1 - r)
		colors[i*3+0] = v
		colors[i*3+1] = v
		colors[i*3+2] = v
	}

	stars.Add(points, colors)

	render_stars := func() {
		glh.With(glh.Attrib{gl.DEPTH_BUFFER_BIT | gl.ENABLE_BIT}, func() {
			gl.Disable(gl.LIGHTING)
			gl.PointSize(1)
			gl.Color4f(1, 1, 1, 1)

			gl.Disable(gl.DEPTH_TEST)
			gl.DepthMask(false)

			stars.Render(gl.POINTS)
		})
	}

	render_scene := func() {

		// Update light position (sensitive to current modelview matrix)
		gl.Lightfv(gl.LIGHT1, gl.POSITION, light_position)
		gl.Lightfv(gl.LIGHT2, gl.POSITION, light_position)

		if earth {
			Sphere(earth_radius, faces)
		}

		unlit_points := glh.Compound(glh.Disable(gl.LIGHTING), glh.Primitive{gl.POINTS})
		glh.With(unlit_points, func() {
			gl.Vertex3d(1, 0, 0)
		})

		for _, p := range planetoids {
			const dt = 0.1 // TODO: Frame update
			p.Render(dt)
		}

		glh.With(glh.Disable(gl.LIGHTING), func() {
			// Atmosphere
			gl.Color4f(0.25, 0.25, 1, 0.1)
开发者ID:pwaller,项目名称:debris,代码行数:66,代码来源:main.go


示例20: Render

func (r *RenderTarget) Render(verts []Vertex, primType PrimitiveType, states RenderStates) {
	// Nothing to draw?
	if len(verts) == 0 {
		return
	}

	// First set the persistent OpenGL states if it's the very first call
	if !r.glStatesSet {
		r.resetGlStates()
	}

	// Check if the vertex count is low enough so that we can pre-transform them
	useVertexCache := len(verts) <= vertexCacheSize
	if useVertexCache {
		// Pre-transform the vertices and store them into the vertex cache
		for i := 0; i < len(verts); i++ {
			r.vpCache[i] = states.Transform.TransformPoint(verts[i].Pos)
			r.vcCache[i] = verts[i].Color
			r.vtCache[i] = verts[i].TexCoords
		}

		// Since vertices are transformed, we must use an identity transform to render them
		if !r.useVertexCache {
			r.applyTransform(IdentityTransform())
		}
	} else {
		r.applyTransform(states.Transform)
	}

	// Apply the view
	if r.viewChanged {
		r.applyCurrentView()
	}

	// Apply the blend mode
	if states.BlendMode != r.lastBlendMode {
		r.applyBlendMode(states.BlendMode)
	}

	// Apply the texture
	var textureId uint64
	if states.Texture != nil {
		textureId = states.Texture.cacheId
	}
	if textureId != r.lastTextureId {
		r.applyTexture(states.Texture)
	}

	// Apply the shader
	// TODO
	/*if states.shader {
		applyShader(states.shader);
	}*/

	// #########################################

	if !useVertexCache {
		// Find the OpenGL primitive type
		modes := [...]gl.GLenum{gl.POINTS, gl.LINES, gl.LINE_STRIP, gl.TRIANGLES,
			gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.QUADS}
		mode := modes[primType]

		gl.Begin(mode)

		for i, _ := range verts {
			gl.TexCoord2f(verts[i].TexCoords.X, verts[i].TexCoords.Y)
			gl.Color4f(float32(verts[i].Color.R)/255, float32(verts[i].Color.G)/255,
				float32(verts[i].Color.B)/255, float32(verts[i].Color.A)/255)
			gl.Vertex2f(verts[i].Pos.X, verts[i].Pos.Y)
		}

		gl.End()
	}

	// #########################################

	// Setup the pointers to the vertices' components
	// ... and if we already used it previously, we don't need to set the pointers again
	if useVertexCache {
		if !r.useVertexCache {
			gl.VertexPointer(2, gl.FLOAT, 0, r.vpCache[:])
			gl.ColorPointer(4, gl.UNSIGNED_BYTE, 0, r.vcCache[:])
			gl.TexCoordPointer(2, gl.FLOAT, 0, r.vtCache[:])
		}

		// Find the OpenGL primitive type
		modes := [...]gl.GLenum{gl.POINTS, gl.LINES, gl.LINE_STRIP, gl.TRIANGLES,
			gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.QUADS}
		mode := modes[primType]

		// Draw the primitives
		gl.DrawArrays(mode, 0, len(verts))
	}

	// Unbind the shader, if any
	// TODO
	/*if (states.shader) {
		r.applyShader(nil)
	}*/

//.........这里部分代码省略.........
开发者ID:BrunoAssis,项目名称:gosfml,代码行数:101,代码来源:rendertarget.go



注:本文中的github.com/go-gl/gl.Color4f函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gl.DepthFunc函数代码示例发布时间:2022-05-23
下一篇:
Golang gl.ClearDepth函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap