ODD2d.mod - DrawImagePoly

BlitzMax Forums/BlitzMax Programming/ODD2d.mod - DrawImagePoly

Raz(Posted 2012) [#1]
Is it possible to use DrawImagePoly with a repeating tile? That is, the supplied is repeated to extend over the whole polygon?

Thanks :)
Chris


Raz(Posted 2012) [#2]
I've just looked at the comments on the ODD2d code and I get how it works now.

Basically I'm going to have to stencil the image over the polygon multiple times.

Luckily doesn't need to be run in real time as I'm just creating the images during level load.

Last edited 2012


Raz(Posted 2012) [#3]
Actually no, that won't work because each time I call drawimagepoly, it draws the whole polygon regardless of image size, hmmm.

Edit: It looks like it just extends the boundaries of the image out to fill the remaining space.

What I get:


What I hoped for:


Source:
http://chrismingay.co.uk/PolyTest.zip

Any ideas?

Last edited 2012


Oddball(Posted 2012) [#4]
The polygon functions in Odd2D use the textures as provided by Max2D. Max2D does not store the textures as repeatable and even blends the edges to fill the rest of the texture. This means drawing a polygon with a repeating TImage is not possible with the way Max2D is set up.

I did look into adding an image flag for repeating textures, but abandoned the idea as it was too impractical to shoehorn it into the existing Max2D image framework.


Raz(Posted 2012) [#5]
Ahh ok, never mind!

I've seen some other posts regarding "SetTextureRepeat" and I think Armitage has got textured polygons working, so I'll have a look around.

Failing that, I will just briefly make a massive Image that fills the whole level and "mask" it from that.


Alberto-Diablo(Posted 2012) [#6]
[offtop]

2 Oddball

In your module Aspect.mod have some bugs, with viewport and offsets.

[/offtop]


Oddball(Posted 2012) [#7]
I've not looked at aspect.mod in a long time as odd2d.mod does all that and more. What is the issue with aspect.mod? Do you have a small example of the problem?


Alberto-Diablo(Posted 2012) [#8]
Given it was ... then I decided to challenge yourself.

Rem
bbdoc: Set drawing viewport
about: Use in place of #SetViewport
End Rem
'Function SetAspectViewport( x:Int, y:Int, width:Int, height:Int )
'	Local x2:Float = Min(x + width, _xoffset + _vwidth)
'	Local y2:Float = Min(y + height, _yoffset + _vheight)
'	x = Max(x, _xoffset)
'	y = Max(y, _yoffset)
'	SetViewport(x, y, x2 - x, y2 - y)
'End Function

Function SetAspectViewport(x:Int, y:Int, width:Int, height:Int)
	Local x2:Float = Min(x + width + _xoffset, _xoffset + _vwidth)
	Local y2:Float = Min(y + height + _yoffset, _yoffset + _vheight)
	x = Max(x + _xoffset, _xoffset)
	y = Max(y + _yoffset, _yoffset)
	SetViewport(x, y, x2 - x, y2 - y)
End Function


There is also a problem with the displacement of one pixel on the screen.

When I draw the image in the coordinates 0.0,0.0. Visually, it seems to be rendered in the coordinates 1.0,0.0


Armitage 1982(Posted 2012) [#9]
I remember having a complete example of my textured polygon on the Code Archives but it has been deleted as well as every other code in the repository.
Unfortunately I can't find that example anymore on my disks :(

But you can read these 2 entries and even reuse the code on one of them as a start :

http://www.blitzbasic.com/Community/posts.php?topic=97065

http://www.blitzbasic.com/Community/posts.php?topic=96133

In a nutshell all I did was decompose an array of polygon vertex in triangles and then using the DrawImagePoly() from Odd with a texture clamped to repeat.
So basically you need Odd2D.mod and a texture wrapping code.

I think I borrowed and adapted that code from Ian Duff in order to make texture wrapping easier under OpenGL.
(I leaved the DirectX version as comments, just in case, but the original code may be better)

[bbcode]
Const TEXTURECLAMP:Int = 0
Const TEXTUREWRAP:Int = 1
Const TEXTUREHWRAPONLY:Int = 2
Const TEXTUREVWRAPONLY:Int = 3

Function SetTextureRepeat(image:TImage, rep:Int = TEXTUREWRAP)

If Not (image.width = Pow2Size(image.width) And image.Height = Pow2Size(image.Height))
'Put your own assert code here ;)
EndIf

' ?Win32
' Local D3D7Driver:TD3D7Max2DDriver = TD3D7Max2DDriver(_max2dDriver)
' ?

Local n:Int = image.seqs.Length
Repeat
n:-1

Select rep

Case TEXTURECLAMP
' ?Win32
' If D3D7Driver
' 'DX
' D3D7Driver.device.SetTextureStageState 0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP
' Else
' ?
'GL
glBindTexture GL_TEXTURE_2D, TOGLImageFrame(image.Frame(n)).glif.name
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
' ?Win32
' EndIf
' ?

Case TEXTUREVWRAPONLY
' ?Win32
' If D3D7Driver
' 'DX
' D3D7Driver.device.SetTextureStageState 0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP
' Else
' ?
'GL
glBindTexture GL_TEXTURE_2D, TOGLImageFrame(image.Frame(n)).glif.name
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT
' ?Win32
' EndIf
' ?

Case TEXTUREHWRAPONLY
' ?Win32
' If D3D7Driver
' 'DX
' D3D7Driver.device.SetTextureStageState 0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP
' Else
' ?
'GL
glBindTexture GL_TEXTURE_2D, TOGLImageFrame(image.Frame(n)).glif.name
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
' ?Win32
' EndIf
' ?

Case TEXTUREWRAP
' ?Win32
' If D3D7Driver
' 'DX
' D3D7Driver.device.SetTextureStageState 0, D3DTSS_ADDRESS, D3DTADDRESS_WRAP
' Else
' ?
'GL
glBindTexture GL_TEXTURE_2D, TOGLImageFrame(image.Frame(n)).glif.name
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT
' ?Win32
' EndIf
' ?

End Select

Until n < 1
End Function


Function Pow2Size:Int(n:Int)
Local t:Int = 1
While t < n
t :* 2
Wend
Return t
End Function
[/bbcode]

Hope this helps.

Last edited 2012


Raz(Posted 2012) [#10]
Armitage, thanks for that!

For what it's worth I think I found your code archive code which is now not being linked to (though still exists) and have been using that and it's doing exactly what I require :)