コード例 #1
0
ファイル: text.go プロジェクト: CubeLite/gltext-1
func (t *Text) Draw() {
	if t.IsDebug {
		t.BoundingBox.Draw()
	}
	gl.UseProgram(t.font.program)

	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, t.font.textureID)

	// uniforms
	gl.Uniform1i(t.font.fragmentTextureUniform, 0)
	gl.Uniform4fv(t.font.colorUniform, 1, &t.color[0])
	gl.Uniform2fv(t.font.finalPositionUniform, 1, &t.finalPosition[0])
	gl.UniformMatrix4fv(t.font.orthographicMatrixUniform, 1, false, &t.font.OrthographicMatrix[0])
	gl.UniformMatrix4fv(t.font.scaleMatrixUniform, 1, false, &t.scaleMatrix[0])

	// draw
	drawCount := int32(t.RuneCount * 6)
	if drawCount > int32(t.eboIndexCount) {
		drawCount = int32(t.eboIndexCount)
	}
	if drawCount < 0 {
		drawCount = 0
	}
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.BindVertexArray(t.vao)
	gl.DrawElements(gl.TRIANGLES, drawCount, gl.UNSIGNED_INT, nil)
	gl.BindVertexArray(0)
	gl.Disable(gl.BLEND)
}
コード例 #2
0
ファイル: postprocess.go プロジェクト: peterudkmaya11/lux
//PreRender binds either the next post process fbo if there is one or unbinds any fbo to render to screen. Also disable depth test.
func (ppfb *PostProcessFramebuffer) PreRender() {
	if ppfb.next != nil {
		ppfb.Fb.Bind(gl2.FRAMEBUFFER)
	} else {
		gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	}
	gl.Disable(gl.DEPTH_TEST)
}
コード例 #3
0
ファイル: opengl.go プロジェクト: Triangle345/GT
func SetPerspective(width, height int) {
	Projection := mathgl.Perspective(mathgl.DegToRad(45.0), float32(width/height), 0.1, 100.0)
	viewM = mathgl.LookAt(0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
	projectionM = Projection

	gl.Disable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)

}
コード例 #4
0
ファイル: opengl.go プロジェクト: Triangle345/GT
func SetOrthographic(width, height int) {
	// Projection := mathgl.Perspective(45.0, winWidth/winHeight, 0.1, 100.0)
	// Projection := mathgl.Ortho2D(0.0, winWidth, winHeight, 0.0)
	// aspect := float32(s.width / s.height)
	Projection := mathgl.Ortho(0.0, float32(width), float32(height), 0.0, -5.0, 5.0)
	viewM = mathgl.LookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
	projectionM = Projection
	gl.Disable(gl.DEPTH_TEST)
}
コード例 #5
0
ファイル: context.go プロジェクト: kurrik/opengl-benchmarks
func (c *Context) CreateWindow(w, h int, name string) (err error) {
	c.w = w
	c.h = h
	c.name = name
	c.createWindow()
	c.SetCursor(c.cursor)
	gl.Init()
	if e := gl.GetError(); e != 0 {
		if e != gl.INVALID_ENUM {
			err = fmt.Errorf("OpenGL glInit error: %X\n", e)
			return
		}
	}
	c.OpenGLVersion = glfw.GetVersionString()
	c.ShaderVersion = gl.GoStr(gl.GetString(gl.SHADING_LANGUAGE_VERSION))
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Disable(gl.CULL_FACE)
	glfw.SwapInterval(1)
	return
}
コード例 #6
0
ファイル: context.go プロジェクト: pikkpoiss/twodee
func (c *Context) CreateWindow(w, h int, name string) (err error) {
	c.w = w
	c.h = h
	c.name = name
	var monitor *glfw.Monitor
	if c.fullscreen == true {
		monitor = glfw.GetPrimaryMonitor()
	}
	if c.window, err = glfw.CreateWindow(c.w, c.h, c.name, monitor, nil); err != nil {
		return
	}
	if c.cursor == false {
		c.window.SetInputMode(glfw.CursorMode, glfw.CursorHidden)
	}
	c.window.MakeContextCurrent()
	gl.Init()
	if e := gl.GetError(); e != 0 {
		if e == gl.INVALID_ENUM {
			fmt.Printf("GL_INVALID_ENUM when calling glInit\n")
		} else {
			err = fmt.Errorf("OpenGL glInit error: %X\n", e)
			return
		}
	}
	c.OpenGLVersion = glfw.GetVersionString()
	c.ShaderVersion = gl.GoStr(gl.GetString(gl.SHADING_LANGUAGE_VERSION))
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Disable(gl.CULL_FACE)
	glfw.SwapInterval(1)
	if c.VAO, err = CreateVAO(); err != nil {
		return
	}
	gl.BindVertexArray(c.VAO)
	c.Events = NewEventHandler(c.window)
	return
}
コード例 #7
0
ファイル: effects.go プロジェクト: pikkpoiss/ld33
func (r *EffectsRenderer) Unbind() error {
	gl.Viewport(0, 0, int32(r.oldwidth), int32(r.oldheight))
	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	gl.Disable(gl.STENCIL_TEST)
	return nil
}
コード例 #8
0
ファイル: setup.go プロジェクト: hialin/hialin
func InitGL() error {
	defer tlog.FuncLog(tlog.Func("InitGL"))

	err := gl.Init()
	if err != nil {
		return err
	}
	gl.GetError() // cleanup gl error state

	version := gl.GoStr(gl.GetString(gl.VERSION))
	tlog.Println("OpenGL version", version)

	gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
	Check()
	gl.ReadBuffer(gl.BACK)
	Check()
	gl.DrawBuffer(gl.BACK)
	Check()

	gl.FrontFace(gl.CW)
	Check()
	gl.CullFace(gl.BACK)
	Check()
	gl.Disable(gl.CULL_FACE)
	Check()

	gl.ClearColor(1, 1, 0.5, 0)
	Check()
	gl.ClearDepth(1.0)
	Check()
	gl.ClearStencil(0)
	Check()

	gl.Disable(gl.STENCIL_TEST)
	Check()
	gl.StencilMask(0xFFFFFFFF)
	Check()
	gl.StencilFunc(gl.EQUAL, 0x00000000, 0x00000001)
	Check()
	gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP)
	Check()

	gl.Disable(gl.DITHER)
	Check()

	gl.Enable(gl.DEPTH_TEST)
	Check()
	gl.DepthFunc(gl.LEQUAL)
	Check()
	gl.DepthMask(true)
	Check()
	gl.DepthRange(0., 1.)
	Check()
	gl.Enable(gl.DEPTH_CLAMP)
	Check()

	gl.Enable(gl.BLEND)
	Check()
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	ForceCheck()
	return nil
}