Page 1 of 2
Newbie 3D engine question
Posted: Wed Mar 09, 2016 2:46 pm
by mrw
Hi,
I´m trying to learn PureBasics approach to the OGRE 3D engine by doing it from scratch.
I have run some of the examples that came with PureBasic and tried to construct my own minimal environment from those examples.
All examples run that "Screen3DRequester.pb" file to give the user a choice but I don´t want that at all.
But I have run into a problem that someone most likely can help me solve.
This piece of code below crashes when I run it. If I comment out the "CreateCamera" line it doesn´t crash and it opens a windows and closes when I hit ESC.
So WHY does it crash when I want to create a camera?? If I had forgot to add some init code PB normally tells me that, but it shouldn´t crash right?
Code: Select all
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
If OpenWindow(0, 0, 0, 640, 480, "3D Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Result = OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)
EndIf
;-- 3d stuff
WorldShadows(#PB_Shadow_Additive)
AmbientColor(0)
; node for Light and Billboard (Sun)
CreateNode(0, 0, 3000, 0)
;Create light
CreateLight(0, RGB(90, 105, 132), 0, 3000, 0)
AttachNodeObject(0, LightID(0))
; Static geometry
;
; Create Entity
CreateCube(0, 1)
CreateEntity(0, MeshID(0), #PB_Material_None)
; Create Static geometry
CreateStaticGeometry(0, 1000, 1000, 1000, #True)
For z = -10 To 10
For x = -10 To 10
AddStaticGeometryEntity(0, EntityID(0), x * 1000, 0, z * 1000, 1000, 10, 1000, 0, 0, 0)
Height.f = 200 + Random(800)
AddStaticGeometryEntity(0, EntityID(0), x * 1000, Height/2, z * 1000, 200, Height, 200, 0, Random(360), 0)
Next
Next
; Build the static geometry
BuildStaticGeometry(0)
FreeEntity(0)
; Camera
;
CreateCamera(0, 0, 0, 100, 100)
;--
Repeat
Repeat
Event = WindowEvent()
ExamineKeyboard()
If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End
Else
Delay(1)
EndIf
Until Event = 0
RenderWorld()
FlipBuffers()
ForEver
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 3:46 pm
by Hades
I do not have enough experience to really help you with that, but what I can tell you is that your code runs just fine here, compiled with x64 and x86 compiler on Win7, and shows a skyline.
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 3:53 pm
by IdeasVacuum
Haven't time to test your code but the crash might actually be caused by FreeEntity(0)
In the code, you have everything with the ID of '0'. Make an Enumeration to ensure each item has a unique ID:
Code: Select all
Enumeration
#Win
#Sun
#Light
#Cube
#Entity
#StaticGeom
#Camera
EndEnumeration
If InitEngine3D() And InitSprite() And InitKeyboard() And InitMouse()
If OpenWindow(#Win, 0, 0, 640, 480, "3D Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Win), 0, 0, WindowWidth(#Win), WindowHeight(#Win), 0, 0, 0)
;-- 3d stuff
WorldShadows(#PB_Shadow_Additive)
AmbientColor(0)
; node for Light and Billboard (Sun)
CreateNode(#Sun, 0, 3000, 0)
;Create light
CreateLight(#Light, RGB(90, 105, 132), 0, 3000, 0)
AttachNodeObject(#Sun, LightID(#Light))
; Static geometry
;
; Create Entity
CreateCube(#Cube, 1)
CreateEntity(#Entity, MeshID(#Cube), #PB_Material_None)
; Create Static geometry
CreateStaticGeometry(#StaticGeom, 1000, 1000, 1000, #True)
For z = -10 To 10
For x = -10 To 10
AddStaticGeometryEntity(#StaticGeom, EntityID(#Entity), x * 1000, 0, z * 1000, 1000, 10, 1000, 0, 0, 0)
Height.f = 200 + Random(800)
AddStaticGeometryEntity(#StaticGeom, EntityID(#Entity), x * 1000, Height/2, z * 1000, 200, Height, 200, 0, Random(360), 0)
Next
Next
; Build the static geometry
BuildStaticGeometry(#StaticGeom)
FreeEntity(#Entity)
; Camera
;
CreateCamera(#Camera, 0, 0, 100, 100)
;--
Repeat
Repeat
Event = WindowEvent()
ExamineKeyboard()
If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End
Else
Delay(1)
EndIf
Until Event = 0
RenderWorld()
FlipBuffers()
ForEver
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
[/size]
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 4:06 pm
by mrw
Thanks for your replies!
Hades: Well if the exact same code works for you but not for me, then I have a problem.. I run this in Windows 10 x64.
I know I have working gfx-drivers and pretty decent hw that easily runs DX HW accelerated games.
What else could be different that makes this works for you but not for me? Is there any prerequisite for running an OGRE code that I havent done? I have installed PB just using the standard installation.
IdeasVacuum: I tried your code, but I crashes on the exact same place, even with your enumeration addition.
And it works fine(well, it only opens a black windows) if a comment out the CreateCamera.
If the problem was with FreeEntity, how would I test that? Theres no difference if I comment out that command.
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 4:31 pm
by Hades
I've just (re-?) installed the newest versions of DirectX9.0c , DirectX SDK and the CG Toolkit from nvidia, because of problems with code not running. Since then it's all fine. I don't know what's the problem here, but if you want to do 3d, you'll want all of that anyways, I guess, so just give it a try?
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 4:54 pm
by IdeasVacuum
Nothing to do with the crash but your loop is OTT. Simplified:
Code: Select all
Repeat
Event = WindowEvent()
ExamineKeyboard()
Delay(1)
RenderWorld()
FlipBuffers()
Until Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 4:56 pm
by applePi
as Hade said install directx 9.0c from microsoft or download the whole 9.0c package from here
http://filehippo.com/download_directx
until then try to run he code by going from the ide to compilers --> compiler options , then in the Library subsystem box write this word opengl . click ok then run your code
the camera is essential it is through it you look at your scene
your city is very big so i have added more camera functions. and the key and mouse usage to fly over your designed city
edit: if you don't see something then it happened your camera inside a building so press Up key to go outside the building
Code: Select all
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
Define.f KeyX, KeyY, MouseX, MouseY
#cameraSpeed = 5
If OpenWindow(0, 0, 0, 640, 480, "3D Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Result = OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)
EndIf
;-- 3d stuff
WorldShadows(#PB_Shadow_Additive)
AmbientColor(0)
; node for Light and Billboard (Sun)
CreateNode(0, 0, 3000, 0)
;Create light
CreateLight(0, RGB(90, 105, 132), 0, 3000, 0)
AttachNodeObject(0, LightID(0))
; Static geometry
;
; Create Entity
CreateCube(0, 1)
CreateEntity(0, MeshID(0), #PB_Material_None)
; Create Static geometry
CreateStaticGeometry(0, 1000, 1000, 1000, #True)
For z = -10 To 10
For x = -10 To 10
AddStaticGeometryEntity(0, EntityID(0), x * 1000, 0, z * 1000, 1000, 10, 1000, 0, 0, 0)
Height.f = 200 + Random(800)
AddStaticGeometryEntity(0, EntityID(0), x * 1000, Height/2, z * 1000, 200, Height, 200, 0, Random(360), 0)
Next
Next
; Build the static geometry
BuildStaticGeometry(0)
FreeEntity(0)
; Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 800,500, #PB_Absolute)
CameraLookAt(0, 0,200,-1000)
;--
Repeat
Repeat
Event = WindowEvent()
Until Event = 0
If ExamineMouse()
MouseX = -MouseDeltaX()/10
MouseY = -MouseDeltaY()/10
EndIf
If ExamineKeyboard()
;moving the camera ================================================
If KeyboardPushed(#PB_Key_Left)
KeyX = -#cameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #cameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#cameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #cameraSpeed
Else
KeyY = 0
EndIf
EndIf
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(0, KeyX, 0, KeyY)
If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End
EndIf
RenderWorld()
FlipBuffers()
ForEver
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 4:58 pm
by IdeasVacuum
Advice from Samuel in another post:
Try using InitEngine3D(#PB_Engine3D_DebugLog). It should create a file named Ogre in your current directory.
You can open it with notepad or something similar.
If you get the file. Look at the sections with D3D9 and make sure there aren't any errors.
You can also post the Ogre file here and we can take a look at it for you.
Also what kind of GPU do you have? It's possible it has some compatiblity issues with DirectX9.0c.
http://www.purebasic.fr/english/viewtop ... =7&t=57478
Edit: It could be Windows Defender interrupting the process. Add everything PB to Defender's safe list (or whatever Anti-Virus you have).
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 5:19 pm
by mrw
until then try to run he code by going from the ide to compilers --> compiler options , then in the Library subsystem box write this word opengl . click ok then run your code
This made the code work! Nice! And that proves to me that something is not correct with DX9 since it works with OpenGL.
But I´m not comfortable with just installing DX9 on a Win10 machine. I´m pretty sure MS doesn´t recommend doing that. DX12 should be backwards compatible with DX9.
I have had similar DX issues in the past and sometimes its just missing a specific dll. I will need to do some research unless anyone know more exactly what I need to do.
Try using InitEngine3D(#PB_Engine3D_DebugLog). It should create a file named Ogre in your current directory.
I activated this and got an ogre.log. But nothing in the logs show any error I´m afraid. I should since the app crashes..
It seems to start D3D9 correctly there are no logged errors.
Re: Newbie 3D engine question
Posted: Wed Mar 09, 2016 6:09 pm
by Samuel
But I´m not comfortable with just installing DX9 on a Win10 machine. I´m pretty sure MS doesn´t recommend doing that. DX12 should be backwards compatible with DX9.
No need to worry, every DirectX version is completely independent of the other (there's no backwards compatibility). In order to properly run DX9 applications you need the required DLLs that belong to said DirectX version.
If you look in your windows system folders you can find lots of different versions of the DirectX Dlls.
Re: Newbie 3D engine question
Posted: Thu Mar 10, 2016 10:53 am
by Bananenfreak
IdeasVacuum wrote:In the code, you have everything with the ID of '0'. Make an Enumeration to ensure each item has a unique ID:
Sorry, but I have to correct you. You can use "0" as PB-ID for the camera, an entity, a light, a menu, a window,... . They must be different.
If I´m using "0" twice for an entity, it crashes or the old entity will be freed.
Enumeration are a good idea, but instead of one enumeration an Enumeration for each type of ID can be used. So one enumeration for cameras, one for entities, one for Windows,... .
What you are using is the PB-ID-System. PB creates intern an Array for all the real id's. You can get the real ID's by using the result of the function.
But I´m not comfortable with just installing DX9 on a Win10 machine. I´m pretty sure MS doesn´t recommend doing that.
As Samuel mentioned before, you have to install DX9, 10, 11 and 12, whenever you wanna use programs using one of These DirectX Systems.
Normally an installer installs the needed DirectX Version (for example game installer).
Back to your Loop:
Code: Select all
Repeat
Repeat
Event = WindowEvent()
Until Event = 0 Or #PB_Event_CloseWindow
ExamineKeyboard()
If Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End
EndIf
RenderWorld()
FlipBuffers()
ForEver
I would prefer something like that. With the usage of WindowEvent(), you'll have to work off all Events in the Queue before you do something else (Except CloseWindow).
Re: Newbie 3D engine question
Posted: Thu Mar 10, 2016 11:31 am
by mrw
Enumeration are a good idea, but instead of one enumeration an Enumeration for each type of ID can be used
I know how Enumeration and IDs work and currently I only use "0"s for everything. But for larger projects I agree with having several enumerations for each type.
Before PB I used BlitzBasic which have named variables as IDs which IMHO works better. But Blitz have its own 3D engine so everything is much easier to do than PB and OGRE. But Blitz is unfortunately not really usable these days due to other factors..
you have to install DX9, 10, 11 and 12, whenever you wanna use programs using one of These DirectX Systems
Not entirely true, since these are mostly backwards compatible by using emulation and it also depend on the gfx-drivers. Most often I don´t have to do anything. I can easily run most DX7 and DX9 apps on a freshly installed Win10. This was the first time I had to install DX9 for several years. But apparently on this machine(a laptop with dual gfxcards with different brands) PB needed a full install of DX9.
Back to your Loop:
Thanks for your input here. I will change my loop as you suggested.
Thanks for all your help with solving my problem!
//Andreas..
Re: Newbie 3D engine question
Posted: Thu Mar 10, 2016 11:56 am
by IdeasVacuum
I used BlitzBasic which have named variables as IDs which IMHO works better
There certainly are occasions when an int array variable is better (well named) and you can do that in PureBasic, no problem. My point about having '0' as an ID for everything is that it's more difficult to follow the code, which is not great when studying it yourself and even less attractive if you want help from the forum. '0' is used as an ID a lot in the Help pages, which in my view is less helpful, especially for people new to PB.
Re: Newbie 3D engine question
Posted: Thu Mar 10, 2016 12:32 pm
by Thade
This enumeration stuff and using numbers instead of Variables which hold the handles is useful for demos and very little projects.
It is some sort of PB typic
Thus, with all code examples, if you want to pick out some lines of code to use them in your own program, you have to change numbers or add your own enumerations.
But most people (if you are not a chess professional with a photographic mind) will never be able to write a Program with more than 10000 lines and always keep track of numbers or names which are enumerated - maybe one reason that so many great ideas don't end up in a finished App or Game.
Especially if you have also to keep track of 100s of Handles in Arrays ... sooner or later it ends in a big mess.
So instead of using a number I always use #PB_Any or short -1 and store the handles in variables with significant names or in arrays
As former Blitz user (many here are) it is quite easy to adapt.
The difference: in Blitz it is the only way to store handles - in PB you have at least 3 different options and you can select which you prefer.
Example: To convert Blitz Code let's say
Code: Select all
MyFriends=ReadFile("MyFriendsList.txt")
you use in PB:
Code: Select all
MyFriends=ReadFile(-1, "MyFriendsList.txt")
Re: Newbie 3D engine question
Posted: Thu Mar 10, 2016 12:45 pm
by mrw
So instead of using a number always use #PB_Any or short -1 and store the handles in variables with significant names or in arrays
Excellent idea to solve the enumeration craziness! I will adopt to your method as of now.
Now on to getting a grasp of OGREs peculiar stuff like Materials, Billboards and Scripts and all the rest.. Everything seems so much more complicated that it has to be.
My Old BlitzBrain has already started thinking of creating a commandset identical to Blitz 3D engine to make life easier.
But that´s for another forum thread I think
