Weird GLFW Problem

Monkey Forums/Monkey Bug Reports/Weird GLFW Problem

Sui(Posted 2013) [#1]
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



AdamRedwoods(Posted 2013) [#2]
is this a problem or is it a way that padding is defined? it seems 256 would make sense without padding.

i would ping Mark/BRL to see if something changed internally.


Sui(Posted 2013) [#3]
Thanks for the reply.

The issue is really that it used to work before and the behaviour is inconsistent across targets.

I have sent an email through the website.

I can get around it by removing the padding. I guess it's not crucial if I'm storing a single texture rather than an image atlas.


byo(Posted 2013) [#4]
Strange. Your example is working correctly here in the latest beta (75d) with or without the comments.


marksibly(Posted 2013) [#5]
Fixed in 75d!

Note: Be careful creating padded images like this, as you will also need to manually WritePixels the padding pixels. WritePixels allows you to write to the entire image (including padding), but when using the image with DrawImage, only the rect from 1,1->width-2,height-2 will be rendered.

If you do need to manually create a padded image, it's probably best to ignore the padding flags and do it manually, eg:

Local padded_image:=CreateImage( 200,200 ) 'for a 198x198 padded image - don't forget to WritePixels the padding too.
Local image:=padded_image.GrabImage( 1,1,198,198 ) 'grab the padded image



Sui(Posted 2013) [#6]
Thanks Mark.