Exemplo n.º 1
0
func main() {
	fmt.Println("OpenGL Test!!!")
	// Init SDL
	err := sdl.Init(sdl.INIT_VIDEO)
	if err != nil {
		fmt.Println("Init error:", err.Error())
		Quit(1)
	}
	// Init OpenGL
	sdl.GL_SetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 3)
	sdl.GL_SetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 3)
	sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
	sdl.GL_SetAttribute(sdl.GL_DEPTH_SIZE, 24)

	// Create SDL Window
	window, err := sdl.CreateWindow("OpenGL Test Nick", sdl.WINDOWPOS_CENTRED, sdl.WINDOWPOS_CENTRED, 512, 512, sdl.WINDOW_OPENGL|sdl.WINDOW_SHOWN)
	if err != nil {
		fmt.Println("Error while creating window:", err.Error())
		Quit(2)
	}

	context := sdl.GL_CreateContext(window)

	err = sdl.GL_SetSwapInterval(1)
	if err != nil {
		fmt.Println("Error while setting swap interval:", err.Error())
		Quit(3)
	}

	//show red
	gl.ClearColor(1.0, 0.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	sdl.GL_SwapWindow(window)
	sdl.Delay(2000)
	//show green
	gl.ClearColor(0.0, 1.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	sdl.GL_SwapWindow(window)
	sdl.Delay(2000)
	//show blue
	gl.ClearColor(0.0, 0.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	sdl.GL_SwapWindow(window)
	sdl.Delay(2000)

	sdl.GL_DeleteContext(context)
	sdl.DestroyWindow(window)
	Quit(0)
}
Exemplo n.º 2
0
func main() {
	fmt.Println("Init GLFW3")
	if glfw3.Init() {
		fmt.Println("Init ok")
		defer closeGLFW()
	}

	// Create the window
	fmt.Println("Opening window")
	win, err := glfw3.CreateWindow(1024, 768, "Kunos Rulez", nil, nil)
	gl.Init()
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("ok", win)
	}

	win.MakeContextCurrent()

	for win.ShouldClose() == false {
		glfw3.PollEvents()
		gl.ClearColor(1.0, 0.0, 0.0, 1.0)
		gl.Clear(gl.COLOR_BUFFER_BIT)

		win.SwapBuffers()
	}

	fmt.Println("Destroying win")
	win.Destroy()
}
Exemplo n.º 3
0
func display() {
	// Clear the background as white
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Use the GLSL program
	gl.UseProgram(program)

	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangle)
	gl.EnableVertexAttribArray(attributeCoord2d)

	// Describe our vertices array to OpenGL (it can't guess its format automatically)
	gl.VertexAttribPointer(attributeCoord2d, 2, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))

	gl.EnableVertexAttribArray(attributeColor)
	gl.BindBuffer(gl.ARRAY_BUFFER, vboTriangleColors)
	gl.VertexAttribPointer(attributeColor, 3, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))

	// Push each element in buffer_vertices to the vertex shader
	gl.DrawArrays(gl.TRIANGLES, 0, 3)

	gl.DisableVertexAttribArray(attributeCoord2d)
	gl.DisableVertexAttribArray(attributeColor)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0) // Unbind

	// Display the result
	glfw.SwapBuffers()
}
Exemplo n.º 4
0
func drawgl() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	uniYaw = yrot * (math.Pi / 180.0)
	yrot = yrot - 1.0
	uniPitch = zrot * (math.Pi / 180.0)
	zrot = zrot - 0.5
	uniRoll = xrot * (math.Pi / 180.0)
	xrot = xrot - 0.2

	gl.Uniform4f(UniScale, gl.Float(uniRoll), gl.Float(uniYaw), gl.Float(uniPitch), gl.Float(uniscale))
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.DrawArrays(gl.TRIANGLES, gl.Int(0), gl.Sizei(len(triangle_vertices)*4))

	time.Sleep(50 * time.Millisecond)

}
Exemplo n.º 5
0
// TODO this should walk a seperate visibility structure.
func (r *GLRenderer) Render(world *World) {
	r.View.Update()
	m := r.View.Matrix(r.View.Position)
	// Take the inverse of the camera matrix
	r.ViewMatrix = s3dm.Mat4{
		m[0], m[4], m[8], 0,
		m[1], m[5], m[9], 0,
		m[2], m[6], m[10], 0,
		-(m[0]*m[12] + m[1]*m[13] + m[2]*m[14]),
		-(m[4]*m[12] + m[5]*m[13] + m[6]*m[14]),
		-(m[8]*m[12] + m[9]*m[13] + m[10]*m[14]),
		1}
	GL <- func() {
		gl33.Clear(gl33.COLOR_BUFFER_BIT | gl33.DEPTH_BUFFER_BIT)
		vpMatrix := r.PerspectiveMatrix.Mul(r.ViewMatrix)
		pass := PassOpaque
		hud := false
		render := func(leaf Leaf) {
			if pass&leaf.Passes() == 0 {
				return
			}
			var modelMatrix s3dm.Mat4
			if hud {
				modelMatrix = leaf.XformNode().WorldXform.Matrix(s3dm.Position{})
			} else {
				modelMatrix = leaf.XformNode().WorldXform.Matrix(r.View.Position)
			}
			mvpMatrix := vpMatrix.Mul(modelMatrix)
			if !hud {
				if leaf.AABB().IntersectsFrustum(r.View.Frustum) < 0 {
					return
				}
			}
			leaf.Render(r.View, mvpMatrix, pass)
		}
		world.Root.Walk(render)
		pass = PassTranslucent
		world.Root.Walk(render)
		if world.Skybox != nil {
			world.Skybox.Render(r.View, vpMatrix, PassOpaque)
		}
		vpMatrix = r.OrthographicMatrix
		hud = true
		pass = PassOpaque
		world.Gui.Walk(render)
		pass = PassTranslucent
		world.Gui.Walk(render)
		sdl.GL_SwapBuffers()
	}
}
Exemplo n.º 6
0
func Clear(c color.Color) {
	r, g, b, a := glcolor.ConvertColorGL(c)
	gl.ClearColor(r, g, b, a)
	gl.Clear(gl.COLOR_BUFFER_BIT) // gl.DEPTH_BUFFER_BIT
}