mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
Add example/mobile (not-compilable yet)
This commit is contained in:
parent
8f5ca7dddb
commit
76ea075896
57
examples/mobile/main.go
Normal file
57
examples/mobile/main.go
Normal 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)")
|
||||
}
|
@ -22,12 +22,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"text/template"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal"
|
||||
)
|
||||
|
||||
var keyCodeToName map[int]string
|
||||
@ -263,7 +264,7 @@ func main() {
|
||||
buildTag := ""
|
||||
switch path {
|
||||
case "internal/ui/keys_glfw.go":
|
||||
buildTag = "// +build !js"
|
||||
buildTag = "// +build !js\n// +build !android"
|
||||
case "internal/ui/keys_js.go":
|
||||
buildTag = "// +build js"
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
// +build darwin linux windows
|
||||
// +build !js
|
||||
// +build !android
|
||||
|
||||
package opengl
|
||||
|
||||
|
@ -300,6 +300,11 @@ func (c *Context) DisableVertexAttribArray(p Program, location string) {
|
||||
gl.DisableVertexAttribArray(mgl.Attrib(l))
|
||||
}
|
||||
|
||||
func (c *Context) DeleteProgram(p Program) {
|
||||
gl := c.gl
|
||||
gl.DeleteProgram(mgl.Program(p))
|
||||
}
|
||||
|
||||
func uint16ToBytes(v []uint16) []byte {
|
||||
b := make([]byte, len(v)*2)
|
||||
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))
|
||||
}
|
||||
|
||||
func (c *Context) DeleteBuffer(b Buffer) {
|
||||
gl := c.gl
|
||||
gl.DeleteBuffer(mgl.Buffer(b))
|
||||
}
|
||||
|
||||
func (c *Context) DrawElements(mode Mode, len int) {
|
||||
gl := c.gl
|
||||
gl.DrawElements(mgl.Enum(mode), len, mgl.UNSIGNED_SHORT, 0)
|
||||
|
@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
// +build !js
|
||||
// +build !android
|
||||
|
||||
package ui
|
||||
|
||||
|
17
internal/ui/input_mobile.go
Normal file
17
internal/ui/input_mobile.go
Normal 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
|
@ -15,6 +15,7 @@
|
||||
// DO NOT EDIT: This file is auto-generated by genkeys.go.
|
||||
|
||||
// +build !js
|
||||
// +build !android
|
||||
|
||||
package ui
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
// +build !js
|
||||
// +build !android
|
||||
|
||||
package ui
|
||||
|
||||
|
65
internal/ui/ui_mobile.go
Normal file
65
internal/ui/ui_mobile.go
Normal 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
|
||||
}
|
@ -15,7 +15,10 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
var chError <-chan error
|
||||
@ -38,13 +41,20 @@ func LastErrorString() string {
|
||||
}
|
||||
|
||||
func SetScreenSize(width, height int) {
|
||||
// TODO: Implement this
|
||||
ui.CurrentUI().SetScreenSize(width, height)
|
||||
}
|
||||
|
||||
func SetScreenScale(scale int) {
|
||||
// TODO: Implement this
|
||||
ui.CurrentUI().SetScreenScale(scale)
|
||||
}
|
||||
|
||||
func Render() {
|
||||
runtime.LockOSThread()
|
||||
// TODO: Implement this
|
||||
/*select {
|
||||
case <-workAvailable:
|
||||
DoWork()
|
||||
case <-done:
|
||||
return
|
||||
}*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user