Created
February 7, 2017 18:57
-
-
Save turbo/c172ef3558e25b884a6fc0e576ea874b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#define seconds * 1e3 | |
#define GLExt(a) a(wglGetProcAddress(#a)) | |
#define native(t) __declspec(dllimport) t __stdcall | |
// ## FRAMEWORK SETTINGS ## | |
//~ #define USEWIN // Use a window (not recommended) | |
#define MODERN_GLSL // One stop shader compiling | |
#define REUSE // Turn on aggressive register reuse (can save dozens of bytes) | |
#define RE_REG_POSITIVE edi // Annotates a "big positive value" (e.g. hDC) | |
// ######################## | |
// #### DEMO SETTINGS #### | |
#define XRES 1366 | |
#define YRES 768 | |
#define RUNTIME 15 seconds | |
// ######################## | |
// Compile: cl /c /GS- /O2 /Ob1 /Oi /Os /FAs blah.cpp | |
/* Link: crinkler.exe | |
/OUT:".\demo.exe" | |
opengl32.lib glu32.lib winmm.lib kernel32.lib user32.lib gdi32.lib | |
winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib | |
uuid.lib odbc32.lib odbccp32.lib msvcrt.lib libcmt.lib | |
/SUBSYSTEM:WINDOWS | |
/ENTRY:"entrypoint" | |
/CRINKLER | |
/HASHTRIES:8192 | |
/COMPMODE:SLOW | |
/ORDERTRIES:32000 | |
/TINYHEADER | |
/TINYIMPORT | |
/UNALIGNCODE | |
/REPORT:.\demo.html | |
/SATURATE | |
/UNSAFEIMPORT | |
/LIBPATH:"C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86" | |
/RANGE:opengl32 | |
.\blah.obj | |
*/ | |
extern "C" { | |
typedef void(__stdcall*glUseProgram)(int); | |
typedef int(__stdcall*glCreateProgram)(void); | |
typedef int(__stdcall*glCreateShader)(int); | |
typedef void(__stdcall*glLinkProgram)(int); | |
typedef void(__stdcall*glCompileShader)(int); | |
typedef void(__stdcall*glAttachShader)(int,int); | |
typedef void(__stdcall*glShaderSource)(unsigned shader, int count, const char** string, const int *length); | |
typedef int(__stdcall*glCreateShaderProgramv)(int, int, const char**); | |
native(void) glRects(short, short, short, short); | |
} | |
void entrypoint( void ) { | |
const static PIXELFORMATDESCRIPTOR pfd = {0,0,PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER}; | |
#ifdef USEWIN | |
const auto hDC = GetDC(CreateWindow("edit", 0, WS_POPUP|WS_VISIBLE|WS_MAXIMIZE, 0,0,0,0,0,0,0,0)); | |
ShowCursor( 0 ); | |
#else | |
const auto hDC = GetDC(nullptr); | |
#ifdef REUSE | |
__asm { | |
push RE_REG_POSITIVE; | |
push 0; | |
call SetCursorPos; | |
} | |
#else | |
SetCursorPos(0,YRES); | |
#endif | |
#endif | |
SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd); | |
wglMakeCurrent(hDC, wglCreateContext(hDC)); | |
#ifndef MODERN_GLSL | |
const auto p = GLExt(glCreateProgram)(); | |
const auto s = GLExt(glCreateShader)(0x8B30); | |
#endif | |
const auto starttime = GetTickCount(); | |
loop: | |
char pflog[1024]; | |
const auto elapsed = GetTickCount() - starttime; | |
wsprintf(pflog, "void main(void) {" | |
"float time = %d. / 1000.;" | |
"float t = time, p;" | |
"vec2 g = gl_FragCoord.xy, s = vec2(1366.,768.), u = (g+g-s)/s.y, ar = vec2(atan(u.x, u.y) * 3.18 + t*2., length(u)*3. + fract(t*.5)*4.);" | |
"p = floor(ar.y)/5.;" | |
"ar = abs(fract(ar)-.5);" | |
"gl_FragColor = mix(vec4(1,.3,0,1), vec4(.3,.2,.5,1), vec4(fract((p)))) * .1/dot(ar,ar);" | |
"gl_FragColor.a = 1.;" | |
"}", elapsed); | |
const char *blorg = pflog; | |
#ifdef MODERN_GLSL | |
GLExt(glUseProgram)(GLExt(glCreateShaderProgramv)(0x8B30, 1, &blorg)); | |
#else | |
GLExt(glShaderSource)(s, 1, &blorg, 0); | |
GLExt(glCompileShader)(s); | |
GLExt(glAttachShader)(p,s); | |
GLExt(glLinkProgram)(p); | |
GLExt(glUseProgram)(p); | |
#endif | |
#ifdef REUSE | |
__asm { | |
push RE_REG_POSITIVE; | |
push RE_REG_POSITIVE; | |
push -1; | |
push -1; | |
call glRects; | |
} | |
#else | |
glRects(-1,-1,1,1); | |
#endif | |
SwapBuffers(hDC); | |
if(GetAsyncKeyState(VK_ESCAPE) || elapsed > RUNTIME) goto graceful; | |
goto loop; | |
graceful: | |
ExitProcess( 0 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment