Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. struct FBOELEM {
  2. GLuint fbo;
  3. GLuint depthbuffer;
  4. GLuint texture;
  5. GLuint depthtexture;
  6. GLint status;
  7. };
  8.  
  9. void start_fbo(GLuint fbo, int width, int height)
  10. {
  11. oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
  12. glPushAttrib(GL_VIEWPORT_BIT);
  13. glViewport(0,0,width,height);
  14. }
  15.  
  16. void end_fbo()
  17. {
  18. glPopAttrib();
  19. oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  20. }
  21.  
  22. void draw_fbotexture(GLuint texture,int width, int height )
  23. {
  24. glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
  25. glEnable(GL_TEXTURE_2D);
  26. BeginOrtho2D(width,height,true);
  27. glBindTexture( GL_TEXTURE_2D, texture);
  28. glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  29. glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  30. DrawFullScreenQuad(width,height);
  31. glBindTexture( GL_TEXTURE_2D, 0);
  32. EndProjection();
  33. }
  34.  
  35. int init_fbo ( int count, struct FBOELEM *buffers, int width, int height ) {
  36. // creates count nummers of Frame/Depthbuffers with a corresponding texture
  37. // buffers have to be allocated.
  38. int current, enderr = 1;
  39. GLenum error;
  40.  
  41. for (current = 0; current < count; current++) {
  42. oglGenFramebuffersEXT (1, &buffers[current].fbo);
  43. oglBindFramebufferEXT (GL_FRAMEBUFFER_EXT, buffers[current].fbo);
  44. oglGenRenderbuffersEXT (1, &buffers[current].depthbuffer);
  45. oglBindRenderbufferEXT (GL_RENDERBUFFER_EXT, buffers[current].depthbuffer);
  46. oglRenderbufferStorageEXT (GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
  47. oglFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, buffers[current].depthbuffer);
  48. glGenTextures (1, &buffers[current].texture);
  49. glBindTexture (GL_TEXTURE_2D, buffers[current].texture);
  50. glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  51. glTexParameteri (GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  52. glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  53. oglFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, buffers[current].texture, 0);
  54. // check if everything was ok with our requests above.
  55. error = oglCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
  56. if (error != GL_FRAMEBUFFER_COMPLETE_EXT) {
  57. buffers[current].status = 0;
  58. enderr = 0;
  59. }
  60. else
  61. buffers[current].status = 1;
  62. }
  63. // set Rendering Device to screen again.
  64. oglBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
  65. return (enderr);
  66. }
  67.  
  68. GLuint init_rendertexture(int resx, int resy)
  69. {
  70. GLuint texture;
  71. unsigned char* texturedata = new unsigned char[4 * resx * resy];
  72. memset(texturedata,0,4*XRES*YRES);
  73. //texture
  74. glEnable(GL_TEXTURE_2D);
  75. glGenTextures(1, &texture);
  76. glBindTexture(GL_TEXTURE_2D, texture);
  77. glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  78. glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  79. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  80. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  81. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, resx, resy, 0, GL_RGBA,
  82. GL_UNSIGNED_BYTE, texturedata);
  83. glGetError();
  84. glBindTexture(GL_TEXTURE_2D, 0);
  85. delete [] texturedata;
  86. return texture;
  87. }
  88.  
  89. int init_fbo(GLuint texture,GLuint fbo, GLuint rbo, int width, int height)
  90. {
  91. unsigned char* texturedata = new unsigned char[4 * width * height];
  92. memset(texturedata,0,4*XRES*YRES);
  93. //texture
  94. glEnable(GL_TEXTURE_2D);
  95. glGenTextures(1, &texture);
  96. glBindTexture(GL_TEXTURE_2D, texture);
  97. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  98. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  99. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA,GL_UNSIGNED_BYTE, texturedata);
  100. oglGenFramebuffersEXT(1, &fbo);
  101. oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
  102. oglGenRenderbuffersEXT(1, &rbo);
  103. oglBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rbo);
  104. oglRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
  105. oglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0);
  106. oglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rbo);
  107. oglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  108. glGetError();
  109. glBindTexture(GL_TEXTURE_2D, 0);
  110. delete [] texturedata;
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement