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.

praxis-textshader1

Version: 7d64ce7

Working directory: cauldron

praxis-textshader2

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

praxis-textshader3

praxis-textshader4

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.

loadBuffer("textshader.lua")

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:

edSetVisLines(120)

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.

praxis-textshader5

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

praxis-textshader6

Here is a video demonstrating these steps:

And a shorter video because why not:

 

Well, that was fun.