Page 1 of 2

Ultimate3D

Posted: Mon May 10, 2010 2:41 pm
by purescotty
Hello there, has anyone successfully used the Ultimate3D dll (for GameMaker) with PureBasic?
I've had limited success but when the program ends, I encounter a "readmemory" error like
maybe some memory not being released when U3D exits. Thoughts?

Scotty

;*******************************************************************************************

hwnd.d=OpenWindow(1,20,20,640,480,"Untitled",#PB_Window_SystemMenu)
If hwnd=0 Or InitSprite()=0 Or InitKeyboard()=0 Or InitMouse()=0 Or InitSound()=0 Or InitMovie()=0:End:EndIf
ws.d=OpenWindowedScreen(WindowID(1),0,0,1,1,0,0,0)

OpenLibrary(0,"C:\Documents and Settings\root\Desktop\USB\SDK\Ultimate3D.dll")

Prototype.d InitUltimate3D1(p0.d,p1.d,p2.d,p3.d,p4.d,p5.d,p6.d,p7.d,p8.d,p9.d)
InitUltimate3D.InitUltimate3D1 = GetFunction(0, "InitUltimate3D")

Prototype.d Cleanup1():Cleanup.Cleanup1 = GetFunction(0, "Cleanup")
Prototype.d Render1():Render.Render1 = GetFunction(0, "Render")
Prototype.d Present1():Present.Present1 = GetFunction(0, "Present")
Prototype.d SwitchView1():SwitchView.SwitchView1 = GetFunction(0, "SwitchView")

Prototype.d LoadBackground1(p0.s):LoadBackground.LoadBackground1 = GetFunction(0, "LoadBackground")

Prototype.d CreateCube1(p0.d,p1.d,p2.d,p3.d,p4.d,p5.d,p6.d,p7.d,p8.d,p9.d,p10.d)
CreateCube.CreateCube1 = GetFunction(0, "CreateCube")

Prototype.d TransmitControllerInformation1(p0.d,p1.d,p2.d,p3.d)
TransmitControllerInformation.TransmitControllerInformation1 = GetFunction(0, "TransmitControllerInformation")


Prototype.d TakeScreenshot1(p0.s):TakeScreenshot.TakeScreenshot1 = GetFunction(0, "TakeScreenshot")
Prototype.d DestroyCamera1(p0.d):DestroyCamera.DestroyCamera1 = GetFunction(0, "DestroyCamera")

Prototype.d UpdateCameraTransformation1(p0.d,p1.d,p2.d,p3.d,p4.d,p5.d,p6.d)
UpdateCameraTransformation.UpdateCameraTransformation1 = GetFunction(0, "UpdateCameraTransformation")

Prototype.d UpdateCameraProjection1(p0.d,p1.d,p2.d,p3.d,p4.d,p5.d,p6.d,p7.d,p8.d,p9.d)
UpdateCameraProjection.UpdateCameraProjection1 = GetFunction(0, "UpdateCameraProjection")


Prototype.d TransmitString1(p0.d,p1.s):TransmitString.TransmitString1 = GetFunction(0, "TransmitString")

Prototype.d LoadTexture1(p0.s,p1.d,p2.d,p3.d):LoadTexture2.LoadTexture1 = GetFunction(0, "LoadTexture")
Prototype.d SetTexturePath1(p0.s):SetTexturePath.SetTexturePath1 = GetFunction(0, "SetTexturePath")


TransmitString(0,"C:\controller1.bmp")
TransmitString(1,"C:\u3d.txt")
TransmitString(2,"")

InitUltimate3D(hwnd,0,0,640,480,32,2,1,0,0)

LoadBackground("C:\Documents and Settings\root\Desktop\USB\TechDemo\gfx\Transitions\ToolsAndToons.png")

number.d=0
x.d=0
y.d=0
z.d=0
height.d=5
rotx.d=0
roty.d=0
rotz.d=0

distance.d=10
min_range.d=0.5
max_range.d=100000
view.d=90
v_left.d=0
v_top.d=0
v_width.d=640
v_height.d=480
actual_aspect.d=0
render_target.d=0


quit=0
Repeat
WindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape):quit=1:EndIf

