mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 14:34:26 +01:00
Add AdjustImage
This commit is contained in:
parent
8ff19c031d
commit
e7c7c69dcc
@ -22,7 +22,8 @@ func DrawTexture(native texture.Native, projectionMatrix [16]float32, quads []gt
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
shaderProgram := use(projectionMatrix, geometryMatrix, colorMatrix)
|
shaderProgram := use(projectionMatrix, geometryMatrix, colorMatrix)
|
||||||
// This state affects the other functions, so can't disable here...
|
defer C.glUseProgram(0)
|
||||||
|
|
||||||
C.glBindTexture(C.GL_TEXTURE_2D, C.GLuint(native))
|
C.glBindTexture(C.GL_TEXTURE_2D, C.GLuint(native))
|
||||||
defer C.glBindTexture(C.GL_TEXTURE_2D, 0)
|
defer C.glBindTexture(C.GL_TEXTURE_2D, 0)
|
||||||
|
|
||||||
|
@ -103,7 +103,11 @@ func getUniformLocation(program C.GLuint, name string) C.GLint {
|
|||||||
return getLocation(program, name, qualifierVariableTypeUniform)
|
return getLocation(program, name, qualifierVariableTypeUniform)
|
||||||
}
|
}
|
||||||
|
|
||||||
func use(projectionMatrix [16]float32, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) C.GLuint {
|
func program() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func use(projectionMatrix [16]float32,
|
||||||
|
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) C.GLuint {
|
||||||
program := programRegular
|
program := programRegular
|
||||||
if !colorMatrix.IsIdentity() {
|
if !colorMatrix.IsIdentity() {
|
||||||
program = programColorMatrix
|
program = programColorMatrix
|
||||||
|
@ -23,6 +23,25 @@ type Texture struct {
|
|||||||
height int
|
height int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AdjustImage(img image.Image, width, height int) *image.NRGBA {
|
||||||
|
adjustedImageBounds := image.Rectangle{
|
||||||
|
image.ZP,
|
||||||
|
image.Point{width, height},
|
||||||
|
}
|
||||||
|
if nrgba := img.(*image.NRGBA); nrgba != nil &&
|
||||||
|
img.Bounds() == adjustedImageBounds {
|
||||||
|
return nrgba
|
||||||
|
}
|
||||||
|
|
||||||
|
adjustedImage := image.NewNRGBA(adjustedImageBounds)
|
||||||
|
dstBounds := image.Rectangle{
|
||||||
|
image.ZP,
|
||||||
|
img.Bounds().Size(),
|
||||||
|
}
|
||||||
|
draw.Draw(adjustedImage, dstBounds, img, image.ZP, draw.Src)
|
||||||
|
return adjustedImage
|
||||||
|
}
|
||||||
|
|
||||||
func New(width, height int, create func(textureWidth, textureHeight int) (
|
func New(width, height int, create func(textureWidth, textureHeight int) (
|
||||||
interface{}, error)) (*Texture, error) {
|
interface{}, error)) (*Texture, error) {
|
||||||
texture := &Texture{
|
texture := &Texture{
|
||||||
@ -46,16 +65,7 @@ func NewFromImage(img image.Image, create func(img *image.NRGBA) (
|
|||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
}
|
}
|
||||||
adjustedImageBound := image.Rectangle{
|
adjustedImage := AdjustImage(img, texture.textureWidth(), texture.textureHeight())
|
||||||
image.ZP,
|
|
||||||
image.Point{texture.textureWidth(), texture.textureHeight()},
|
|
||||||
}
|
|
||||||
adjustedImage := image.NewNRGBA(adjustedImageBound)
|
|
||||||
dstBound := image.Rectangle{
|
|
||||||
image.ZP,
|
|
||||||
img.Bounds().Size(),
|
|
||||||
}
|
|
||||||
draw.Draw(adjustedImage, dstBound, img, image.ZP, draw.Src)
|
|
||||||
var err error
|
var err error
|
||||||
texture.native, err = create(adjustedImage)
|
texture.native, err = create(adjustedImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user