Ejemplo n.º 1
0
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)
		})
	})
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
func newTexDrawer(vshader, fshader string) *GlDrawer {
	dr := NewGlDrawer(vshader, fshader)
	program := dr.program
	posAttr := program.GetAttribLocation("position")
	posAttr.AttribPointer(2, gl.FLOAT, false, 4*4, uintptr(0))
	posAttr.EnableArray()

	texAttr := program.GetAttribLocation("texcoord")
	texAttr.AttribPointer(2, gl.FLOAT, false, 4*4, uintptr(8))
	glh.OpenGLSentinel()
	texAttr.EnableArray()

	return dr
}
Ejemplo n.º 4
0
func MakeTextureFromTGA(fname string) gl.Texture {
	tex := gl.GenTexture()

	tex.Bind(gl.TEXTURE_2D)
	glfw.LoadTexture2D(fname, 0)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
	gl.GenerateMipmap(gl.TEXTURE_2D)

	glh.OpenGLSentinel() // check for errors

	return tex
}
Ejemplo n.º 5
0
func main() {
	window, err := initGL()
	if err != nil || window == nil {
		log.Printf("InitGL: %v", err)
		return
	}
	defer glfw.Terminate()

	shaderLoad()

	cube, square = createBuffers()

	defer cube.Release()
	defer square.Release()

	timeframe = 0.0

	stack := trig.NewMatrixStack()
	stack.Push(trig.TranslateXYZ(-0.5, -0.5, 0), trig.RotateY(math.Pi/4))

	modelMatrix = stack.Get()
	viewMatrix = trig.TranslateXYZ(0, 0, -2)
	projMatrix = trig.Frustum(-0.5, 0.5, -0.5, 0.5, 1, 10)

	textureBank = helper.InitTextureBank(4, 1)
	textureBank.InitSamplerWithDefaults(0)
	textureBank.InstantiateSamplers()

	textureBank.InstantiateGeometry(0, 768, 768, 0, 0)
	textureBank.InstantiateGeometry(1, 768, 768, 0, 0)
	textureBank.InstantiateGeometry(2, 256, 256, 256, 0)
	textureBank.InstantiateGeometry(3, 256, 0, 0, 0)

	textureBank.InstantiateFormat(0, gl.FLOAT, gl.RGB, gl.RGB32F)
	textureBank.InstantiateFormat(1, gl.FLOAT, gl.RGB, gl.RGB32F)
	textureBank.InstantiateFormat(2, gl.UNSIGNED_BYTE, gl.RED, gl.R8)
	textureBank.InstantiateFormat(3, gl.UNSIGNED_BYTE, gl.RGBA, gl.RGBA)

	textureBank.ConfigUnit(0, gl.TEXTURE_2D, 0)
	textureBank.ConfigUnit(1, gl.TEXTURE_2D, 0)
	textureBank.ConfigUnit(2, gl.TEXTURE_3D, 0)
	textureBank.ConfigUnit(3, gl.TEXTURE_1D, 0)

	loadTexture()
	textureBank.InstantiateTextures()
	glh.OpenGLSentinel()()

	glh.With(textureBank, func() {

		framebuffer = &helper.Framebuffer{}
		framebuffer.Outputs = []gl.Texture{
			textureBank.Units[0].Texture,
			textureBank.Units[1].Texture,
		}
		framebuffer.Sizes = []*helper.TextureGeometry{
			textureBank.PixelData[0].Geometry[0],
			textureBank.PixelData[1].Geometry[0],
		}
		for !window.ShouldClose() {
			render()
			compose()
			window.SwapBuffers()
			glfw.PollEvents()
		}
	})
	os.Exit(0)
}