Add AdjustImage

This commit is contained in:
Hajime Hoshi 2013-11-26 01:08:12 +09:00
parent 8ff19c031d
commit e7c7c69dcc
3 changed files with 27 additions and 12 deletions

View File

@ -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)

View File

@ -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

View File

@ -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 {