aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-02-16 21:28:33 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-02-16 21:28:33 +0800
commit702218008ee2b6d708d6b2821cdef80736bb3224 (patch)
treed55ff7ce88187082378e7d8e4c2f3aad14d23b4e /Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2
parent202362d9258335c695eb75f55f4be74a50a1af33 (diff)
downloadgo-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar
go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.gz
go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.bz2
go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.lz
go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.xz
go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.tar.zst
go-tangerine-702218008ee2b6d708d6b2821cdef80736bb3224.zip
Add versioned dependencies from godep
Diffstat (limited to 'Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2')
-rw-r--r--Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2/painting.go115
-rw-r--r--Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2/painting.qml66
2 files changed, 181 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2/painting.go b/Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2/painting.go
new file mode 100644
index 000000000..71f2d89a2
--- /dev/null
+++ b/Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2/painting.go
@@ -0,0 +1,115 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "gopkg.in/qml.v1"
+ "gopkg.in/qml.v1/gl/es2"
+)
+
+func main() {
+ if err := qml.Run(run); err != nil {
+ fmt.Fprintf(os.Stderr, "error: %v\n", err)
+ os.Exit(1)
+ }
+}
+
+func run() error {
+ qml.RegisterTypes("GoExtensions", 1, 0, []qml.TypeSpec{{
+ Init: func(r *GoRect, obj qml.Object) { r.Object = obj },
+ }})
+
+ engine := qml.NewEngine()
+ component, err := engine.LoadFile("painting.qml")
+ if err != nil {
+ return err
+ }
+
+ win := component.CreateWindow(nil)
+ win.Show()
+ win.Wait()
+ return nil
+}
+
+type GoRect struct {
+ qml.Object
+}
+
+var vertexShader = `
+#version 120
+
+attribute vec2 position;
+
+void main()
+{
+ gl_Position = vec4(position.x, position.y, 0.0, 1.0);
+}
+`
+
+var fragmentShader = `
+#version 120
+
+void main()
+{
+ gl_FragColor = vec4(1.0, 1.0, 1.0, 0.8);
+}
+`
+
+func (r *GoRect) Paint(p *qml.Painter) {
+ gl := GL.API(p)
+
+ vertices := []float32{
+ -1, -1,
+ +1, -1,
+ +1, +1,
+ -1, +1,
+ }
+
+ indices := []uint8{
+ 0, 1, 2, // first triangle
+ 2, 3, 0, // second triangle
+ }
+
+ buf := gl.GenBuffers(2)
+ gl.BindBuffer(GL.ARRAY_BUFFER, buf[0])
+ gl.BufferData(GL.ARRAY_BUFFER, 0, vertices, GL.STATIC_DRAW)
+ gl.BindBuffer(GL.ELEMENT_ARRAY_BUFFER, buf[1])
+ gl.BufferData(GL.ELEMENT_ARRAY_BUFFER, 0, indices, GL.STATIC_DRAW)
+
+ vshader := gl.CreateShader(GL.VERTEX_SHADER);
+ gl.ShaderSource(vshader, vertexShader)
+ gl.CompileShader(vshader)
+
+ var status [1]int32
+ gl.GetShaderiv(vshader, GL.COMPILE_STATUS, status[:])
+ if status[0] == 0 {
+ log := gl.GetShaderInfoLog(vshader)
+ panic("vertex shader compilation failed: " + string(log))
+ }
+
+ fshader := gl.CreateShader(GL.FRAGMENT_SHADER)
+ gl.ShaderSource(fshader, fragmentShader)
+ gl.CompileShader(fshader)
+
+ gl.GetShaderiv(fshader, GL.COMPILE_STATUS, status[:])
+ if status[0] == 0 {
+ log := gl.GetShaderInfoLog(fshader)
+ panic("fragment shader compilation failed: " + string(log))
+ }
+
+ program := gl.CreateProgram()
+ gl.AttachShader(program, vshader)
+ gl.AttachShader(program, fshader)
+ gl.LinkProgram(program)
+ gl.UseProgram(program)
+
+ position := gl.GetAttribLocation(program, "position")
+ gl.VertexAttribPointer(position, 2, GL.FLOAT, false, 0, 0)
+ gl.EnableVertexAttribArray(position)
+
+ gl.Enable(GL.BLEND)
+ gl.BlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA)
+
+ gl.DrawElements(GL.TRIANGLES, 6, GL.UNSIGNED_BYTE, nil)
+}
diff --git a/Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2/painting.qml b/Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2/painting.qml
new file mode 100644
index 000000000..8c59fc351
--- /dev/null
+++ b/Godeps/_workspace/src/github.com/obscuren/qml/examples/painting-es2/painting.qml
@@ -0,0 +1,66 @@
+import QtQuick 2.0
+import GoExtensions 1.0
+
+Rectangle {
+ id: root
+
+ width: 640
+ height: 280
+ color: "black"
+
+ Rectangle {
+ x: 20; y: 20; width: 100; height: 100
+ color: "red"
+
+ SequentialAnimation on x {
+ loops: Animation.Infinite
+ NumberAnimation { from: 20; to: 120; duration: 4000; easing.type: Easing.InOutQuad }
+ NumberAnimation { from: 120; to: 20; duration: 4000; easing.type: Easing.InOutQuad }
+ }
+ }
+
+ Rectangle {
+ x: 40; y: 40; width: 100; height: 100
+ color: "yellow"
+ opacity: 0.7
+
+ SequentialAnimation on x {
+ loops: Animation.Infinite
+ NumberAnimation { from: 40; to: 220; duration: 4000; easing.type: Easing.InOutQuad }
+ NumberAnimation { from: 220; to: 40; duration: 4000; easing.type: Easing.InOutQuad }
+ }
+ }
+
+ GoRect {
+ x: 60; y: 60; width: 100; height: 100
+
+ SequentialAnimation on x {
+ loops: Animation.Infinite
+ NumberAnimation { from: 60; to: 320; duration: 4000; easing.type: Easing.InOutQuad }
+ NumberAnimation { from: 320; to: 60; duration: 4000; easing.type: Easing.InOutQuad }
+ }
+ }
+
+ Rectangle {
+ x: 80; y: 80; width: 100; height: 100
+ color: "yellow"
+ opacity: 0.7
+
+ SequentialAnimation on x {
+ loops: Animation.Infinite
+ NumberAnimation { from: 80; to: 420; duration: 4000; easing.type: Easing.InOutQuad }
+ NumberAnimation { from: 420; to: 80; duration: 4000; easing.type: Easing.InOutQuad }
+ }
+ }
+
+ Rectangle {
+ x: 100; y: 100; width: 100; height: 100
+ color: "red"
+
+ SequentialAnimation on x {
+ loops: Animation.Infinite
+ NumberAnimation { from: 100; to: 520; duration: 4000; easing.type: Easing.InOutQuad }
+ NumberAnimation { from: 520; to: 100; duration: 4000; easing.type: Easing.InOutQuad }
+ }
+ }
+}