naqvis / webview

Crystal bindings to Webview library
MIT License
93 stars 8 forks source link

WebKit2 enable webgl #29

Closed gummybears closed 1 year ago

gummybears commented 1 year ago

Trying out your webview shard with the following code but alas webgl is not enabled by default. I see there is a setting in WebKit to enable webgl but not in lib.cr.

require "webview"

html = <<-HTML
<!DOCTYPE html>
<html>
  <canvas id = "mycanvas" width = "600" height = "200"></canvas>
  <div id="textview">
    <p>Shader code</p>
  </div>

  <script>
    var canvas = document.getElementById('mycanvas');
    var gl = canvas.getContext('experimental-webgl');
    gl.clearColor(1,0,0,1);
    gl.clear(gl.COLOR_BUFFER_BIT);

  </script>
</html>
HTML

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebView")
wv.html = html
wv.run
wv.destroy
naqvis commented 1 year ago

Not sure I understand the problem here.

WebGL is enabled by default and you don't need to toggle anything. Running your provided code does produce the required result.

You can try running examples from threejs like:

require "webview"

wv = Webview.window(640, 480, Webview::SizeHints::NONE, "Hello WebGL", "https://threejs.org/examples/#webgl_animation_skinning_blending")
wv.run
wv.destroy

image

gummybears commented 1 year ago

Are you running this on a Apple computer? I am running this on a Asus laptop with Linux Mint 21 installed. The HTML runs in my browser and displays a red rectangle, running the code I gave gives a black rectangle.

I have libwebkit2gtk-4.0-dev installed. May I ask which version you are using?

Thanks

naqvis commented 1 year ago

Are you running this on a Apple computer?

Yes, above screenshot was showing this running on Apple Silicon. And I've tested same demo on Fedora running webkit2gtk4.0 with same results.

I believe its something related to how your linux box is configured. try opening https://whatsmybrowser.org and see what information you see.

gummybears commented 1 year ago

Thanks for your reply, good to know you are able to run the code on Fedora with webkit2gtk4.0. I will post the browser info later.

gummybears commented 1 year ago

browser

gummybears commented 1 year ago

SOLVED

I needed to upgrade crystal to the latest version, that fixed the problem, thanks for your help.