Advertisement
Guest User

flow2, *nix dnload.py port

a guest
Sep 18th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. // Port of flow2 to be compiled and linked by dnload.py, platform-independent.
  2. // Both original comments and those from Amand Tihon copied verbatim.
  3.  
  4. // Linux x86_64 port of flow2, to be linked with the bold linker.
  5. // Ported by Amand Tihon (alrj).
  6. // Original comments in flow2 source code copied verbatim
  7.  
  8. // Chris Thornborrow (auld/sek/taj/copabars)
  9. // If you use this code please credit...blahblah
  10. // Example OGL + shaders in 1k
  11. // Requires crinkler - magnificent tool
  12. // VS2005 modifications by benny!weltenkonstrukteur.de from dbf
  13. //    Greets!
  14. // NOTE: DX will beat this no problem at all due to OpenGL forced
  15. // to import shader calls as variables..nontheless we dont need
  16. // d3dxblahblah to be loaded on users machine.
  17.  
  18. #include "dnload.h"
  19.  
  20. // NOTE: in glsl it is legal to have a fragment shader without a vertex shader
  21. //  Infact ATi/AMD  drivers allow this but unwisely forget to set up variables for
  22. // the fragment shader - thus all GLSL programs must have a vertex shader :-(
  23. // Thanks ATI/AMD
  24.  
  25. // This is pretty dirty...note we do not transform the rectangle but we do use
  26. // glRotatef to pass in a value we can use to animate...avoids one more getProcAddress later
  27. const GLchar *vsh="\
  28. varying vec4 p;\
  29. void main(){\
  30. p=sin(gl_ModelViewMatrix[1]*9.0);\
  31. gl_Position=gl_Vertex;\
  32. }";
  33.  
  34. // an iterative function for colour
  35. const GLchar *fsh="\
  36. varying vec4 p;\
  37. void main(){\
  38. float r,t,j;\
  39. vec4 v=gl_FragCoord/400.0-1.0;\
  40. r=v.x*p.r;\
  41. for(int j=0;j<7;j++){\
  42. t=v.x+p.r*p.g;\
  43. v.x=t*t-v.y*v.y+r;\
  44. v.y=p.g*3.0*t*v.y+v.y;\
  45. }\
  46. gl_FragColor=vec4(mix(p,vec4(t),max(t,v.x)));\
  47. }";
  48. //p.g*3.0*t*v.y+i;\
  49.  
  50. static void setShaders() {
  51.  
  52.   GLuint v = dnload_glCreateShader(GL_VERTEX_SHADER);
  53.   GLuint f = dnload_glCreateShader(GL_FRAGMENT_SHADER);
  54.   GLuint p = dnload_glCreateProgram();
  55.  
  56.   dnload_glShaderSource(v, 1, &vsh, NULL);
  57.   dnload_glCompileShader(v);
  58.   dnload_glAttachShader(p, v);
  59.   dnload_glShaderSource(f, 1, &fsh, NULL);
  60.   dnload_glCompileShader(f);
  61.   dnload_glAttachShader(p, f);
  62.   dnload_glLinkProgram(p);
  63.   dnload_glUseProgram(p);
  64. }
  65.  
  66. void _start()
  67. {
  68.   static SDL_Event e;
  69.   dnload();
  70.   dnload_SDL_Init(SDL_INIT_VIDEO);
  71.   dnload_SDL_SetVideoMode(1024, 768, 0, SDL_OPENGL);
  72.  
  73.   dnload_SDL_ShowCursor(SDL_DISABLE);
  74.   setShaders();
  75.    //**********************
  76.    // NOW THE MAIN LOOP...
  77.    //**********************
  78.    // there is no depth test or clear screen...as we draw in order and cover
  79.    // the whole area of the screen.
  80.   do
  81.   {
  82.     dnload_glRotatef(0.3f, 1, 1, 1);
  83.     dnload_glRecti(-1, -1, 1, 1);
  84.     dnload_SDL_GL_SwapBuffers();
  85.    
  86.     dnload_SDL_PollEvent(&e);
  87.    
  88.     if (e.type == SDL_KEYDOWN)
  89.       break;
  90.   } while (e.type != SDL_QUIT);
  91.  
  92.   asm_exit();
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement