Simple way to put a picture on screen using polys?

BlitzMax Forums/BlitzMax Beginners Area/Simple way to put a picture on screen using polys?

Sokurah(Posted 2011) [#1]
I'm working on a Mac version of one of my games and I have a strange problem with the background picture which *mostly* just shows as a small white blob at the center of the screen (yeah, it seems a big random) and I can't quite figure out what's causing it.

I'm thinking I should try drawing it as a textured polygon instead of 'just' using DRAWIMAGE - just to see if it makes any difference, but I don't have any experience will all that poly-stuff.

Can someone please help me out with a very simple way to get a single picture on screen using this method?

Here's what happens.


Last edited 2011


ima747(Posted 2011) [#2]
how big is the image? Are you validating it after loading?


Sokurah(Posted 2011) [#3]
The image is the size of the screen - 1024x768. I've tried to load it both as JPG and PNG and it doesn't make any difference. It is being loaded, though, because sometimes it's there...sometimes it isn't - and the above happens instead.


ImaginaryHuman(Posted 2011) [#4]
It looks like how it would look if it were a 1 pixel image. Any issues with SetScale or anything?


Sokurah(Posted 2011) [#5]
I've been sitting with this problem most of the evening and I've come to the conclusion that the problem lies with the one piece of code I haven't written and don't know how to fix - IndiePath's TexturedPoly module...but I'm sure someone can fix it. ;-)

I've made a RAR file with the 4 files needed to test it: The test program, the module (which I've modified so it's imported) and the two images - a background and the gradient dot.

http://dl.dropbox.com/u/2697142/PolyProblem.rar (33KB)

Below is just the test program from the archive. This is as simple as it gets.

Just comment out the SetGraphicsDriver and it runs perfectly on Windows. However, it's on OSX I'm having the problem.

* If you comment out just the TPoly.Line line you get the background without problems.
* Leave it there and you get the line, but the background picture becomes a glowing dot in the centre of the screen.

So it's clearly the TPoly.Line function that is the problem, as it won't play nice with a background (on a Mac) but I have no idea why.

I'd be grateful for a solution to this?




Yan(Posted 2011) [#6]
SuperStrict
'SetGraphicsDriver D3D7Max2DDriver()
SetGraphicsDriver GLMax2DDriver()

Include "texturedpoly.bmx"

Global BackdropGFX:TImage = LoadImage ("background.jpg")
Global GlowingDot:TImage = LoadImage ("dot.png")
MidHandleImage GlowingDot

Graphics 512,512, 0
SetBlend LIGHTBLEND
TPoly.Initialise()

Repeat
	Cls
	SetColor 255,255,255
	DrawImage BackdropGFX, 0,0
	
	TPoly._Begin()
	TPoly.Line(GlowingDot, 0, 0, 0, $ffffff00, 511, 511, $ffff2080, 36)
	TPoly._End()
	' Horrible horrible kludge to resync 'state_texenabled' flag (see EnableTex()). :o[
	DrawImage GlowingDot, 1000000, 1000000
	' or add...
	'TGLImageFrame(image.Frame(frame)).Draw(0, 0, 0, 0, 0, 0, 0, 0, 1, 1)
	'...to texturedpoly drawing code
	Flip
Until KeyHit(key_escape)



Oddball(Posted 2011) [#7]
If you are going to go to all this trouble to kludge it why not simply move EnableTex() from the Private block to the Public block, then all you need to do is add EnableTex() to your textured poly function. Alternatively you could try my Odd2D module which will happily work along side the standard Max2D commands in either D3D7, D3D9 or OpenGL. That way you could also get rid of all that TPoly.Initialise/Begin/End nonsense too.


AdamRedwoods(Posted 2011) [#8]
What a great game! I love Omega Race on the Vic-20!


For another way of fixing the problem, one could use ResetGLContext():
SuperStrict
SetGraphicsDriver GLMax2DDriver()

Include "texturedpoly.bmx"

Global BackdropGFX:TImage = LoadImage ("background.jpg")
Global GlowingDot:TImage = LoadImage ("dot.png")
MidHandleImage GlowingDot

Global gdriver:TGraphics = Graphics( 512,512, 0)
SetBlend LIGHTBLEND
TPoly.Initialise()


Repeat
	Cls
	SetColor 255,255,255
	DrawImage BackdropGFX, 0,0
	
	
	TPoly._Begin()
		TPoly.Line(GlowingDot, 0, 0, 0, $ffffff00, 511, 511, $ffff2080, 36)
	TPoly._End()
	GLMax2DDriver().ResetGLContext( gdriver )

	Flip

Until KeyHit(key_escape)



Sokurah(Posted 2011) [#9]
Cool, now there's a bag-full of solutions. :-)

@Yan
I ended up using the DrawImage GlowingDot, 1000000, 1000000 method. That seemed like a nice and fast way of doing it...even if it is a horrible kludge. ;-)

@Oddball
Thanks for your suggestions but I'm not going to introduce new modules and change functionality all through the program unless I absolutely have to. Hmm, and the string EnableTex() does not appear anywhere in the TexturedPoly code. But I will check out your Odd2D module and see if it's something I can find a use for in future projects.

@AdamRedwoods
I'd already used Yan's solution before you answered, so I haven't tried your solution, but I'll try it when I find the time to port Star Castle too.

Glad you like the game. The Windows version is just under two years old, but it looks like I'll be releasing an OSX version soon. I'm also working on an iPad port of it, which is nearly done, but I doubt I'll post about that here, though, as it's not done in BlitzMax...but anyone interrested in it should keep an eye on my blog for it.

Thanks for the help guys. <3