Ooops
October 24, 2021, 23:39:49

Author Topic: OpenB3D online, combined with My-Basic interpreter  (Read 1010 times)

Offline angros47

  • Jr. Member
  • **
  • Posts: 74
OpenB3D online, combined with My-Basic interpreter
« on: July 06, 2021, 00:12:38 »
Want to try developing a small program in OpenB3D, without having to install/configure/compile anything?
It is now possible to use OpenB3D from a basic interpreter embedded in a web page

https://openb3d-online.sourceforge.io/

Offline markcwm

  • Hero Member
  • *****
  • Posts: 508
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #1 on: July 06, 2021, 12:11:06 »
Wow! Amazing. Works well. Had a quick play, it was fun.

How would you do a framerate limited main loop? Could it load textures?

Thanks.

Offline angros47

  • Jr. Member
  • **
  • Posts: 74
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #2 on: July 06, 2021, 19:00:35 »
Thank you!

About your questions:
1) It is possible to have a framerate limited main loop, in a way not too different from classic Blitz3D: the loop is defined with the commands do.... until (there is no "loop" keyword, in My-Basic). The loop must include somewhere inside it the command Flip(), that will take care to call the command emscripten_sleep(1). The interpreter is compiled with the ASYNCIFY option, so closed loops are allowed, no need to use time scheduled events.
Just remember that if you forget the command Flip() in the loop, the web page might hang, since the script would not give back control. Also, commands KeyHit and GetKey are implemented, and keyboard input is evaluated in the time when Flip() is called.
I considered using a separate Sleep command, instead of using the Flip one (that would have allowed me to use a parameter for it, to decide the framerate), but I preferred to keep the simplest syntax, closer to original Blitz3D

2) About loading textures (or also terrains, or 3d models): in theory, it would be possible (the code for it is implemented). Unfortunately, the files should be embedded with the interpreter itself, and at the moment no external file is embedded (I could add some free generic textures, but this would increase the size of the data to download, slowing down page loading). There is no way to use a texture file stored on your local computer, due to the default security settings of most browsers: in fact, giving a webapp access to local files would allow it to potentially read your private documents and share them online, and since a webapp can be started without user's consent, this can't be allowed.

Offline markcwm

  • Hero Member
  • *****
  • Posts: 508
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #3 on: July 07, 2021, 22:06:27 »
Thanks for the reply Angros. Yes, this has great potential but still needs a lot of work, for example KeyDown needs added.

I think this could work well if you ported some of the Blitz3d command reference examples so users could just go and tweak it to test things.

Maybe textures could be scaled down to minimize filesize, but it would only be possible if they were loaded as needed by each example program. I find the framerate too fast on my browser and have no way to set it, I would rather have the Sleep function than not be able to set it at all, the alternative would be to use: time=CreateTimer(60) and WaitTimer(time).

Also I found a bug, when I press Spacebar with lighting on the cube vanishes.

Offline angros47

  • Jr. Member
  • **
  • Posts: 74
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #4 on: July 08, 2021, 01:00:00 »
I have strange issues with lighting (it works at the first execution, but then I need to reload the page)

The changes you mention should not be too difficult to implement. Perhaps would you like if I published the source code?

Offline markcwm

  • Hero Member
  • *****
  • Posts: 508
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #5 on: July 08, 2021, 22:55:44 »
Could it be since Opengl-ES 2 needs shaders for lighting see here?

I think you would be better to keep the source as I'm not familiar with Opengl-ES so I can't see how I could help much.

Offline angros47

  • Jr. Member
  • **
  • Posts: 74
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #6 on: July 09, 2021, 12:13:35 »
In fact that's how lights are implemented in OpenB3D for web (check the file shaders.cpp). There are different shaders, depending on how many lights are implemented. The issue is that the right shader must be enabled in the right moment, and when the program is restarted, I guess they are not reset correctly. Still, you manage do render the meshes with lights (until you press space, at least), don't you?

Offline markcwm

  • Hero Member
  • *****
  • Posts: 508
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #7 on: July 10, 2021, 01:09:49 »
OK, yes I manage to render the mesh with light (I only tested one light) on the first run, it seems not just Space breaks it though, all I need to do is edit the Input window or even just click Run again and the screen goes blank.

Offline angros47

  • Jr. Member
  • **
  • Posts: 74
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #8 on: July 10, 2021, 18:40:32 »
I suspect that space will just trigger "run" another time (if the last thing you clicked was the "run" button).
Anyway, I don't know yet what is wrong, but it should be something in the reset code. Surely it is not something in the shader, otherwise it wouldn't work at first attempt, either.

Offline angros47

  • Jr. Member
  • **
  • Posts: 74
Re: OpenB3D online, combined with My-Basic interpreter
« Reply #9 on: October 03, 2021, 17:48:41 »
Since I forgot to upload the source codes, I fixed that now:

https://sourceforge.net/projects/openb3d-online/files/

The only "original" file is OB3D.cpp, that builds the interface between My-Basic and OpenB3D. Source code of OpenB3D is not included, the file OpenB3D.o can be built from last version of OpenB3D source code using "make web"

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal