Add package internal/opengl

This commit is contained in:
Hajime Hoshi 2014-12-31 03:04:52 +09:00
parent 450a8da267
commit efb759d23c
3 changed files with 39 additions and 9 deletions

View File

@ -24,11 +24,3 @@ const (
FilterNearest Filter = gl.NEAREST
FilterLinear = gl.LINEAR
)
func Init() {
gl.Init()
gl.Enable(gl.TEXTURE_2D)
// Textures' pixel formats are alpha premultiplied.
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
}

View File

@ -0,0 +1,36 @@
// Copyright 2014 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 opengl
import (
"github.com/go-gl/gl"
)
type Context struct {
}
func NewContext() *Context {
c := &Context{}
c.init()
return c
}
func (c *Context) init() {
gl.Init()
gl.Enable(gl.TEXTURE_2D)
// Textures' pixel formats are alpha premultiplied.
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
}

4
ui.go
View File

@ -18,6 +18,7 @@ import (
"fmt"
glfw "github.com/go-gl/glfw3"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/opengl"
"image"
"runtime"
)
@ -47,7 +48,7 @@ func init() {
}
currentUI.run()
currentUI.use(func() {
graphics.Init()
currentUI.glContext = opengl.NewContext()
glfw.SwapInterval(1)
})
}
@ -55,6 +56,7 @@ func init() {
type ui struct {
window *glfw.Window
scale int
glContext *opengl.Context
graphicsContext *graphicsContext
input input
funcs chan func()