I am creating a game using procedurally generated textures. I am creating the textures as an array and placing them into an Image object using WritePixels.
This worked fine with v66b but seems to be broken since I have installed a newer version (73b). I have also tested with 74a and encountered the same problem.
The problem is that the sprite is shearing internally when drawing under the GLFW build. The HTML5 build works fine.
The sprite should be drawn as a square with the left half red and the right half green. In GLFW the colour change becomes diagonal.
I have created a small example to demonstrate below. It seems to be related to the Image.XYPadding flag on the image, as uncommenting the lines that change sizePixels etc. to not use the padding cause the problem to go away.
I can get around this by using my own padding but thought I would ask if anyone else is having a problem or perhaps a solution.
Import mojo
Function Main()
Local o:WritePixels = New WritePixels
End Function
Class WritePixels Extends App
Field m_img:Image = Null
Method OnCreate()
SetUpdateRate 60
End Method
Method OnUpdate()
If KeyHit(KEY_CLOSE) Then Error("") ' quits if window is closed
If m_img = Null Then
' Pixel buffer will be sizePixels*sizePixels
' Image will be larger to accomodate single pixel padding at each side
Local sizePixels:Int = 254
Local sizeImage:Int = 256
Local flags:Int = Image.MidHandle | Image.XYPadding
' Uncomment these to make it work correctly with GLFW_Game configuration
' Seems to be a problem with the Image.XYPadding functionality
' sizePixels = 256
' sizeImage = 256
' flags = Image.MidHandle | Image.XYPadding
Local pixels:Int[sizePixels * sizePixels]
' Create an image that is red on the left, green on the right
For Local y:Int = 0 To sizePixels - 1
For Local x:Int = 0 To sizePixels - 1
Local i = y * sizePixels + x
If x < sizePixels / 2 Then
pixels[i] = (128 Shl 16) + (255 Shl 24) ' red, full alpha
Else
pixels[i] = (128 Shl 8) + (255 Shl 24) ' green, full alpha
EndIf
Next
Next
m_img = CreateImage(sizeImage, sizeImage, 1, flags)
m_img.WritePixels(pixels, 0, 0, sizePixels, sizePixels)
EndIf
End Method
Method OnRender()
If m_img <> Null Then DrawImage(m_img, 320, 200)
End Method
End Class
|