mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Rename programColorMatrix -> programFragmentShader
This commit is contained in:
parent
02dbeef1b9
commit
243208b849
@ -42,7 +42,7 @@ pre {
|
||||
<h2>Features</h2>
|
||||
<ul>
|
||||
<li>2D Graphics</li>
|
||||
<li>Input (Mouse, Keyboard)</li>
|
||||
<li>Input (Mouse, Keyboard, Gamepad)</li>
|
||||
</ul>
|
||||
|
||||
<h2>Example</h2>
|
||||
|
@ -19,7 +19,8 @@ import (
|
||||
)
|
||||
|
||||
type Input struct {
|
||||
states [256]int
|
||||
keyStates [256]int
|
||||
gamepadButtonStates [4]int
|
||||
}
|
||||
|
||||
func NewInput() *Input {
|
||||
@ -27,15 +28,28 @@ func NewInput() *Input {
|
||||
}
|
||||
|
||||
func (i *Input) StateForKey(key ebiten.Key) int {
|
||||
return i.states[key]
|
||||
return i.keyStates[key]
|
||||
}
|
||||
|
||||
func (i *Input) StateForGamepadButton(button ebiten.GamepadButton) int {
|
||||
return i.gamepadButtonStates[button]
|
||||
}
|
||||
|
||||
func (i *Input) Update() {
|
||||
for key := range i.states {
|
||||
for key := range i.keyStates {
|
||||
if !ebiten.IsKeyPressed(ebiten.Key(key)) {
|
||||
i.states[key] = 0
|
||||
i.keyStates[key] = 0
|
||||
continue
|
||||
}
|
||||
i.states[key]++
|
||||
i.keyStates[key]++
|
||||
}
|
||||
|
||||
const gamepadID = 0
|
||||
for b := range i.gamepadButtonStates {
|
||||
if !ebiten.IsGamepadButtonPressed(gamepadID, ebiten.GamepadButton(b)) {
|
||||
i.gamepadButtonStates[b] = 0
|
||||
continue
|
||||
}
|
||||
i.gamepadButtonStates[b]++
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4
|
||||
return nil
|
||||
}
|
||||
|
||||
program := useProgramColorMatrix(c, glMatrix(projectionMatrix), geo, color)
|
||||
program := useProgramTexture(c, glMatrix(projectionMatrix), geo, color)
|
||||
|
||||
// We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture
|
||||
// See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
)
|
||||
|
||||
var programColorMatrix opengl.Program
|
||||
var programTexture opengl.Program
|
||||
|
||||
func initialize(c *opengl.Context) error {
|
||||
const size = 10000
|
||||
@ -30,17 +30,17 @@ func initialize(c *opengl.Context) error {
|
||||
}
|
||||
defer c.DeleteShader(shaderVertexNative)
|
||||
|
||||
shaderColorMatrixNative, err := c.NewShader(c.FragmentShader, shader(c, shaderColorMatrix))
|
||||
shaderFragmentTextureNative, err := c.NewShader(c.FragmentShader, shader(c, shaderFragmentTexture))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.DeleteShader(shaderColorMatrixNative)
|
||||
defer c.DeleteShader(shaderFragmentTextureNative)
|
||||
|
||||
shaders := []opengl.Shader{
|
||||
shaderVertexNative,
|
||||
shaderColorMatrixNative,
|
||||
shaderFragmentTextureNative,
|
||||
}
|
||||
programColorMatrix, err = c.NewProgram(shaders)
|
||||
programTexture, err = c.NewProgram(shaders)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -64,12 +64,12 @@ func initialize(c *opengl.Context) error {
|
||||
|
||||
var lastProgram opengl.Program
|
||||
|
||||
func useProgramColorMatrix(c *opengl.Context, projectionMatrix []float32, geo Matrix, color Matrix) opengl.Program {
|
||||
if lastProgram != programColorMatrix {
|
||||
c.UseProgram(programColorMatrix)
|
||||
lastProgram = programColorMatrix
|
||||
func useProgramTexture(c *opengl.Context, projectionMatrix []float32, geo Matrix, color Matrix) opengl.Program {
|
||||
if lastProgram != programTexture {
|
||||
c.UseProgram(programTexture)
|
||||
lastProgram = programTexture
|
||||
}
|
||||
program := programColorMatrix
|
||||
program := programTexture
|
||||
|
||||
c.UniformFloats(program, "projection_matrix", projectionMatrix)
|
||||
|
||||
|
@ -23,7 +23,7 @@ type shaderId int
|
||||
|
||||
const (
|
||||
shaderVertex shaderId = iota
|
||||
shaderColorMatrix
|
||||
shaderFragmentTexture
|
||||
)
|
||||
|
||||
func shader(c *opengl.Context, id shaderId) string {
|
||||
@ -48,7 +48,7 @@ void main(void) {
|
||||
gl_Position = projection_matrix * modelview_matrix * vec4(vertex, 0, 1);
|
||||
}
|
||||
`,
|
||||
shaderColorMatrix: `
|
||||
shaderFragmentTexture: `
|
||||
uniform lowp sampler2D texture;
|
||||
uniform lowp mat4 color_matrix;
|
||||
uniform lowp vec4 color_matrix_translation;
|
||||
|
Loading…
Reference in New Issue
Block a user