
Sprite3DReal Userlibrary
It seems that a few articles were erased.
Here is my old article:
@Shannara
Yes, I added 2 commands:(Not documented at the moment)
I hope it is useful for you.
Download: http://hometown.aol.de/Gastmailing/S3DR_1_0.zip (129 KB)
Here is a short example for the new commands:
//Edit:
@dracflamloc
regards
Stefan

Here is my old article:
@Shannara
Yes, I added 2 commands:(Not documented at the moment)
Code: Select all
S3DR_SetCameraRangeAndFOV(Near.f,Far.f,FOV.f) ;FOV is in degree
S3DR_SetDiffuseColors(Color1,Color2,Color3,Color4)

Download: http://hometown.aol.de/Gastmailing/S3DR_1_0.zip (129 KB)
Here is a short example for the new commands:
Code: Select all
InitSprite()
InitSprite3D()
InitKeyboard()
OpenScreen(800,600,16,"Example for S3DR_SetCameraRangeAndFOV() and S3DR_SetDiffuseColors()")
S3DR_CreateZBuffer()
CreateSprite(1,64,64,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
Box(0,0,64,64,#white)
StopDrawing()
Start3D()
S3DR_BeginReal3D()
S3DR_SetCullMode(#S3DR_NONE)
S3DR_MoveCamera(0,5,0)
S3DR_EndReal3D()
Stop3D()
Repeat
ExamineKeyboard()
Start3D()
S3DR_BeginReal3D()
S3DR_ClearScreenAndZBuffer(RGB(220,220,255))
S3DR_SetCameraRangeAndFOV(1,1000,120) ;FOV is in degree
S3DR_SelectTexture(1)
S3DR_SetDiffuseColors(#red,#green,#white,#blue)
For c=0 To 9;Draws a Cylinder
a1.f=c/10*ACos(-1)*2
a2.f=(c+1)/10*ACos(-1)*2
T1.f=c/10
T2.f=c/10+1/10
S3DR_SetTextureCoordinates(T1,0,T2,0,T1,1,T2,1)
X1.f=Sin(a1)*100
Y1.f=50
Z1.f=Cos(a1)*100
X2.f=Sin(a2)*100
Y2.f=50
Z2.f=Cos(a2)*100
X3.f=Sin(a1)*100
Y3.f=0
Z3.f=Cos(a1)*100
X4.f=Sin(a2)*100
Y4.f=0
Z4.f=Cos(a2)*100
S3DR_Draw3D(X1.f,Y1.f,Z1.f,X2.f,Y2.f,Z2.f,X3.f,Y3.f,Z3.f,X4.f,Y4.f,Z4.f)
Next
S3DR_SetTextureCoordinates(0,0,1,0,0,1,1,1)
If KeyboardPushed(#PB_Key_Left):S3DR_RotateCamera(-0.02,0,0):EndIf
If KeyboardPushed(#PB_Key_Right):S3DR_RotateCamera( 0.02,0,0):EndIf
If KeyboardPushed(#PB_Key_Up):S3DR_MoveCamera(0,0,1):EndIf
If KeyboardPushed(#PB_Key_Down):S3DR_MoveCamera(0,0,-1):EndIf
S3DR_SetDiffuseColors(#green,0,0,#green)
For x=-100 To 100 Step 20
For z=-100 To 100 Step 20
S3DR_Draw3D(-10+x, 0, 10+z, 10+x, 0, 10+z,-10+x, 0,-10+z, 10+x, 0,-10+z)
Next
Next
S3DR_EndReal3D()
Stop3D()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
S3DR_FreeZBuffer()
@dracflamloc
Sorry, it is not intended for now.Any possiblilty of a linux version?
regards
Stefan
Hi Shannara
Do you mean the texture coordinates ?
The value of a texture coordinate is from 0.0 to 1.0.
You can calculate the texture coordinate with that formula:
here is a short example:
I hope I understood you right. :roll:
regards
Stefan
Do you mean the texture coordinates ?

The value of a texture coordinate is from 0.0 to 1.0.
You can calculate the texture coordinate with that formula:
Code: Select all
tu.f=X.l/SpriteWidth.l
tv.f=Y.l/SpriteHeight.l
Code: Select all
#SpriteWidth=256
#SpriteHeight=256
InitSprite()
InitSprite3D()
InitKeyboard()
OpenScreen(800,600,16,"Texture coordinates")
S3DR_CreateZBuffer()
CreateSprite(1,#SpriteWidth,#SpriteHeight,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
Box(0,0,256,256,#green)
Circle(128,128,128,#red)
StopDrawing()
Repeat
Start3D()
S3DR_BeginReal3D()
S3DR_ClearScreenAndZBuffer(#blue)
S3DR_SelectTexture(1)
X1=10
Y1=10
X2=256-10
Y2=10
X3=10
Y3=256-10
X4=256-10
Y4=256-10
;convert the pixel-coordinates to texture-coordinates.
TU1.f=X1/#SpriteWidth
TV1.f=Y1/#SpriteHeight
TU2.f=X2/#SpriteWidth
TV2.f=Y2/#SpriteHeight
TU3.f=X3/#SpriteWidth
TV3.f=Y3/#SpriteHeight
TU4.f=X4/#SpriteWidth
TV4.f=Y4/#SpriteHeight
; tu1,tv1 tu2,tv2
; +---------+
; | |
; | |
; | |
; | |
; | |
; +---------+
; tu3,tv3 tu4,tv4
S3DR_SetTextureCoordinates(TU1.f,TV1.f,TU2.f,TV2.f,TU3.f,TV3.f,TU4.f,TV4.f)
; X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3 X4 Y4 Z4
S3DR_Draw3D( -1, 1, 5, 1, 1, 5, -1, -1, 5, 1, -1, 5);draws the selected sprite
S3DR_EndReal3D()
Stop3D()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
S3DR_FreeZBuffer()
I hope I understood you right. :roll:
regards
Stefan
I think this is correct, I merged the two codes above, the resulting code is pasted below. Had to change the #<color> values to the actual rgb values because this library would black out everything that was not green. So when I replaced those constants, the colors actually show on the texture
However, when running the following code, you will notice the reg and blue values pixelate the texture horribly. making huge chunky blocks of different colors, instead of a smooth gradient
I'm going to test it up against an actual textured picture to see how it looks ...
Also, I noticed that there is no need to create a 3Dsprite from a 2dsprite if using this library .... ... sweet!


Also, I noticed that there is no need to create a 3Dsprite from a 2dsprite if using this library .... ... sweet!
Code: Select all
#SpriteWidth=256
#SpriteHeight=256
InitSprite()
InitSprite3D()
InitKeyboard()
OpenScreen(800,600,16,"Texture coordinates")
S3DR_CreateZBuffer()
CreateSprite(1,#SpriteWidth,#SpriteHeight,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
Box(0,0,256,256,RGB(255,255,255))
StopDrawing()
Repeat
Start3D()
S3DR_BeginReal3D()
S3DR_ClearScreenAndZBuffer(#blue)
S3DR_SelectTexture(1)
S3DR_SetDiffuseColors(RGB(0,255,0),RGB(255,0,0),RGB(0,0,255),RGB(0,0,0))
X1=10
Y1=10
X2=256-10
Y2=10
X3=10
Y3=256-10
X4=256-10
Y4=256-10
;convert the pixel-coordinates to texture-coordinates.
TU1.f=X1/#SpriteWidth
TV1.f=Y1/#SpriteHeight
TU2.f=X2/#SpriteWidth
TV2.f=Y2/#SpriteHeight
TU3.f=X3/#SpriteWidth
TV3.f=Y3/#SpriteHeight
TU4.f=X4/#SpriteWidth
TV4.f=Y4/#SpriteHeight
; tu1,tv1 tu2,tv2
; +---------+
; | |
; | |
; | |
; | |
; | |
; +---------+
; tu3,tv3 tu4,tv4
S3DR_SetTextureCoordinates(TU1.f,TV1.f,TU2.f,TV2.f,TU3.f,TV3.f,TU4.f,TV4.f)
; X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3 X4 Y4 Z4
S3DR_Draw3D( -1, 1, 5, 1, 1, 5, -1, -1, 5, 1, -1, 5);draws the selected sprite
S3DR_EndReal3D()
Stop3D()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
S3DR_FreeZBuffer()
I can provide the textured image file I used, but it turns out the library stretches out the texture really wide (then the normal 256x256), and while doing this, it repeats existing pixels over, basically bleeding them. So a 32x32 tile on a 256x256 tileset, will be bled over a couple of tiles.
PM me if you want me to email you the texture used.
PM me if you want me to email you the texture used.
Hi Shannara
You can solve the problem by using a dither.Or you use the 32-Bit Screenmode...
regards
Stefan
You've right, it looks very ugly.I think this is correct, I merged the two codes above, the resulting code is pasted below. Had to change the #<color> values to the actual rgb values because this library would black out everything that was not green. So when I replaced those constants, the colors actually show on the texture However, when running the following code, you will notice the reg and blue values pixelate the texture horribly. making huge chunky blocks of different colors, instead of a smooth gradient I'm going to test it up against an actual textured picture to see how it looks ...

You can solve the problem by using a dither.
Code: Select all
S3DR_UseDither(#S3DR_TRUE)

That's true, but you need to create the sprite with the flag #PB_Sprite_Texture.Also, I noticed that there is no need to create a 3Dsprite from a 2dsprite if using this library .... ... sweet!

regards
Stefan
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
@Psychophanta
@Shannara
Can you test this code:
Does it have the same result ?
regards
Stefan
Yes, i will add this feature.I notice you add S3DR_FreeZBuffer() function at the end of all progs.
Can you do that it is made automatically when program ending is reached?

@Shannara
Can you test this code:
Code: Select all
InitSprite()
InitSprite3D()
InitKeyboard()
OpenScreen(800,600,16,"Texture coordinates")
S3DR_CreateZBuffer()
LoadSprite(1,"base1.bmp",#PB_Sprite_Texture)
Repeat
Start3D()
S3DR_BeginReal3D()
S3DR_ClearScreenAndZBuffer(#blue)
S3DR_SelectTexture(1)
S3DR_Draw3D( -1, 1, 5, 1, 1, 5, -1, -1, 5, 1, -1, 5)
S3DR_EndReal3D()
Stop3D()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
S3DR_FreeZBuffer()
regards
Stefan
Hmm, do you know of a full screen screenshot program that works with windows xp, sp2? With SP2, microsoft was dumb enough to remove the ability to take screenshots of directx screens (both windows and full screen), so for those tons of screeshot programs (like fraps), that rely on the OS to take screenshots, are broken with SP2.
The PB grabsprite/savesprite only works for windowed and not fullscreen mode. (it only returns a blank black screen for full screen).
The PB grabsprite/savesprite only works for windowed and not fullscreen mode. (it only returns a blank black screen for full screen).
Hi Shannara
Why you don't use the windowed mode for the snapshot ?
It should have the same result as in fullscreenmode.
The reason for the black image in fullscreenmode could be that you forgot to comment out FlipBuffers().
regards
Stefan
No , the most time I use the print-key for snapshots. :roll:Hmm, do you know of a full screen screenshot program that works with windows xp, sp2? With SP2, microsoft was dumb enough to remove the ability to take screenshots of directx screens (both windows and full screen), so for those tons of screeshot programs (like fraps), that rely on the OS to take screenshots, are broken with SP2.
Why you don't use the windowed mode for the snapshot ?
It should have the same result as in fullscreenmode.
Code: Select all
InitSprite()
InitSprite3D()
InitKeyboard()
OpenWindow(1,0,0,640,480,#PB_Window_ScreenCentered,"Snapshot")
OpenWindowedScreen(WindowID(),0,0,640,480,0,0,0)
S3DR_CreateZBuffer()
LoadSprite(1,"base1.bmp",#PB_Sprite_Texture)
Start3D()
S3DR_BeginReal3D()
S3DR_ClearScreenAndZBuffer(#blue)
S3DR_SelectTexture(1)
S3DR_Draw3D( -1, 1, 5, 1, 1, 5, -1, -1, 5, 1, -1, 5)
S3DR_EndReal3D()
Stop3D()
GrabSprite(2,0,0,640,480)
SaveSprite(2,"snapshot.bmp")
S3DR_FreeZBuffer()

regards
Stefan
Heh, works great with flipbuffers w/o the library commands, aka w/ sprite/sprite3d, Anyways, here's the screenie 
http://www.japbe.com/real3d.png

http://www.japbe.com/real3d.png
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact: