mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57: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
|
||||
}
|
||||
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))
|
||||
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)
|
||||
}
|
||||
|
||||
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
|
||||
if !colorMatrix.IsIdentity() {
|
||||
program = programColorMatrix
|
||||
|
@ -23,6 +23,25 @@ type Texture struct {
|
||||
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) (
|
||||
interface{}, error)) (*Texture, error) {
|
||||
texture := &Texture{
|
||||
@ -46,16 +65,7 @@ func NewFromImage(img image.Image, create func(img *image.NRGBA) (
|
||||
width: width,
|
||||
height: height,
|
||||
}
|
||||
adjustedImageBound := image.Rectangle{
|
||||
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)
|
||||
adjustedImage := AdjustImage(img, texture.textureWidth(), texture.textureHeight())
|
||||
var err error
|
||||
texture.native, err = create(adjustedImage)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user