Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problem with display.setDefault( "textureWrapX", "repeat" )
Started by admin@appscraft.ru Nov 11 2013 05:41 AM

13 replies to this topic
fill display.setdefault
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

admin@appscraft.ru

[GLOBAL: userInfoPane.html]
admin@appscraft.ru
  • Observer

  • 5 posts
  • Corona SDK

Hi all !

I'm trying to fill square polygon with image. It works fine until i want to repeat texture. So if i write:
 

 

local vertices = { 0,0,500,0,500,500,0,500, }
local x,y = display.contentCenterX, display.contentCenterY

local o = display.newPolygon( x, y, vertices )
o:setFillColor( 255, 0, 0 )
o.fill = { type="image", filename="bg.jpg" }
o.strokeWidth = 5
o:setStrokeColor( 0, 255, 255 )
 

 



it works fine. but in this case:
 

 

display.setDefault( "textureWrapX", "repeat" )
display.setDefault( "textureWrapY", "repeat" )

local vertices = { 0,0,500,0,500,500,0,500, }
local x,y = display.contentCenterX, display.contentCenterY

local o = display.newPolygon( x, y, vertices )
o:setFillColor( 255, 0, 0 )
o.fill = { type="image", filename="bg.jpg" }
o.fill.scaleX=320/o.width
o.fill.scaleY=480/o.height
o.strokeWidth = 5
o:setStrokeColor( 0, 255, 255 )
 

 



it works in Simaulator but no texture on device. I see empty square only. And no errors in XCode terminal. Tested on ipad3 and iphone 5. Anybody who had same problem?

Attached Files

  • Attached File  fill.zip   48.07KB   6 downloads


[TOPIC: post.html]
#2

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @admin@appscraft.ru,

I'm seeing similar issue in my tests. I'll bring this to the attention of the engineers.

 

Thanks for your report,

Brent



[TOPIC: post.html]
#3

walter

[GLOBAL: userInfoPane.html]
walter
  • Moderator

  • 726 posts
  • Alumni

Repeat modes require to use textures that have power-of-two dimensions. The default mode (clampToEdge) is the only mode that supports non-power-of-two textures:

 

See "Important note on texture wrap":

 

http://docs.coronalabs.com/tachyon/api/library/display/setDefault.html



[TOPIC: post.html]
#4

Fat Red Couch

[GLOBAL: userInfoPane.html]
Fat Red Couch
  • Enthusiast

  • 34 posts
  • Corona SDK

I'm using power of 2 textures for fills, however, I'm noticing that when I do:

display.setDefault("textureWrapX", "repeat");
display.setDefault("textureWrapY", "repeat");

In the Corona Simulator everything works as expected. However, when I build for device or Xcode Simulator, *everything* is showing up as black (not just objects that are being filled, but all image rects, etc.) are coming up black. Touch points still work because I'm hearing audio and things happen when I click the screen but all images are turning out black.

I believe it is a Corona bug that is affecting device only, because as mentioned, everything works as expected on the Corona Simulator.

This is still occurring with build 2096.

[TOPIC: post.html]
#5

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @Fat Red Couch,

Is this happening on actual physical devices, or only the Xcode Simulator?

 

Brent



[TOPIC: post.html]
#6

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

I just tested our "PatternFill" demo (located in SampleCode > Graphics-Premium) and it works as expected on my iPhone5. Test was done using Build 2097.

[TOPIC: post.html]
#7

Fat Red Couch

[GLOBAL: userInfoPane.html]
Fat Red Couch
  • Enthusiast

  • 34 posts
  • Corona SDK

Hi @Fat Red Couch,

Is this happening on actual physical devices, or only the Xcode Simulator?

 

Brent

This happens ONLY on device and never in Simulator.



[TOPIC: post.html]
#8

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

If the "PatternFill" demo runs on your device, then there's an issue in your code. When I created that demo, I made a simple (stupid) mistake in my line progression… perhaps you've done the same thing. Once I saw my mistake, I kicked myself at how obvious it should have been. :)

 

CoronaSDK > SampleCode > Graphics-Premium > PatternFill

 

Brent



[TOPIC: post.html]
#9

Fat Red Couch

[GLOBAL: userInfoPane.html]
Fat Red Couch
  • Enthusiast

  • 34 posts
  • Corona SDK

Hi Brent,

 

The sample helps, thanks. However, there is still an issue. I see the sample sets textureWrapX/Y just before filling, and then resets it back to the default "clampToEdge" afterwards, and that works great in main.lua. However, in order for things to work properly, it seems you have to do that on the very first frame of the app.

 

What if you wanted to apply a repeating texture in a scene other than the very first scene of the app?

 

To demonstrate the issue, open the PatternFill demo and wrap the block of code from the start of the textureWrapX/Y all the way to the reset of texture wrap modes in a 1000ms timer delay and you'll see what I'm talking about.

 

