Skip to content

Instantly share code, notes, and snippets.

@turbo
Created February 7, 2017 17:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save turbo/46f5c2a8c4205cb199a200bae60a0eaa to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <GL/gl.h>
#define XRES 1366
#define YRES 768
//~ #define USEWIN
#define GLExt(a) a(wglGetProcAddress(#a))
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, char** string, const int *length);
}
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);
SetCursorPos(0,YRES);
#endif
SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);
wglMakeCurrent(hDC, wglCreateContext(hDC));
const auto p = GLExt(glCreateProgram)();
const auto s = GLExt(glCreateShader)(0x8B30);
const auto starttime = GetTickCount();
do {
char *pflog;
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.;"
"}", GetTickCount() - starttime);
char *blorg = pflog;
GLExt(glShaderSource)(s, 1, &blorg, 0);
GLExt(glCompileShader)(s);
GLExt(glAttachShader)(p,s);
GLExt(glLinkProgram)(p);
GLExt(glUseProgram)(p);
glRects(-1,-1,1,1);
SwapBuffers(hDC);
}while ( !GetAsyncKeyState(VK_ESCAPE) );
ExitProcess( 0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment