Add example/mobile (not-compilable yet)

This commit is contained in:
Hajime Hoshi 2016-05-19 03:17:50 +09:00
parent 8f5ca7dddb
commit 76ea075896
10 changed files with 168 additions and 4 deletions

57
examples/mobile/main.go Normal file
View File

@ -0,0 +1,57 @@
// Copyright 2016 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
_ "image/jpeg"
"log"
"math"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/examples/common"
"github.com/hajimehoshi/ebiten/mobile"
)
const (
screenWidth = 320
screenHeight = 240
)
var (
count int
gophersImage *ebiten.Image
)
func update(screen *ebiten.Image) error {
count++
w, h := gophersImage.Size()
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Rotate(float64(count%360) * 2 * math.Pi / 360)
op.GeoM.Translate(screenWidth/2, screenHeight/2)
if err := screen.DrawImage(gophersImage, op); err != nil {
return err
}
return nil
}
func main() {
var err error
gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
if err != nil {
log.Fatal(err)
}
mobile.Start(update, screenWidth, screenHeight, 2, "Mobile (Ebiten Demo)")
}

View File

@ -22,12 +22,13 @@
package main package main
import ( import (
"github.com/hajimehoshi/ebiten/internal"
"log" "log"
"os" "os"
"sort" "sort"
"strconv" "strconv"
"text/template" "text/template"
"github.com/hajimehoshi/ebiten/internal"
) )
var keyCodeToName map[int]string var keyCodeToName map[int]string
@ -263,7 +264,7 @@ func main() {
buildTag := "" buildTag := ""
switch path { switch path {
case "internal/ui/keys_glfw.go": case "internal/ui/keys_glfw.go":
buildTag = "// +build !js" buildTag = "// +build !js\n// +build !android"
case "internal/ui/keys_js.go": case "internal/ui/keys_js.go":
buildTag = "// +build js" buildTag = "// +build js"
} }

View File

@ -14,6 +14,7 @@
// +build darwin linux windows // +build darwin linux windows
// +build !js // +build !js
// +build !android
package opengl package opengl

View File

@ -300,6 +300,11 @@ func (c *Context) DisableVertexAttribArray(p Program, location string) {
gl.DisableVertexAttribArray(mgl.Attrib(l)) gl.DisableVertexAttribArray(mgl.Attrib(l))
} }
func (c *Context) DeleteProgram(p Program) {
gl := c.gl
gl.DeleteProgram(mgl.Program(p))
}
func uint16ToBytes(v []uint16) []byte { func uint16ToBytes(v []uint16) []byte {
b := make([]byte, len(v)*2) b := make([]byte, len(v)*2)
for i, x := range v { for i, x := range v {
@ -344,6 +349,11 @@ func (c *Context) BufferSubData(bufferType BufferType, data []int16) {
gl.BufferSubData(mgl.Enum(bufferType), 0, int16ToBytes(data)) gl.BufferSubData(mgl.Enum(bufferType), 0, int16ToBytes(data))
} }
func (c *Context) DeleteBuffer(b Buffer) {
gl := c.gl
gl.DeleteBuffer(mgl.Buffer(b))
}
func (c *Context) DrawElements(mode Mode, len int) { func (c *Context) DrawElements(mode Mode, len int) {
gl := c.gl gl := c.gl
gl.DrawElements(mgl.Enum(mode), len, mgl.UNSIGNED_SHORT, 0) gl.DrawElements(mgl.Enum(mode), len, mgl.UNSIGNED_SHORT, 0)

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
// +build !js // +build !js
// +build !android
package ui package ui

View File

@ -0,0 +1,17 @@
// Copyright 2016 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build android
package ui

View File

@ -15,6 +15,7 @@
// DO NOT EDIT: This file is auto-generated by genkeys.go. // DO NOT EDIT: This file is auto-generated by genkeys.go.
// +build !js // +build !js
// +build !android
package ui package ui

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
// +build !js // +build !js
// +build !android
package ui package ui

65
internal/ui/ui_mobile.go Normal file
View File

@ -0,0 +1,65 @@
// Copyright 2016 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build android
package ui
import (
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
)
func initialize() (*opengl.Context, error) {
// TODO: Implement
return nil, nil
}
func Main() error {
return nil
}
type UserInterface struct {
}
func CurrentUI() *UserInterface {
return nil
}
func (u *UserInterface) Start(width, height, scale int, title string) error {
return nil
}
func (u *UserInterface) Terminate() error {
return nil
}
func (u *UserInterface) Update() (interface{}, error) {
return nil, nil
}
func (u *UserInterface) SwapBuffers() error {
return nil
}
func (u *UserInterface) SetScreenSize(width, height int) bool {
return false
}
func (u *UserInterface) SetScreenScale(scale int) bool {
return false
}
func (u *UserInterface) ScreenScale() int {
return 1
}

View File

@ -15,7 +15,10 @@
package mobile package mobile
import ( import (
"runtime"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/internal/ui"
) )
var chError <-chan error var chError <-chan error
@ -38,13 +41,20 @@ func LastErrorString() string {
} }
func SetScreenSize(width, height int) { func SetScreenSize(width, height int) {
// TODO: Implement this ui.CurrentUI().SetScreenSize(width, height)
} }
func SetScreenScale(scale int) { func SetScreenScale(scale int) {
// TODO: Implement this ui.CurrentUI().SetScreenScale(scale)
} }
func Render() { func Render() {
runtime.LockOSThread()
// TODO: Implement this // TODO: Implement this
/*select {
case <-workAvailable:
DoWork()
case <-done:
return
}*/
} }