Thanks for your help with this.



[TOPIC: post.html]
#10

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @Fat Red Couch,

In my tests, this can be set (must be set) any time that you want to make a repeating pattern fill. Then, just reset back to "clampToEdge" when you're done filling the object(s). I haven't noticed any specific need to do this on the first frame of the app… as long as you set it directly before you do the fill, then revert it afterward, everything should work out fine. If it's not in your case, I'd have to see a code sample or projects exhibiting so.

 

Best regards,

Brent



[TOPIC: post.html]
#11

Fat Red Couch

[GLOBAL: userInfoPane.html]
Fat Red Couch
  • Enthusiast

  • 34 posts
  • Corona SDK

I attached a modified version of the PatterFill main.lua which demonstrates the problem clearly.

 

All I did was wrap the code, starting from the first display.setDefault() call down to the bottom in a 1sec. timer delay. I made no other modifications to the code.

 

If you set the delay to 0, the app launches as it should. If you change it back to 1000, you'll see that when the texture *does* show up, it shows up much different (the "repeat" is no longer being honored, even though it is using the same exact code — the only change was the timer interval).

 

Edit: I attached the main.lua file in the post editor but it doesn't seem to be showing up. Here's the modified main.lua file for PatternFill (only two additional lines were added for the timer).

 

--
-- Abstract: repeating fills sample app, demonstrating how to use repeating fills with transitions and filter effects
--
-- Date: October 2013
--
-- Version: 1.0
--
-- File name: main.lua
--
-- Author: Corona Labs
--
-- Demonstrates: graphics, fills, textures, filters, transitions
--
-- File dependencies: none
--
-- Target devices: Simulator and devices
--
-- Limitations:
--
-- Comments: 
--
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
-- Copyright © 2010 Corona Labs Inc. All Rights Reserved.
---------------------------------------------------------------------------------------

display.setStatusBar( display.HiddenStatusBar )


-- Create container for visual objects
local myContainer = display.newContainer( 570, 570 )
myContainer.x = display.contentCenterX 
myContainer.y = display.contentCenterY


-- Place Corona logo
local x,y = display.contentCenterX, display.contentCenterY
local logo = display.newImage( "corona-logo-large.png" )
myContainer:insert( logo )
logo.fill.effect = "filter.wobble"
logo.fill.effect.amplitude = 10


local water1 = display.newRect( 0,0,800,800 )
myContainer:insert( water1 )
local water2 = display.newRect( 0,0,800,800 )
myContainer:insert( water2 )


-- Calculate scale factor for repeating textures
local scaleFactorX = 1 ; local scaleFactorY = 1
if ( water1.width > water1.height ) then
	scaleFactorY = water1.width / water1.height
else
	scaleFactorX = water1.height / water1.width
end

-- Set defaults for repeated textures which follow
timer.performWithDelay(1000, function()
	display.setDefault( "textureWrapX", "repeat" )
	display.setDefault( "textureWrapY", "mirroredRepeat" )

	-- Apply repeating textures and filters to objects
	water2.fill = { type="image", filename="water-fill.png" }
	water2.fill.scaleX = 0.25 * scaleFactorX
	water2.fill.scaleY = 0.25 * scaleFactorY
	water2.fill.rotation = 40
	water2.fill.effect = "filter.wobble"
	water2.fill.effect.amplitude = 6
	water2.alpha = 0.4

	water1.fill = { type="image", filename="water-fill.png" }
	water1.fill.scaleX = 0.25 * scaleFactorX
	water1.fill.scaleY = 0.25 * scaleFactorY
	water1.fill.effect = "filter.wobble"
	water1.fill.effect.amplitude = 6
	water1.alpha = 0.9

	-- Reset texture wrap modes
	display.setDefault( "textureWrapX", "clampToEdge" )
	display.setDefault( "textureWrapY", "clampToEdge" )

	-- Begin repeating transition function
	local function repeatTrans()
		transition.to( water1.fill, { time=4000, x=water1.fill.x+0.5, onComplete=repeatTrans })
		transition.to( water2.fill, { time=4000, x=water1.fill.x+0.5 })
		if ( logo.alpha == 1 ) then
			transition.to( logo, { time=3000, alpha=0.8, transition=easing.inOutQuad } )
			transition.to( water1, { time=3000, alpha=1, transition=easing.inOutQuad } )
			transition.to( water2, { time=3600, alpha=0.6, transition=easing.inOutQuad } )
		else
			transition.to( logo, { time=3000, alpha=1, transition=easing.inOutQuad } )
			transition.to( water1, { time=3000, alpha=0.9, transition=easing.inOutQuad } )
			transition.to( water2, { time=3600, alpha=0.4, transition=easing.inOutQuad } )
		end
	end
	repeatTrans()
end, 1);



[TOPIC: post.html]
#12

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @Fat Red Couch,

