pas2js Webgl unit committed

classic Classic list List threaded Threaded
50 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Michael Van Canneyt


On Wed, 9 May 2018, Ryan Joseph wrote:

>
>
>> On May 9, 2018, at 8:41 AM, Ryan Joseph <[hidden email]> wrote:
>>
>> Ok it finally worked.
>
> Making progress but the wiki is incomplete I think. I figured out how to add the rtl with -Fu but I’m getting an error. What’s wrong with that name? Can you show an example of a working command line?
>
> ./pas2js -Jc -Jirtl.js -Tbrowser -Fu/Developer/pas2js/packages/rtl /Users/ryanjoseph/Downloads/hello.pas

The above should be fine. It may be easier to use a config file, though.

> Fatal: Compilation aborted
> invalid custom JS file name "rtl.js"

Where is the rtl.js file ? is it in /Developer/pas2js/packages/rtl ? it
should be in one of the directories specified with -Fu.

my .pas2js.cfg config file contains the following:
-Fu/home/michael/projects/pas2js/packages/rtl
-Fu/home/michael/projects/pas2js/packages/*

And I have symlinked rtl.js (available in compiler/utils/pas2js/dist/)
in directory /home/michael/projects/pas2js/packages/rtl, so the compiler
will always find it.


Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Mattias Gaertner
In reply to this post by Ryan Joseph
On Wed, 9 May 2018 09:03:29 +0700
Ryan Joseph <[hidden email]> wrote:

> > On May 9, 2018, at 8:41 AM, Ryan Joseph <[hidden email]> wrote:
> >
> > Ok it finally worked.  
>
> Making progress but the wiki is incomplete I think. I figured out how to add the rtl with -Fu but I’m getting an error. What’s wrong with that name? Can you show an example of a working command line?
>
> ./pas2js -Jc -Jirtl.js -Tbrowser -Fu/Developer/pas2js/packages/rtl /Users/ryanjoseph/Downloads/hello.pas
> Fatal: Compilation aborted
> invalid custom JS file name "rtl.js"

It means file not found. I will change the error message.

The -Ji option searches in the unit search path. In the svn the rtl.js
is only in "compiler/utils/pas2js/dist/rtl.js". So you need to add a
-Fu.
In the release it is in "packages/rtl/rtl.js" as well, so it can be
found without an extra -Fu.


Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Ryan Joseph
In reply to this post by Michael Van Canneyt


> On May 9, 2018, at 1:20 PM, Michael Van Canneyt <[hidden email]> wrote:
>
> Where is the rtl.js file ? is it in /Developer/pas2js/packages/rtl ? it
> should be in one of the directories specified with -Fu.

I misunderstood the wiki I guess. I thought that command was supposed to generate the file for you. It’s just a little auxiliary file we need with every .html file generated right?

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Michael Van Canneyt


On Wed, 9 May 2018, Ryan Joseph wrote:

>
>
>> On May 9, 2018, at 1:20 PM, Michael Van Canneyt <[hidden email]> wrote:
>>
>> Where is the rtl.js file ? is it in /Developer/pas2js/packages/rtl ? it
>> should be in one of the directories specified with -Fu.
>
> I misunderstood the wiki I guess. I thought that command was supposed to generate the file for you. It’s just a little auxiliary file we need with every .html file generated right?

Yes. It contains some basic functionality that the compiler relies on.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Ryan Joseph
In reply to this post by Mattias Gaertner


> On May 9, 2018, at 1:25 PM, Mattias Gaertner <[hidden email]> wrote:
>
> The -Ji option searches in the unit search path. In the svn the rtl.js
> is only in "compiler/utils/pas2js/dist/rtl.js". So you need to add a
> -Fu.
> In the release it is in "packages/rtl/rtl.js" as well, so it can be
> found without an extra -Fu.

Ok got it working now finally. Now I need to learn how to do anything at all besides writeln. :)

1) can the script output the required .html file also? I don’t see the reason do this manually each time
2) 1200 lines for a 1 line hello world program? Seems a little steep so maybe I did something wrong?

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Michael Van Canneyt


On Wed, 9 May 2018, Ryan Joseph wrote:

>
>
>> On May 9, 2018, at 1:25 PM, Mattias Gaertner <[hidden email]> wrote:
>>
>> The -Ji option searches in the unit search path. In the svn the rtl.js
>> is only in "compiler/utils/pas2js/dist/rtl.js". So you need to add a
>> -Fu.
>> In the release it is in "packages/rtl/rtl.js" as well, so it can be
>> found without an extra -Fu.
>
> Ok got it working now finally. Now I need to learn how to do anything at all besides writeln. :)
>
> 1) can the script output the required .html file also? I don’t see the reason do this manually each time
No. The IDE does this for you, ij you install the pas2js_dsgn package.

The compiler just compiles. No more, no less.

> 2) 1200 lines for a 1 line hello world program? Seems a little steep so maybe I did something wrong?

See the FAQ section in the WIKI :)

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Ryan Joseph
In reply to this post by Ryan Joseph


> On May 9, 2018, at 1:46 PM, Ryan Joseph <[hidden email]> wrote:
>
> Ok got it working now finally. Now I need to learn how to do anything at all besides writeln. :)

Finally got a context open and working. Next things:

1) what’s the best way to handle long strings? in JS they’ll loading text from divs but i’d rather do that from a file since long strings in Pascal aren’t great. How does that work?

2) what’s the deal with arrays? I saw there is array of xxx syntax for dynamic arrays. Can we use static arrays also and do they work with new Float32Array(xxx)? I guess all JS arrays are the same and I can pass them like

3) how does the syntax “new Float32Array()” translate to Pascal? There’s no generic class allocator syntax in Pascal so what do we use?

4) in functions from webgl that return strings the type is “JSValue”. How do those work with “string” in Pascal now? Maybe just typecast to string?

====

uses BrowserConsole, Web, WebGL;

const
        kWidth = 100;
        kHeight = 100;
var
  canvas: TJSHTMLCanvasElement;
  gl: TJSWebGLRenderingContext;
begin

  canvas := TJSHTMLCanvasElement(document.createElement('canvas'));
  canvas.width := kWidth;
  canvas.height := kHeight;
        document.body.appendChild(canvas);

        gl := TJSWebGLRenderingContext(canvas.getContext('webgl'));
        if gl = nil then
                begin
                        writeln('failed to load webgl!');
                        exit;
                end;
        gl.clearColor(1, 0, 0, 1);
        gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
        gl.clear(gl.COLOR_BUFFER_BIT);
end.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Mattias Gaertner
On Wed, 9 May 2018 15:42:41 +0700
Ryan Joseph <[hidden email]> wrote:

>[...] > On May 9, 2018, at 1:46 PM, Ryan Joseph <[hidden email]> wrote:
> >
> > Ok got it working now finally. Now I need to learn how to do anything at all besides writeln. :)  
>
> Finally got a context open and working. Next things:

These questions are better asked on the pas2js mailing list:
http://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Michael Van Canneyt
In reply to this post by Ryan Joseph


On Wed, 9 May 2018, Ryan Joseph wrote:

>
>
>> On May 9, 2018, at 1:46 PM, Ryan Joseph <[hidden email]> wrote:
>>
>> Ok got it working now finally. Now I need to learn how to do anything at all besides writeln. :)
>
> Finally got a context open and working. Next things:
>
> 1) what’s the best way to handle long strings? in JS they’ll loading text from divs but i’d rather do that from a file since long strings in Pascal aren’t great. How does that work?

What do you mean by this ? "long strings in pascal aren't great".

What do you want to achieve ?

>
> 2) what’s the deal with arrays?
> I saw there is array of xxx syntax for dynamic arrays. Can we use static arrays also and do they work with new Float32Array(xxx)? I guess all JS arrays are the same and I can pass them like

You can use static arrays.

>
> 3) how does the syntax “new Float32Array()” translate to Pascal? There’s no generic class allocator syntax in Pascal so what do we use?

var
   a : TJSFloat32Array;

begin
   a:=TJSFloat32Array(TJSFloat32Array.From(something))
end;

I will see about introducing some things to make this easier.

>
> 4) in functions from webgl that return strings the type is “JSValue”. How do those work with “string” in Pascal now? Maybe just typecast to string?

Yes. Note that if they return JSValue, it means that the return type can
also be different from string.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: pas2js Webgl unit committed

Joost van der Sluis
In reply to this post by Ryan Joseph
Op 09-05-18 om 03:41 schreef Ryan Joseph:
> Ok it finally worked. The fpmake.pp file athttps://svn.freepascal.org/svn/projects/pas2js/trunk  was totally different than the one in the compiler sources.
>
> May I suggest you put these instructions at the top level of the wiki? It’s pretty easy but I wasn’t able to build it for literally days and could have easily given up.
>
> Something like that would have been really helpful:

It took more time then I thought, but finally got it working.

I've added a fppkg-repository for fpc-version 3.0.4 to fpc.cnoc.nl. And
added a recent version of utils-pas2js. (Which is the actual
package-name of pas2js)

In principle this means that you can install pas2js with the following
command-line:

fppkg install utils-pas2js

Then the pas2js binary will be in ~/.fppkg/bin/pas2js.

There are a few buts, though:
- You need a valid fppkg-configuration
- You need to set in your fppkg.cfg:
     RemoteMirrors=http://fpc.cnoc.nl/repo/testing/mirrors.xml
- Fppkg wil not automatically update packages, but you need
   updated versions of fcl-web, fcl-js and fcl-passrc. This means
   you have to update them manually:
     fppkg install fcl-js fcl-passrc fcl-web
- Fppkg version 3.0.4 has an irritating bug that it can get into an
   infinite loop. When this happens, kill it (ctrl-c) and run
     fppkg fixbroken
   until it does not happen anymore.

I've only tested it on my own system, so there might be issues but just
ask, see if I can help.

Regards,

Joost

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
123