If KeyboardPushed(#PB_Key_Left)
rotx=rotx+1
UpdateCameraTransformation(number,x,y,z+height,rotx,roty,rotz)
UpdateCameraProjection(number,min_range,max_range,view,v_left,v_top,v_width,v_height,actual_aspect,render_target)
EndIf

If KeyboardPushed(#PB_Key_Right)
rotx=rotx-1
UpdateCameraTransformation(number,x,y,z+height,rotx,roty,rotz)
UpdateCameraProjection(number,min_range,max_range,view,v_left,v_top,v_width,v_height,actual_aspect,render_target)
EndIf

Present()
TransmitControllerInformation(0,0,0,1)
Render()

Until quit=1

Cleanup()
CloseLibrary(0)
CloseWindow(1)
End

;*****************************************************************************************

Re: Ultimate3D

Posted: Mon May 10, 2010 2:51 pm
by Kaeru Gaman
Hi Scotty,
there is a button labelled "code" in the post and edit function of the forums.
please use this one to put your code in tags, this will provide a codebox with monospace font and copy function.

Code: Select all

; this is code

Re: Ultimate3D

Posted: Mon May 10, 2010 3:00 pm
by purescotty
Thank you, this is all new and exciting for me. Press the "code" button, I got it!

Scotty

Code: Select all

;*******************************************************************************************************

hwnd.d=OpenWindow(1,20,20,640,480,"Untitled",#PB_Window_SystemMenu)
If hwnd=0 Or InitSprite()=0 Or InitKeyboard()=0 Or InitMouse()=0 Or InitSound()=0 Or InitMovie()=0:End:EndIf 
ws.d=OpenWindowedScreen(WindowID(1),0,0,1,1,0,0,0)

OpenLibrary(0,"C:\Documents and Settings\root\Desktop\USB\SDK\Ultimate3D.dll")

Prototype.d InitUltimate3D1(p0.d,p1.d,p2.d,p3.d,p4.d,p5.d,p6.d,p7.d,p8.d,p9.d)
InitUltimate3D.InitUltimate3D1 = GetFunction(0, "InitUltimate3D")

Prototype.d Cleanup1():Cleanup.Cleanup1 = GetFunction(0, "Cleanup")
Prototype.d Render1():Render.Render1 = GetFunction(0, "Render")
Prototype.d Present1():Present.Present1 = GetFunction(0, "Present")
Prototype.d SwitchView1():SwitchView.SwitchView1 = GetFunction(0, "SwitchView")

Prototype.d LoadBackground1(p0.s):LoadBackground.LoadBackground1 = GetFunction(0, "LoadBackground")

Prototype.d CreateCube1(p0.d,p1.d,p2.d,p3.d,p4.d,p5.d,p6.d,p7.d,p8.d,p9.d,p10.d)
CreateCube.CreateCube1 = GetFunction(0, "CreateCube")

Prototype.d TransmitControllerInformation1(p0.d,p1.d,p2.d,p3.d)
TransmitControllerInformation.TransmitControllerInformation1 = GetFunction(0, "TransmitControllerInformation")


Prototype.d TakeScreenshot1(p0.s):TakeScreenshot.TakeScreenshot1 = GetFunction(0, "TakeScreenshot")
Prototype.d DestroyCamera1(p0.d):DestroyCamera.DestroyCamera1 = GetFunction(0, "DestroyCamera")

Prototype.d UpdateCameraTransformation1(p0.d,p1.d,p2.d,p3.d,p4.d,p5.d,p6.d)
UpdateCameraTransformation.UpdateCameraTransformation1 = GetFunction(0, "UpdateCameraTransformation")

Prototype.d UpdateCameraProjection1(p0.d,p1.d,p2.d,p3.d,p4.d,p5.d,p6.d,p7.d,p8.d,p9.d)
UpdateCameraProjection.UpdateCameraProjection1 = GetFunction(0, "UpdateCameraProjection")


Prototype.d TransmitString1(p0.d,p1.s):TransmitString.TransmitString1 = GetFunction(0, "TransmitString")

Prototype.d LoadTexture1(p0.s,p1.d,p2.d,p3.d):LoadTexture2.LoadTexture1 = GetFunction(0, "LoadTexture")
Prototype.d SetTexturePath1(p0.s):SetTexturePath.SetTexturePath1 = GetFunction(0, "SetTexturePath")


TransmitString(0,"C:\controller1.bmp")
TransmitString(1,"C:\u3d.txt")
TransmitString(2,"")

InitUltimate3D(hwnd,0,0,640,480,32,2,1,0,0)

LoadBackground("C:\Documents and Settings\root\Desktop\USB\TechDemo\gfx\Transitions\ToolsAndToons.png")

number.d=0
x.d=0
y.d=0
z.d=0
height.d=5
rotx.d=0
roty.d=0
rotz.d=0

distance.d=10
min_range.d=0.5
max_range.d=100000
view.d=90
v_left.d=0
v_top.d=0
v_width.d=640
v_height.d=480
actual_aspect.d=0
render_target.d=0


quit=0
Repeat
WindowEvent()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape):quit=1:EndIf

If KeyboardPushed(#PB_Key_Left)
rotx=rotx+1
UpdateCameraTransformation(number,x,y,z+height,rotx,roty,rotz)
UpdateCameraProjection(number,min_range,max_range,view,v_left,v_top,v_width,v_height,actual_aspect,render_target)
EndIf

If KeyboardPushed(#PB_Key_Right)
rotx=rotx-1
UpdateCameraTransformation(number,x,y,z+height,rotx,roty,rotz)
UpdateCameraProjection(number,min_range,max_range,view,v_left,v_top,v_width,v_height,actual_aspect,render_target)
EndIf

Present()
TransmitControllerInformation(0,0,0,1)
Render()

Until quit=1

Cleanup()
CloseLibrary(0)
CloseWindow(1)
End

;*******************************************************************************************************

Re: Ultimate3D

Posted: Mon May 10, 2010 3:21 pm
by pjay
I think you need to use PrototypeC.

Re: Ultimate3D

Posted: Mon May 10, 2010 3:28 pm
by purescotty
int main()
{
printf("What is prototypec?\n");
exit(0);
}


Scotty

Re: Ultimate3D

Posted: Mon May 10, 2010 3:30 pm
by pjay
:lol:

Search & Replace 'Prototype' with 'PrototypeC'.

Re: Ultimate3D

Posted: Mon May 10, 2010 3:47 pm
by purescotty
I thought that since GameMaker uses doubles that any parameters U3D uses would
be doubles or strings. Or did you have some other meaning that I do not realize?

Re: Ultimate3D

Posted: Mon May 10, 2010 3:54 pm
by purescotty
Using ProtoTypeC instead of ProtoType does not help, but thanks for your suggestion.

Scotty

Re: Ultimate3D

Posted: Mon May 10, 2010 4:11 pm
by Trond
Paste this on the top of your code:

Code: Select all

Global _regout
Macro regout(register)
  !push register
  !pop  [v__regout]
  !pushad
  Debug _regout
  !popad
EndMacro
Then paste this at various places in the code:
regout(esp)

It will debug a number that should be the same each time (unless you're inside a procedure). If it isn't you did something wrong with the number of parameters of some called imported function.

Re: Ultimate3D

Posted: Mon May 10, 2010 4:31 pm
by Kuron
Hello there, has anyone successfully used the Ultimate3D dll
I can't make any promises, but I would be willing to take a gander, but I have no idea what Ultimate3D is or where I can find it. Any chance of a link to the engine?

Re: Ultimate3D

Posted: Mon May 10, 2010 4:39 pm
by pjay
Gave this a test myself.

Using Tronds suggestion:

Prototype: the ESP register changes during program run, and the program eventually ends with a stack overflow error.
PrototypeC: the ESP register remains static, and no crash occurs.

Kuron - Download from here mate: http://forum.ultimate3d.org/topic/7194536/1/

Re: Ultimate3D

Posted: Mon May 10, 2010 5:43 pm
by Trond
pjay wrote:Gave this a test myself.

Using Tronds suggestion:

Prototype: the ESP register changes during program run, and the program eventually ends with a stack overflow error.
PrototypeC: the ESP register remains static, and no crash occurs.
Then PrototypeC is the correct.

Re: Ultimate3D

Posted: Mon May 10, 2010 6:35 pm
by purescotty
Sorry, been off-line.

Kuron - http://www.ultimate3d.org/

I tried PrototypeC and still had the same problem. Did you make any other modifications?

Trond - Thanks for the assembly debug code. I'm using the number of parameters that are in the GameMaker
example code.

It's also possible that the functions are returning something other than doubles, which would result in the stack being off.

Thanks to everyone for their input.

Scotty

Re: Ultimate3D

Posted: Mon May 10, 2010 6:50 pm
by Trond
It's also possible that the functions are returning something other than doubles, which would result in the stack being off.
That would only cause the fpu register stack to become off. While "serious", it won't crash your program, only give nonsense results in computations with floats and doubles.

Re: Ultimate3D

Posted: Mon May 10, 2010 6:56 pm
by pjay
Have you tried the latest beta (2.1.3 from the link I posted earlier) - It's the one I used and had no problems.

Didn't change anything in your code with the exception of the loaded image files and the logging directory.