Skip to main content

OpenGL in a Workspace

On some modern Linux systems, Croquet does not work anymore because OpenGL failes to initialize. Now, I originally wrote that code, and it worked fine for years. So it can't possibly be buggy, right? Jens Lincke of impara tracked it down to the "Composite" extension that is enabled by default nowadays. With Composite disabled, it works, enable it, and it does not.

So I turned to NVIDIA for help, thinking their driver might be buggy. Had to give them an easy way to reproduce the problem, this is the snippet I came up with:
| ogl green |
ogl := OpenGL newIn: (0@0 extent: 100@100).
green := 1.
[[
ogl glClearColor(0, green, 0, 1).
ogl glClear(16r4000).
ogl swapBuffers.
Sensor waitClickButton.
green := 1 - green.
] repeat] ensure: [ogl destroy]
Beauty, eh? ;-) I guess nobody has done this in a workspace for a long time. Stop it with Alt-.

Anyway, NVIDIA could reproduce the problem, and found our bug:
[...] the app is trying to create a depth 24 child window of a depth 32 parent and the app specifies neither a border pixel nor a border pixmap.
Doh! I forgot to specify the border! We were just lucky that this did not happen before. Jens and y.t. made a patch, should be in the next VM. And big thanks to NVIDIA developer support!

Comments

Anonymous said…
...
ogl glClearColor(0, green, 0, 1).
ogl glClear(16r4000).
...

I'm sure I don't get that. Most of the syntax here in the snippet looks like Smalltalk syntax. But then there's this mixed in? It's amazing, because immediately I have no idea what the glClearColor arguments mean. Or the glClear. Is this one of these "on beyond Smalltalk" things I keep hearing some of the spring-from-Squeak projects talking about?
Vanessa said…
This is called "positional arguments", Andreas allowed this syntax in Croquet. The actual selector in this case is #'glClearColor()/4'.

The reason is that this is the syntax that is used in any piece of OpenGL documentation. You can alternatively write

ogl glClearColor: 0 with: green with: 0 with: 1

which I find even less readable. These are FFI methods, so they directly call out to the corresponding C function. Personally I like this, it reminds me that this is a C call rather than a Smalltalk method.

A "cool" hack is to use cascades, which allows you to copy C code almost verbatim:

ogl
glClearColor(0, green, 0, 1);
glClear(16r4000);
yourself.
Anonymous said…
I'm looking for a way to do this cleanly within a Tweak project, but I can't seem to find the right offset(s) to put the OGL area in the project window. Any ideas?
Vanessa said…
There is no official way to convert Tweak coordinates to absolute Squeak Display coordinates. Here is a hack involving Sensor.

Besides, you might find this useful: COpenGLPlayer
Anonymous said…
Thank you! The Sensor hack is what I was looking for. I actually have the COpenGlPlayer code already, although when I tried to backtrack to find where I had gotten it, I looked everywhere except the Tweak list. Thanks again. daf

Popular posts from this blog

Frontend-only Multi-Player. Unlimited Bandwidth. Or: What is Croquet.io, really?

A multi-player web app needs a backend, right? What if I told you, it doesn’t? Read on for how Croquet gets rid of servers running your multiplayer code. No, really . Instantaneous Shared Experiences  is how we describe Croquet on our website. And while that excellently describes What Croquet does, as Croquet's Chief Architect, I wanted to share a bit about How we do that. So I wrote a Twitter thread . Here it is in blog form, slightly extended. Click the animation above if it does not play automatically Croquet lets you build completely client-side multi-user web apps. Read that again. Client-side. Multi-user. No I’m not kidding. I built it, I know it works. 😁  Croquet apps run completely client-side: are hosted as a static web site no server-side code needed no networking code needed  Croquet is literally virtualizing the server: Instead of running code on a server (or in a serverless function) we run it as a virtual machine (VM) on each client.  Croquet ca...

Deconstructing Floats: frexp() and ldexp() in JavaScript

While working on my  SqueakJS VM, it became necessary to deconstruct floating point numbers into their mantissa and exponent parts, and assembling them again. Peeking into the C sources of the regular VM, I saw they use the  frexp ()   and ldexp () functions found in the standard C math library. Unfortunately, JavaScript does not provide these two functions. But surely there must have been someone who needed these before me, right? Sure enough, a Google search came up with a few implementations. However, an hour later I was convinced none of them actually are fully equivalent to the C functions. They were imprecise, that is, deconstructing a float using frexp() and reconstructing it with ldexp() did not result in the original value. But that is the basic use case: for all float values, if [ mantissa , exponent ] = frexp (value) then value = ldexp ( mantissa , exponent ) even if the value is subnormal . None of the implementations (even the complex ones) re...

Smalltalk Bindings for Minecraft Pi

The Raspberry Pi is a cute little computer. Quite cheap at $35, you plug in USB keyboard+mouse and a TV as monitor. And it is surprisingly capable, even for running 3D games. One particularly interesting game is Minecraft: Pi Edition . As in other Minecraft versions, the main goal is to create a world. But unlike other versions, you can not only use the tools provided by the game, you can make your own tools! That's because it comes with a programming interface. The Minecaft world is made of little cubes, and you normally place or remove these blocks by hand, one after another. This is fun, but for larger structures also quite cumbersome. For example, this rainbow here might take a long time to construct manually: But I did not make the rainbow by hand. I programmed it, using the Smalltalk programming language. It's just these dozen lines of code in the Squeak programming environment: Squeak is already installed on the Raspberry Pi, because Scratch was made in Squea...