Created
August 29, 2014 09:29
-
-
Save emoon/78d62820c44a808c730f 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
#define WIN32_LEAN_AND_MEAN | |
#define WIN32_EXTRA_LEAN | |
#include <windows.h> | |
#include <mmsystem.h> | |
#include <GL/gl.h> | |
#include "glext.h" | |
#define XRES 1280 | |
#define YRES 720 | |
// fragment shader | |
static const char *fragmentShader = | |
"float t=gl_Color.x*100;" | |
"void main(){" | |
"vec2 uv=gl_FragCoord.xy/500;" | |
"float c=sin(t+uv.x*3)+sin(t+uv.y*5)+sin((t+uv.x+uv.y)*4);" | |
"gl_FragColor=vec4(vec3(sin(c),sqrt(c),cos(c)),1);" | |
"}"; | |
// pixel format descriptor | |
static PIXELFORMATDESCRIPTOR pfd = { 0, 0, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER }; | |
// screen settings (uncomment for proper screen control) | |
//static DEVMODE screenSettings = { { 0 }, 0, 0, sizeof(DEVMODE), 0, | |
//DM_PELSWIDTH | DM_PELSHEIGHT, | |
//{ 0 }, 0, 0, 0, 0, 0, { 0 }, 0, 0, XRES, YRES}; | |
//---------------------------------------------------------------------------- | |
void main() { | |
// full screen (uncomment for proper screen control) | |
//ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN); | |
// create windows | |
const HDC hDC = GetDC(CreateWindowA((LPCSTR)0xC018, 0, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, 0)); | |
// init opengl | |
SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd); | |
wglMakeCurrent(hDC, wglCreateContext(hDC)); | |
ShowCursor(NULL); | |
// midi | |
static HMIDIOUT out; | |
midiOutOpen(&out, 0, 0, 0, CALLBACK_NULL); // open MIDI output | |
midiOutShortMsg(out, 0x7eC0); // change instrument | |
midiOutShortMsg(out, 0x7f2490); // play a note | |
// create shader | |
const int ps = ((PFNGLCREATESHADERPROGRAMVPROC)wglGetProcAddress("glCreateShaderProgramv"))(GL_FRAGMENT_SHADER, 1, &fragmentShader); | |
((PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram"))(ps); | |
const int startTime = timeGetTime(); // get starting time | |
int time; | |
do { | |
time = (timeGetTime() - startTime); // calculate current time | |
glColor3us (time, 0, 0); // pass time to shader through gl_Color | |
glRects(-1,-1,1,1); // draw full screen rectangle | |
SwapBuffers(hDC); // swap buffer call to refresh screen | |
PeekMessageA(0, 0, 0, 0, PM_REMOVE); // Remove error message to prevent busy cursor | |
} while (time < 30000 && !GetAsyncKeyState(VK_ESCAPE)); // exit after time or escape key press | |
ExitProcess(NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment