Advertisement
Guest User

Shadowbuffer creation

a guest
Aug 16th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. Creation of depthmap:
  2.  
  3. shadowBufferStruct shadowFrameBufferCreator(GLfloat shadowWidth, GLfloat shadowHeight)
  4. {
  5.     shadowBufferStruct shadowBuf;
  6.  
  7.     //Create the FBO and the required textures
  8.     GLuint depthMapFBO;
  9.     glGenFramebuffers(1, &shadowBuf.depthMapFBO);
  10.  
  11.     //Depth map texture
  12.     GLuint depthMap;
  13.     glGenTextures(1, &shadowBuf.depthMap);
  14.     glBindTexture(GL_TEXTURE_2D, shadowBuf.depthMap);
  15.     glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowWidth, shadowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
  16.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  17.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  18.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  19.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  20.  
  21.     glBindFramebuffer(GL_FRAMEBUFFER, shadowBuf.depthMapFBO);
  22.     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowBuf.depthMap, 0);
  23.     glDrawBuffer(GL_NONE); //No color buffer needed
  24.     glReadBuffer(GL_NONE);
  25.  
  26.     if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
  27.         printf("\nFramebuffer is not complete!");
  28.  
  29.     glBindFramebuffer(GL_FRAMEBUFFER, 0);
  30.  
  31.     //Create LSMatrix
  32.     GLfloat near_plane = 1.0f;
  33.     GLfloat far_plane = 10.0f;
  34.     glm::mat4 lightProjMat = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
  35.     glm::mat4 lightViewMatrix = glm::lookAt(glm::vec3(-2.0f, 6.0f, -1.0f),
  36.                                                 glm::vec3(0.0f, 0.0f, 0.0f),
  37.                                                 glm::vec3(0.0f, 1.0f, 0.0f));
  38.  
  39.     shadowBuf.lightSpaceMat = lightProjMat * lightViewMatrix;
  40.  
  41.     return shadowBuf;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement