コード例 #1
0
ファイル: video.go プロジェクト: BluePadge/Fergulator-Android
func (video *Video) initGL() {
	log.Print("Initing")
	video.fpsmanager = gfx.NewFramerate()
	video.fpsmanager.SetFramerate(60)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)

	log.Print("Creating program")
	video.prog = createProgram(vertShaderSrcDef, fragShaderSrcDef)
	log.Print("Attrib loc 1")
	posAttrib := attribLocation(video.prog, "vPosition")
	log.Print("Attrib loc 2")
	texCoordAttr := attribLocation(video.prog, "vTexCoord")
	log.Print("Uniform loc 1")
	paletteLoc := uniformLocation(video.prog, "palette")
	log.Print("Uniform loc 2")
	video.textureUni = uniformLocation(video.prog, "texture")

	log.Print("Gen Texture")
	video.texture = genTexture()
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, video.texture)

	log.Print("TexParam")
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	gl.UseProgram(video.prog)
	gl.EnableVertexAttribArray(posAttrib)
	gl.EnableVertexAttribArray(texCoordAttr)

	gl.Uniform3iv(paletteLoc, nes.SPaletteRgb)

	log.Print("VertBO")
	vertVBO := genBuffer()
	checkGLError()
	gl.BindBuffer(gl.ARRAY_BUFFER, vertVBO)
	verts := f32.Bytes(binary.LittleEndian, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0)
	gl.BufferData(gl.ARRAY_BUFFER, verts, gl.STATIC_DRAW)

	textCoorBuf := genBuffer()
	checkGLError()
	gl.BindBuffer(gl.ARRAY_BUFFER, textCoorBuf)
	texVerts := f32.Bytes(binary.LittleEndian, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0)
	gl.BufferData(gl.ARRAY_BUFFER, texVerts, gl.STATIC_DRAW)

	gl.VertexAttribPointer(posAttrib, 2, gl.FLOAT, false, 0, 0)
	gl.VertexAttribPointer(texCoordAttr, 2, gl.FLOAT, false, 0, 0)
	log.Print("Started")
}
コード例 #2
0
ファイル: main.go プロジェクト: acsellers/ofs
func main() {
	flag.Parse()

	v = game.NewVault()
	v.PlaceRoom(9, 0, 1)
	v.PlaceRoom(9, 1, 1)
	v.PlaceRoom(10, 1, 2)

	// setup transparency for sprites
	gl.Disable(gl.DEPTH_TEST)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	app.Main(func(a app.App) {
		var sz size.Event
		for e := range a.Events() {
			switch e := app.Filter(e).(type) {
			case size.Event:
				sz = e
			case paint.Event:
				onPaint(sz)
				a.EndPaint(e)
			}
		}
	})
}
コード例 #3
0
ファイル: skybox.go プロジェクト: shazow/linerage3d
func (scene *Floor) Draw(camera Camera) {
	shader, _ := scene.UseShader(nil)

	gl.Enable(gl.STENCIL_TEST)
	gl.StencilFunc(gl.ALWAYS, 1, 0xFF)
	gl.StencilOp(gl.KEEP, gl.KEEP, gl.REPLACE)
	gl.StencilMask(0xFF)
	gl.DepthMask(false)
	gl.Clear(gl.STENCIL_BUFFER_BIT)

	// Draw floor
	gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.1, 0.1, 0.1})
	scene.Shape.Draw(shader, camera)

	// Draw reflections
	gl.StencilFunc(gl.EQUAL, 1, 0xFF)
	gl.StencilMask(0x00)
	gl.DepthMask(true)

	view := camera.View()
	gl.Uniform3fv(shader.Uniform("material.ambient"), []float32{0.3, 0.3, 0.3})
	for _, node := range scene.reflected {
		model := node.Transform(scene.transform)
		gl.UniformMatrix4fv(shader.Uniform("model"), model[:])

		normal := model.Mul4(view).Inv().Transpose()
		gl.UniformMatrix4fv(shader.Uniform("normalMatrix"), normal[:])

		node.Draw(camera)
	}

	gl.Disable(gl.STENCIL_TEST)
}
コード例 #4
0
ファイル: main.go プロジェクト: golang-samples/gomobile
func main() {
	app.Main(func(a app.App) {
		var c event.Config
		var eng *WritableEngine
		var root *sprite.Node
		startClock := time.Now()
		for e := range a.Events() {
			switch e := event.Filter(e).(type) {
			case event.Config:
				c = e
			case event.Draw:
				if eng == nil || root == nil {
					eng = NewWritableEngine(
						glsprite.Engine(),
						image.Rect(0, 0, int(c.Width.Px(c.PixelsPerPt)), int(c.Height.Px(c.PixelsPerPt))),
						color.White,
					)
					root = loadScene(eng, loadTextures(eng))
					go listen(eng, ":8080")
				}
				now := clock.Time(time.Since(startClock) * 60 / time.Second)
				gl.ClearColor(1, 1, 1, 1)
				gl.Clear(gl.COLOR_BUFFER_BIT)
				gl.Enable(gl.BLEND)
				gl.BlendEquation(gl.FUNC_ADD)
				gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
				if eng != nil && root != nil {
					eng.Render(root, now, c)
				}
				a.EndDraw()
			}
		}
	})
}
コード例 #5
0
ファイル: main.go プロジェクト: lomoalbert/gomobileapp
func (e *Engine) Draw(c size.Event) {

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0.2, 0.2, 0.2, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	m := mgl32.Perspective(0.785, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projection, m[:])

	eye := mgl32.Vec3{0, 0, 8}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.view, m[:])

	m = mgl32.HomogRotate3D(float32(e.touchLoc.X/c.WidthPt-0.5)*3.14*2, mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.modelx, m[:])

	m = mgl32.HomogRotate3D(float32(e.touchLoc.Y/c.HeightPt-0.5)*3.14, mgl32.Vec3{1, 0, 0})
	gl.UniformMatrix4fv(e.shader.modely, m[:])

	coordsPerVertex := 3
	for _, obj := range e.shape.Objs {
		gl.BindBuffer(gl.ARRAY_BUFFER, obj.coord)
		gl.EnableVertexAttribArray(e.shader.vertCoord)

		gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 12, 0)

		if obj.useuv == true {
			gl.Uniform1i(e.shader.useuv, 1)
			texCoordsPerVertex := 2
			gl.BindBuffer(gl.ARRAY_BUFFER, obj.uvcoord)
			gl.EnableVertexAttribArray(e.shader.vertTexCoord)
			gl.VertexAttribPointer(e.shader.vertTexCoord, texCoordsPerVertex, gl.FLOAT, false, 8, 0)

			gl.BindTexture(gl.TEXTURE_2D, obj.tex)
		} else {
			gl.Uniform1i(e.shader.useuv, 0)
			gl.Uniform4f(e.shader.color, obj.color[0], obj.color[1], obj.color[2], obj.color[3])
		}
		gl.DrawArrays(gl.TRIANGLES, 0, obj.vcount)
		if obj.useuv {
			gl.DisableVertexAttribArray(e.shader.vertTexCoord)
		}
		gl.DisableVertexAttribArray(e.shader.vertCoord)
	}

	debug.DrawFPS(c)
}
コード例 #6
0
ファイル: main.go プロジェクト: lovexiaov/gomobileapp
func (e *Engine) Draw(c size.Event) {

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0.5, 0.8, 0.8, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	gl.Uniform3fv(e.shader.lightdir, []float32{0.5, 0.6, 0.7})

	m := mgl32.Perspective(1.3, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projectionmatrix, m[:])

	eye := mgl32.Vec3{0, 0, 0.2}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.viewmatrix, m[:])

	m = mgl32.HomogRotate3D((e.touchx/float32(c.WidthPt)-0.5)*6.28, mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.modelmatrix, m[:])

	m = mgl32.HomogRotate3D((e.touchx/float32(c.WidthPt)-0.5)*6.28, mgl32.Vec3{0, -1, 0})
	gl.UniformMatrix4fv(e.shader.lightmatrix, m[:])

	coordsPerVertex := 3
	for _, obj := range e.shape.Objs {
		gl.BindBuffer(gl.ARRAY_BUFFER, obj.coord)
		gl.EnableVertexAttribArray(e.shader.vertCoord)
		gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 12, 0)

		texCoordsPerVertex := 2
		gl.BindBuffer(gl.ARRAY_BUFFER, obj.uvcoord)
		gl.EnableVertexAttribArray(e.shader.texcoord)
		gl.VertexAttribPointer(e.shader.texcoord, texCoordsPerVertex, gl.FLOAT, false, 8, 0)

		gl.BindBuffer(gl.ARRAY_BUFFER, obj.normal)
		gl.EnableVertexAttribArray(e.shader.normal)
		gl.VertexAttribPointer(e.shader.normal, 3, gl.FLOAT, false, 12, 0)

		gl.BindTexture(gl.TEXTURE_2D, obj.tex)

		gl.DrawArrays(gl.TRIANGLES, 0, obj.vcount)

		gl.DisableVertexAttribArray(e.shader.texcoord)
		gl.DisableVertexAttribArray(e.shader.normal)
		gl.DisableVertexAttribArray(e.shader.vertCoord)
	}

	debug.DrawFPS(c)
}
コード例 #7
0
ファイル: main.go プロジェクト: shazow/linerage3d
func (e *Engine) Draw(c config.Event) {
	now := time.Now()
	interval := now.Sub(e.lastTick)
	e.lastTick = now

	// Handle key presses
	var camDelta mgl.Vec3
	if e.bindings.Pressed(KeyCamForward) {
		camDelta[2] -= moveSpeed
	}
	if e.bindings.Pressed(KeyCamReverse) {
		camDelta[2] += moveSpeed
	}
	if e.bindings.Pressed(KeyCamLeft) {
		camDelta[0] -= moveSpeed
	}
	if e.bindings.Pressed(KeyCamRight) {
		camDelta[0] += moveSpeed
	}
	if e.bindings.Pressed(KeyCamUp) {
		e.camera.MoveTo(e.camera.Position().Add(mgl.Vec3{0, moveSpeed, 0}))
	}
	if e.bindings.Pressed(KeyCamDown) {
		e.camera.MoveTo(e.camera.Position().Add(mgl.Vec3{0, -moveSpeed, 0}))
	}
	if camDelta[0]+camDelta[1]+camDelta[2] != 0 {
		e.following = false
		e.camera.Move(camDelta)
	} else if e.following {
		pos := e.world.Focus().Position()
		e.camera.Lerp(pos.Add(e.followOffset), pos, 0.1)
	}

	gl.ClearColor(0, 0, 0, 1)
	//gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.Enable(gl.DEPTH_TEST)

	//gl.Disable(gl.CULL_FACE)
	//gl.DepthFunc(gl.LESS)
	//gl.SampleCoverage(4.0, false)

	if !e.paused {
		err := e.world.Tick(interval)
		if err != nil {
			e.paused = true
			e.gameover = true
		}
	}
	e.scene.Draw(e.camera)

	gl.Disable(gl.DEPTH_TEST)
	debug.DrawFPS(c)
}
コード例 #8
0
ファイル: key.go プロジェクト: gordonklaus/justkeys
func initKeys() {
	var err error
	program, err = glutil.CreateProgram(
		`#version 100
		uniform mat4 projection;
		attribute vec3 position;
		attribute float pointsize;
		void main() {
			gl_Position = projection * vec4(position, 1);
			gl_PointSize = pointsize;
		}`,
		`#version 100
		precision mediump float;
		uniform vec4 color;
		void main(void)
		{
		    vec2 v = 2.0*gl_PointCoord.xy - vec2(1.0);
			float r2 = dot(v, v);
			gl_FragColor = mix(color, vec4(0), r2);
		}`,
	)
	if err != nil {
		log.Printf("error creating GL program: %v", err)
		return
	}

	gl.Enable(34370) // GL_PROGRAM_POINT_SIZE; apparently not necessary on Android
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR)

	projection = gl.GetUniformLocation(program, "projection")
	updateProjectionMatrix()

	position = gl.GetAttribLocation(program, "position")
	pointsize = gl.GetAttribLocation(program, "pointsize")
	color = gl.GetUniformLocation(program, "color")
	positionbuf = gl.CreateBuffer()
	pointsizebuf = gl.CreateBuffer()
	updateKeys(ratio{1, 1})
}
コード例 #9
0
ファイル: main.go プロジェクト: geraldstanje/slides
func onStart() {
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	rc, err := asset.Open("hello.wav")
	if err != nil {
		log.Fatal(err)
	}
	player, err = audio.NewPlayer(rc, 0, 0)
	if err != nil {
		log.Fatal(err)
	}
}
コード例 #10
0
ファイル: main.go プロジェクト: lovexiaov/gomobileapp
func (e *Engine) Draw(c size.Event) {
	since := time.Now().Sub(e.started)
	//gl.Enable()

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	m := mgl32.Perspective(0.785, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projection, m[:])

	eye := mgl32.Vec3{3, 3, 3}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.view, m[:])

	m = mgl32.HomogRotate3D(float32(since.Seconds()), mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.model, m[:])

	gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.buf)

	coordsPerVertex := 3
	texCoordsPerVertex := 2
	vertexCount := len(cubeData) / (coordsPerVertex + texCoordsPerVertex)

	gl.EnableVertexAttribArray(e.shader.vertCoord)
	gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 20, 0) // 4 bytes in float, 5 values per vertex

	gl.EnableVertexAttribArray(e.shader.vertTexCoord)
	gl.VertexAttribPointer(e.shader.vertTexCoord, texCoordsPerVertex, gl.FLOAT, false, 20, 12)

	gl.BindTexture(gl.TEXTURE_2D, e.shape.texture)

	gl.DrawArrays(gl.TRIANGLES, 0, vertexCount)

	gl.DisableVertexAttribArray(e.shader.vertCoord)

	debug.DrawFPS(c)
}
コード例 #11
0
ファイル: main.go プロジェクト: shazow/gomobile-examples
func (e *Engine) Draw(c event.Config) {
	since := time.Now().Sub(e.started)

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	// Setup MVP
	var m mgl.Mat4
	m = mgl.Perspective(0.785, float32(c.Width/c.Height), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projection, m[:])

	m = mgl.LookAtV(
		mgl.Vec3{3, 3, 3}, // eye
		mgl.Vec3{0, 0, 0}, // center
		mgl.Vec3{0, 1, 0}, // up
	)
	gl.UniformMatrix4fv(e.shader.view, m[:])

	m = mgl.HomogRotate3D(float32(since.Seconds()), mgl.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.model, m[:])

	// Draw our shape
	gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.buf)

	gl.EnableVertexAttribArray(e.shader.vertCoord)
	gl.VertexAttribPointer(e.shader.vertCoord, e.shape.coordsPerVertex, gl.FLOAT, false, 20, 0) // 4 bytes in float, 5 values per vertex

	gl.EnableVertexAttribArray(e.shader.vertTexCoord)
	gl.VertexAttribPointer(e.shader.vertTexCoord, e.shape.texCoordsPerVertex, gl.FLOAT, false, 20, 12)

	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, e.shape.texture)

	gl.DrawArrays(gl.TRIANGLES, 0, e.shape.vertexCount)

	gl.DisableVertexAttribArray(e.shader.vertCoord)

	//debug.DrawFPS(c)
}
コード例 #12
0
ファイル: main.go プロジェクト: gitter-badger/bukkake
func onStart() {
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)

	texture := loadImages("495.png")

	textureId = gl.CreateTexture()
	gl.BindTexture(gl.TEXTURE_2D, textureId)

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

	gl.TexImage2D(gl.TEXTURE_2D, 0, texture.Rect.Size().X, texture.Rect.Size().Y, gl.RGBA, gl.UNSIGNED_BYTE, texture.Pix)

	// loading Shaders & linking programs
	program = createProgram("vShader.vs", "fShader.vs")
	texProgram = createProgram("vTexShader.vs", "fTexShader.vs")

	quadBuffer = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, quadBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, quadData, gl.STATIC_DRAW)

	quadTexBuffer = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, quadTexBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, quadTexData, gl.STATIC_DRAW)

	swasBuffer = gl.CreateBuffer()
	gl.BindBuffer(gl.ARRAY_BUFFER, swasBuffer)
	gl.BufferData(gl.ARRAY_BUFFER, swastikaData, gl.STATIC_DRAW)

	position = gl.GetAttribLocation(program, "position")
	color = gl.GetUniformLocation(program, "color")
	matrixId = gl.GetUniformLocation(program, "rotationMatrix")
	resolutionId = gl.GetUniformLocation(program, "resIndex")

	position2 = gl.GetAttribLocation(texProgram, "position")
	textureCoords = gl.GetAttribLocation(texProgram, "texCoords")
	matrixId2 = gl.GetUniformLocation(texProgram, "rotationMatrix")
	resolutionId2 = gl.GetUniformLocation(texProgram, "resIndex")
	color2 = gl.GetUniformLocation(texProgram, "color")
}
コード例 #13
0
ファイル: main.go プロジェクト: lovexiaov/gomobileapp
func (e *Engine) Draw(c size.Event) {

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	m := mgl32.Perspective(0.785, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projection, m[:])

	eye := mgl32.Vec3{0, 3, 3}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.view, m[:])

	m = mgl32.HomogRotate3D(float32(e.touchLocX*5/c.WidthPt), mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.modelx, m[:])

	m = mgl32.HomogRotate3D(float32(e.touchLocY*5/c.HeightPt), mgl32.Vec3{1, 0, 0})
	gl.UniformMatrix4fv(e.shader.modely, m[:])

	gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.buf)
	gl.EnableVertexAttribArray(e.shader.vertCoord)
	gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 0, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, e.shape.colorbuf)
	gl.EnableVertexAttribArray(e.shader.color)
	gl.VertexAttribPointer(e.shader.color, colorsPerVertex, gl.FLOAT, false, 0, 0) //更新color值

	gl.DrawArrays(gl.TRIANGLES, 0, vertexCount)

	gl.DisableVertexAttribArray(e.shader.vertCoord)
	gl.DisableVertexAttribArray(e.shader.color)

	debug.DrawFPS(c)
}
コード例 #14
0
ファイル: main.go プロジェクト: lovexiaov/gomobileapp
func (e *Engine) Draw(c size.Event) {

	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	gl.ClearColor(0.2, 0.2, 0.2, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(e.shader.program)

	m := mgl32.Perspective(0.785, float32(c.WidthPt/c.HeightPt), 0.1, 10.0)
	gl.UniformMatrix4fv(e.shader.projection, m[:])

	eye := mgl32.Vec3{0, 0, 5}
	center := mgl32.Vec3{0, 0, 0}
	up := mgl32.Vec3{0, 1, 0}

	m = mgl32.LookAtV(eye, center, up)
	gl.UniformMatrix4fv(e.shader.view, m[:])

	m = mgl32.HomogRotate3D(float32(e.touchLoc.X*10/c.WidthPt), mgl32.Vec3{0, 1, 0})
	gl.UniformMatrix4fv(e.shader.modelx, m[:])

	m = mgl32.HomogRotate3D(float32(e.touchLoc.Y*10/c.HeightPt), mgl32.Vec3{1, 0, 0})
	gl.UniformMatrix4fv(e.shader.modely, m[:])

	coordsPerVertex := 3
	for _, buf := range e.shape.bufs {
		gl.BindBuffer(gl.ARRAY_BUFFER, buf.coord)
		gl.EnableVertexAttribArray(e.shader.vertCoord)
		gl.VertexAttribPointer(e.shader.vertCoord, coordsPerVertex, gl.FLOAT, false, 0, 0)
		gl.Uniform4f(e.shader.color, buf.color[0], buf.color[1], buf.color[2], buf.color[3])
		gl.DrawArrays(gl.TRIANGLES, 0, buf.vcount)

		gl.DisableVertexAttribArray(e.shader.vertCoord)
	}

	debug.DrawFPS(c)
}
コード例 #15
0
ファイル: main.go プロジェクト: eugenechertikhin/gofun
func loadScene(c event.Config) {
	gl.Enable(gl.BLEND)
	gl.BlendEquation(gl.FUNC_ADD)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	w, h := float32(c.Width), float32(c.Height)

	texs = loadTextures()
	scene = &sprite.Node{}
	eng.Register(scene)
	a := f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	}

	if h > w {
		w, h = h, w
		angle := float32(-math.Pi / 2)
		a = f32.Affine{
			{f32.Cos(angle), -f32.Sin(angle), 0},
			{f32.Sin(angle), f32.Cos(angle), w},
		}
	}
	scale = w / 1100
	eng.SetTransform(scene, a)
	x0 = w/2 - 500*scale
	y0 = h/2 - 100*scale
	//log.Printf("width:%f height:%f scale:%f x0:%f y0:%f", w, h, scale, x0, y0)

	timeNode := newTimeNode()
	scene.AppendChild(timeNode)

	startNode := newStartNode()
	scene.AppendChild(startNode)

	endNode := newEndNode()
	scene.AppendChild(endNode)

	startVisilbe, endVisible := false, false
	scene.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		switch state {
		case stateStart:
			if !startVisilbe {
				startVisilbe = true
				eng.SetSubTex(startNode, texs["GO"])
			}

			if endVisible {
				eng.SetSubTex(endNode, sprite.SubTex{})
				endVisible = false
			}
		case stateRunning:
			if startVisilbe {
				eng.SetSubTex(startNode, sprite.SubTex{})
				startVisilbe = false
			}
		case stateEnd:
			if !endVisible {
				endVisible = true
				eng.SetSubTex(endNode, texs["gooon"])
			}
		}
	})
}