Use Cases

Daniel Limberger edited this page Jan 25, 2014 · 13 revisions

Texture Compression

You can use glraw to compress your textures and save memory on your graphics card. If you haven't heard of texture compression yet, this Wikipedia article should be a good starting point. Basically you lose some visual quality in favor of less used bandwidth and memory.


uncompressed compressed
Result [[images/uncompressed_cat.png alt=uncompressed cat]] show full size capture
Detail [[images/uncompressed_cat_detail.png alt=uncompressed cat detail]]
Size 1024px x 1024px, 4.00 MiB 1024px x 1024px, 0.50 MiB

For these images, the following commands where used:

  • Uncompressed: >glraw-cmd -f GL_RGB -t GL_UNSIGNED_BYTE image.png
  • Compressed: >glraw-cmd --compressed-format GL_COMPRESSED_RGB_S3TC_DXT1_EXT image.png

Note: When you want to load a compressed image, use glCompressedTexImage2D instead of glTexImage2D.

Image Processing

You can pass a fragment shader to glraw, which is executed within a temporary OpenGL context. The shader gets executed when all requested image modifiers were applied, just before the image is written into its target file.

Example boxblur

With the following command, the input image can be horizontally blurred: glraw-cmd --shader boxblur.frag --uniform boxR=vec2(32,0) image.png

Source of boxblur.frag:

#version 150

uniform sampler2D src;
uniform vec2 boxR = vec2(16, 16);

in vec2 v_uv;
out vec4 dst;

void main()
	ivec2 r = ivec2(boxR);
	float w = 1.0 / ((r.x * 2.0 + 1) * (r.y * 2.0 + 1));

	vec2 sizei = vec2(1.0) / vec2(textureSize(src, 0));

    vec4 sum = vec4(0.0);

    for (int x = -r.x; x <= r.x; ++x) 
        for (int y = -r.y; y <= r.y; ++y) 
            sum += texture(src, v_uv + vec2(x, y) * sizei);

    dst = sum * w;

Note: The input image is named src and the default value of boxR is overwritten by the command line option uniform --uniform boxR=vec2(32, 0), causing a horizontal blur.

Example grayscale

Command: glraw-cmd --shader grayscale.frag image.png


| cat blurred | cat grayscaled | | ------------ | ------------ |