Guest User

Untitled

a guest
Apr 6th, 2012
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define WIN32_LEAN_AND_MEAN
  2. #include <windows.h>
  3.  
  4.  
  5. #include <gl\gl.h>
  6. #include "d:\\gl3.h"
  7. #pragma comment(lib, "opengl32.lib")
  8.  
  9.  
  10. const char* vs =
  11. "#version 330\n"
  12. "void main() {"
  13.       "gl_Position = vec4(gl_Vertex.xyz, 1.0);"
  14. "}";
  15.  
  16. const char* fs =
  17. "#version 330\n"
  18. "uniform float t;"
  19. "out vec4 f;"
  20. "void main() {"
  21.       "f = vec4(sin(t+gl_FragCoord.y/768.0) * cos(t+gl_FragCoord.x/1024.0), 0.0, 0.0, 1.0);"
  22. "}";
  23.  
  24.  
  25. int WINAPI WinMain(HINSTANCE h1, HINSTANCE h2, LPSTR cmd, int show)
  26. {
  27.     static PIXELFORMATDESCRIPTOR pfd = {0, 0, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0};
  28.     HDC hDC = GetDC(CreateWindowA("edit", 0, WS_CAPTION | WS_VISIBLE, 100, 100, 1024, 768, 0, 0, 0, 0));
  29.     SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);
  30.     wglMakeCurrent(hDC, wglCreateContext(hDC));
  31.  
  32.     ShowCursor(FALSE);
  33.  
  34.  
  35.     PFNGLCREATESHADERPROGRAMVPROC glCreateShaderProgramv = (PFNGLCREATESHADERPROGRAMVPROC)wglGetProcAddress("glCreateShaderProgramv");
  36.     PFNGLUSEPROGRAMSTAGESPROC glUseProgramStages = (PFNGLUSEPROGRAMSTAGESPROC)wglGetProcAddress("glUseProgramStages");
  37.     PFNGLGENPROGRAMPIPELINESPROC glGenProgramPipelines = (PFNGLGENPROGRAMPIPELINESPROC)wglGetProcAddress("glGenProgramPipelines");
  38.     PFNGLBINDPROGRAMPIPELINEPROC glBindProgramPipeline = (PFNGLBINDPROGRAMPIPELINEPROC)wglGetProcAddress("glBindProgramPipeline");
  39.     PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f = (PFNGLPROGRAMUNIFORM1FPROC)wglGetProcAddress("glProgramUniform1f");
  40.     PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation");
  41.  
  42.  
  43.     GLuint pipeline;
  44.     glGenProgramPipelines(1, &pipeline);
  45.     glBindProgramPipeline(pipeline);
  46.  
  47.     GLuint pvs = glCreateShaderProgramv(GL_VERTEX_SHADER, 1, &vs);
  48.     glUseProgramStages(pipeline, GL_VERTEX_SHADER_BIT, pvs);
  49.  
  50.     GLuint pfs = glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1, &fs);
  51.     glUseProgramStages(pipeline, GL_FRAGMENT_SHADER_BIT, pfs);
  52.  
  53.     GLuint loc = glGetUniformLocation(pfs, "t");
  54.  
  55.  
  56.     DWORD start = GetTickCount();
  57.     do
  58.     {
  59.         glBindProgramPipeline(pipeline);
  60.  
  61.         glProgramUniform1f(pfs, loc, (GetTickCount()-start) * 0.001f);
  62.  
  63.         glRecti(-1, -1, 1, 1);
  64.         SwapBuffers(hDC);
  65.  
  66.     } while(!GetAsyncKeyState(VK_ESCAPE));
  67.  
  68.     ExitProcess(0);
  69.     //return 0;
  70. }
RAW Paste Data