A text editor in a shader

The text shader is now usable as a text editor, complete with the highlight blocks for selection and Lua do/end blocks.


Version: 7d64ce7

Working directory: cauldron


Hitting F5 and F6 renders the game of life shaders underneath the text editor:



Call disableStdMouseCam() and enableStdMouseCam() to allow you to switch between moving the camera and interacting with the cellular automata shaders. (Reminder: Ctrl-Enter executes the current line or do/end block)

So now there is a shader based text editor in praxis. This means no more massive performance penalties when I want to render text in praxis.

It runs quite well on modest hardware too. It runs very well on a HP Stream 11 laptop (running Linux Mint 17), which I run praxis on regularly.

The text shader in the previous post was rendering to an FBO. In this version, I’ve made the text shader draw directly to the quad. So far, it looks like I can render as much text as I like with this technique with no noticeable performance hit (apart from the GPU possibly getting hot). The source file textshader.lua initially sets the visible area to 40 lines and 120 columns. That is already quite nice, but lets try pushing it a bit.

With praxis running, load a file into the editor, a file with at least a few screenfulls of text.


Then in the file textshader.lua, change the line that sets the number of visible lines. Around line 281, increase the number of visible lines to 120 and save:


If you press F7 now, those visible lines are written to the “string texture”, but they aren’t appearing yet because the shader variable iResolution.y (the starting point used in the fragment shader function FragCoordToCharPixel_Plain) is too low. So increase that around line 226 to 1500 (doesn’t have to be a power of 2):

glUniformf(u.resolution, 512, 1500)

Then you also need to change the fragment coordinate scaling multiplier in textshader-fragment.glsl so it maps to the quad properly. The quad is 100×100, so for 1500 “pixels”, we need to scale by 15.0. Around line 148 in textshader-fragment.glsl, make this change:

mainImage(gl_FragColor, V.xz * 15.0 )

Save the files you changed if you haven’t yet, then press F7.


120 visible lines. No problem. Zoom in, move around, its all there:


Here is a video demonstrating these steps:

And a shorter video because why not:


Well, that was fun.


2 thoughts on “A text editor in a shader

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s