[fpc-pascal] pas2js Webgl unit committed

Ryan Joseph ryan at thealchemistguild.com
Wed May 9 10:42:41 CEST 2018



> On May 9, 2018, at 1:46 PM, Ryan Joseph <ryan at thealchemistguild.com> 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




More information about the fpc-pascal mailing list