Feeling the Squeeze : OpenGL in 1kb

Jan 29

Written by:
1/29/2014 9:50 AM  RssIcon

With the rapidly growing power in the PC market hard-disk space, ram and processing power seems to be increasing constantly. But every now and again there is a squeeze for optimisations to try and get a game under that 15GB target, or less than 8GB ram usage, and whilst that is a challenge it doesn't compare to that of the Demoscene.  A subculture that thrives in the tight requirements of a spectrum Rom or the ram restrictions of a C64, pushing to maximise the capabilities of their demos within the limitations of the hardware. For those eager to push the boundaries competitions still run such as :

Scene.org Awards is a way of honouring the previous year of demoscene releases in a more formal setting, and disregarding their ranks in other competitions.

This is a competition about JavaScript scripts no larger than 1k. Starting out as a joke, the first version ended with a serious amount of submissions, prizes and quality.

Over the past 2 days I have been looking into the feasibility of getting OpenGL within the tight restrictions of 1k, and as demonstrated by the image above, this seems fairly achievable. The 1k program (1022 bytes) contains enough code to create a window handle, OpenGL context and draw a changing section of the Mandelbrot set with two whole bytes to spare, but how is this achievable? 

There are a number of things that can be done to reduce the output exe size, with the first most obvious being to take advantage of size saving options of the compiler. Instructing the compiler that you need as small an exe as possible will cause it to optimise code where possible to reduce in size (no in-lines ect). This alone however wont get you down to a handful of kilobytes, for this you will need an advanced linker. 

A linker takes the object code produced by the compiler and shoehorns it all into the final EXE package. Along with your own code a large number of routines are also added from the C runtime with additional code from the STL you may need. For this project I used a free linker called Crinkler developed by Rune L. H. Stubbe (Mentor/TBC) and Aske Simon Christensen (Blueberry/Loonies). 

As a linker that has been designed around the sole purpose of reducing exe size for Demo’s this is where the majority of your size reduction will be generated. The linker builds a small code compressor into your exe which allows a greater amount of code to be packaged into the same space. Combining Crinker with some code level optimisations (reducing the use of differing constants, strings etc) you’ll be well on your way to fitting everything into your demo.

 For this project i’m sure there is still much more that could be squeezed in, if you are interested in the source (including an optimised visual studio project) please checkout the GitHub links below: 

Get the source: HERE (f6cce7e931cae6a9230954dc175ff42d05a75277)

Your name:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
Lets hope @torfiFrans doesn't get me in trouble with HR if they find the book on my desk and flick through to the Navitas :P #tweetfleet about a month ago . Reply . Retweet . Favorite
Grabbed my copy of the Frigates of Eve book, you should too #tweetfleet :) https://t.co/cwai7R5bli about a month ago . Reply . Retweet . Favorite
Trying to setup an #Ark server and no matter what i do we cant gather stones or berries, any idea on how to fix guys @survivetheark ? about a month ago . Reply . Retweet . Favorite
Mate sent some Pig of Doom scratching's from @SnafflingPigCo, My face hurts as i've been hammering in the tasty morishing fiery pain snacks. about a month ago . Reply . Retweet . Favorite
RT @astroneergame: Paul Pepera, 1986-2017. Co-founder, artist, and friend of System Era. RIP. https://t.co/Zgm954YfHK about a month ago . Reply . Retweet . Favorite