Perfect 2D in 3D Quads - no Blurr

Community Forums/Showcase/Perfect 2D in 3D Quads - no Blurr

coffeedotbean(Posted 2003) [#1]
We all wanna make 2D games but want to do it in 3D with quads because of all kinds of cool effects.
The problem was that all textures got filtered in B3D, right?.. wrong, as long as you use square images in the power of 2 (2,4,8,16,32,64,128 etc), it can be done with no blur, and crisp images, you can't tell the difference between 2D and 3D Quads.

Current Commands:

Graphics2D(Width,Height,Depth,Mode)
Load3DImage(FileName$,[Alpha#])
Load3DAnimImage(FileName$,FrameWidth,FrameHeight,StartFrame,FrameCount,[Alpha#])
Draw3DImage(Image,X,Y,[Frame])
Handle3DImage(Image,PosX,PosY)

I can't take full credit for this I put this together when skidracer posted a way of creating a no blurred sprite in a BB post. I just made it work with quads.

Feel free at add to this, It got all the tools I want for my game. Enjoy.

http://www.jabawokie.ukgamers.net/2DSprite.zip




jfk EO-11110(Posted 2003) [#2]
cool! although I am afraid it must be used in a certain resolution(?). However, the example pic looks very crispy. thx!


coffeedotbean(Posted 2003) [#3]
Certain Resolution?

Works ok in 640,480 and 800x600 and 1024x768... unless you mean the image must be sqaure and in the power of 2 (2,4,8,16,32,64,128 etc). A fair trade off :D

I just added Rotation (will be in the next release)Look pretty good although theres a slight blurr, hard to tell unless you zoom in though.

I think I'll need to add some kind of draw order though.


jfk EO-11110(Posted 2003) [#4]
Ok, if the "images" are used with a fixed size (as they are in 2D), then it might work ok (although the resolution must be a factor in the positioning), but if you want them to be scaled resolution independently (eg. a quad is always 25 percent of the screen, no matter what resolution) then it might be blurred in lower and higher resolutions.

However, very nice and useful stuff!


simonh(Posted 2003) [#5]
skidracer posted some code for doing this in the code archives - I think his term for them was 'pixies'.


coffeedotbean(Posted 2003) [#6]
Yeah I credited SkidRacer.

The images don't scale depending on the resolution if you load a 64x64 image with my Load3d[Anim]Image() and position it at X:12 Y:67 for example, it will stay that size and at that position no matter the resolution, tried resolutions from 320x240 to 1027x768 and all is A-OK.

I just added draw ordering also.

I think thats about it, I looked at scale image but it went all blurry... what i wanted to avoid in the first place.


Ian Thompson(Posted 2003) [#7]
Very nice!


IPete2(Posted 2003) [#8]
Thanks for that - very nice idea!

IPete2.


coffeedotbean(Posted 2003) [#9]
For the next release.. tonight i hope, there will be a few more function:

Rotate3DImage(Image,Angle) - Done!
ImagesOverlap(Image1,X,Y,Image2,X,Y) - Working on it

I'll also be reworking the Draw3DImage() function to have the Alpha and other Entity effects in the Draw3DImage function. instead of the Load3DImage() function... make mroe sense.

I'll also be fixing the slow up when the program runs for a while, i just need to free textures when they are used.


QuickSilva(Posted 2003) [#10]
This is great. Have you seen Sprite Control? Will your functions have as many features?

Jason.


EOF(Posted 2003) [#11]
Nice work David. This is the sort of thing I've been wanting to do in SpriteControl for ages.

What do you think to this version of your Load3DImage() function? It let's you load and display any image size.
The function loads a padded version of the original image into a texture and scales the texture to stretch beyond the quads size (which mimics the original image size).
The downside to this is that if the programmer say, loads an image at 258 by 130 then the size of the image after being padded out will be 512 by 256.

Anyhow, the sprite and image still seem identical:



Function Load3DImage(File$,Alpha#=1)
	
	Local TempMesh = CreateMesh()
	Local TempSurf = CreateSurface(TempMesh)

	AddVertex TempSurf,-1,1,0 ,0,0 : AddVertex TempSurf,1,1,0 , 1,0
	AddVertex TempSurf,-1,-1,0 ,0,1 : AddVertex TempSurf,1,-1,0 , 1,1
	AddTriangle TempSurf,0,1,2 : AddTriangle TempSurf,3,2,1
	
	Local tmpimg=LoadImage(File$)
	Local imgW=ImageWidth(tmpimg) , imgH=ImageHeight(tmpimg)
	Local sizeX=NextPower(imgW) , sizeY=NextPower(imgH)
	Local newimg=CreateImage(sizeX,sizeY)
	CopyRect 0,0,imgW,imgH,0,0,ImageBuffer(tmpimg),ImageBuffer(newimg)
	FreeImage tmpimg
	Local tmpfile$=SystemProperty("tempdir")+"scTMP"+Rand(9999)
	SaveImage newimg,tmpfile$ : FreeImage newimg
	
	tex=LoadTexture(tmpfile$,1+4) : DeleteFile tmpfile$
	sizeX=TextureWidth(tex) : sizeY=TextureHeight(tex)
	ScaleTexture tex,Float(sizeX)/Float(imgW),Float(sizeY)/Float(imgH)

	EntityTexture TempMesh,tex
	EntityFX TempMesh,1
	EntityParent TempMesh,SpriteControler
	ScaleEntity TempMesh,Float(ImgW)/2,Float(imgH)/2,1	 
	EntityAlpha TempMesh,Alpha#
	
	Handle3DImage(TempMesh,-1,-1)
	spritetexture=tex
	Return TempMesh
	
End Function



You also need this function:
; round to next POWER   (2..4..8..16..32..64 etc)
Function NextPower(n)
	Return 2 Shl (Len(Int(Bin(n-1)))-1)
End Function


!EDIT!
I got this working with my ImageWidth3D() and ImageHeight3D() functions. It now shows the correct (original) image size in pixels.

I may incorporate your method into SpriteControl with full credits of course :-)

Good luck with the collision stuff!


coffeedotbean(Posted 2003) [#12]
Jim, thats nice work ill try it when i get home, it not me who needs the credit, skidracer did the hard work i just made it work with quads and put it into easy to use functions.

But if you can get your sprite control to work with this pixel perfect-ness then please go ahead.

heres the image collision function its very basic, and wont work with images that have be rotated, and you have to manualy enter each images size, and they must have the same handle position... but hey it works :)
Function Images3DOverlap(Image1,X1,Y1,Size1,Image2,X2,y2,Size2)

	If X1+Size1>X2 And X1<X2+Size2 And Y1+Size1>Y2 And Y1<Y2+Size2 Then Return 1

End Function



wedoe(Posted 2003) [#13]
Very nice, I use Norc's old system which basically does the same and it never fails :)