Thanks for the code sample, but I'm just not seeing an issue. I copied your exact code above (timer included) and ran the project both in the Simulator and compiled on my iPhone5. The pattern shows up properly each time, and it honors the repeat. This was done using build #2100.

 

Best regards,

Brent



[TOPIC: post.html]
#13

landoncope

[GLOBAL: userInfoPane.html]
landoncope
  • Contributor

  • 112 posts
  • Corona SDK

@Fat Red Couch,

 

Are you still having this problem? I am having the exact same behavior using the latest build (2181). 

 

I am using power of 2 textures



[TOPIC: post.html]
#14

quinohp

[GLOBAL: userInfoPane.html]
quinohp
  • Enthusiast

  • 37 posts
  • Corona SDK

 

I attached a modified version of the PatterFill main.lua which demonstrates the problem clearly.

 

All I did was wrap the code, starting from the first display.setDefault() call down to the bottom in a 1sec. timer delay. I made no other modifications to the code.

 

If you set the delay to 0, the app launches as it should. If you change it back to 1000, you'll see that when the texture *does* show up, it shows up much different (the "repeat" is no longer being honored, even though it is using the same exact code — the only change was the timer interval).

 

Edit: I attached the main.lua file in the post editor but it doesn't seem to be showing up. Here's the modified main.lua file for PatternFill (only two additional lines were added for the timer).

--
-- Abstract: repeating fills sample app, demonstrating how to use repeating fills with transitions and filter effects
--
-- Date: October 2013
--
-- Version: 1.0
--
-- File name: main.lua
--
-- Author: Corona Labs
--
-- Demonstrates: graphics, fills, textures, filters, transitions
--
-- File dependencies: none
--
-- Target devices: Simulator and devices
--
-- Limitations:
--
-- Comments: 
--
-- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license
-- Copyright (C) 2010 Corona Labs Inc. All Rights Reserved.
---------------------------------------------------------------------------------------

display.setStatusBar( display.HiddenStatusBar )


-- Create container for visual objects
local myContainer = display.newContainer( 570, 570 )
myContainer.x = display.contentCenterX 
myContainer.y = display.contentCenterY


-- Place Corona logo
local x,y = display.contentCenterX, display.contentCenterY
local logo = display.newImage( "corona-logo-large.png" )
myContainer:insert( logo )
logo.fill.effect = "filter.wobble"
logo.fill.effect.amplitude = 10


local water1 = display.newRect( 0,0,800,800 )
myContainer:insert( water1 )
local water2 = display.newRect( 0,0,800,800 )
myContainer:insert( water2 )


-- Calculate scale factor for repeating textures
local scaleFactorX = 1 ; local scaleFactorY = 1
if ( water1.width > water1.height ) then
	scaleFactorY = water1.width / water1.height
else
	scaleFactorX = water1.height / water1.width
end

-- Set defaults for repeated textures which follow
timer.performWithDelay(1000, function()
	display.setDefault( "textureWrapX", "repeat" )
	display.setDefault( "textureWrapY", "mirroredRepeat" )

	-- Apply repeating textures and filters to objects
	water2.fill = { type="image", filename="water-fill.png" }
	water2.fill.scaleX = 0.25 * scaleFactorX
	water2.fill.scaleY = 0.25 * scaleFactorY
	water2.fill.rotation = 40
	water2.fill.effect = "filter.wobble"
	water2.fill.effect.amplitude = 6
	water2.alpha = 0.4

	water1.fill = { type="image", filename="water-fill.png" }
	water1.fill.scaleX = 0.25 * scaleFactorX
	water1.fill.scaleY = 0.25 * scaleFactorY
	water1.fill.effect = "filter.wobble"
	water1.fill.effect.amplitude = 6
	water1.alpha = 0.9

	-- Reset texture wrap modes
	display.setDefault( "textureWrapX", "clampToEdge" )
	display.setDefault( "textureWrapY", "clampToEdge" )

	-- Begin repeating transition function
	local function repeatTrans()
		transition.to( water1.fill, { time=4000, x=water1.fill.x+0.5, onComplete=repeatTrans })
		transition.to( water2.fill, { time=4000, x=water1.fill.x+0.5 })
		if ( logo.alpha == 1 ) then
			transition.to( logo, { time=3000, alpha=0.8, transition=easing.inOutQuad } )
			transition.to( water1, { time=3000, alpha=1, transition=easing.inOutQuad } )
			transition.to( water2, { time=3600, alpha=0.6, transition=easing.inOutQuad } )
		else
			transition.to( logo, { time=3000, alpha=1, transition=easing.inOutQuad } )
			transition.to( water1, { time=3000, alpha=0.9, transition=easing.inOutQuad } )
			transition.to( water2, { time=3600, alpha=0.4, transition=easing.inOutQuad } )
		end
	end
	repeatTrans()
end, 1);




[topic_controls]
[/topic_controls]