1 / 16

Chap 7. O penGL extension

Chap 7. O penGL extension. How to. By yourself Query the “OpenGL32.dll”, and get the function address Don’t do it glew http://glew.sourceforge.net/. In your C++ project. Add “include/glew.h” to your “Include Files” folder in .NET Put “lib/glew32s.lib” into your project folder

mizell
Download Presentation

Chap 7. O penGL extension

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chap 7. OpenGL extension

  2. How to • By yourself • Query the “OpenGL32.dll”, and get the function address • Don’t do it • glew • http://glew.sourceforge.net/

  3. In your C++ project • Add “include/glew.h” to your “Include Files” folder in .NET • Put “lib/glew32s.lib” into your project folder #define GLEW_STATIC 1 #include "glew.h“ … glutInit(&argc, argv); glewInit();

  4. Some online resources • OpenGL programming guide chapter 9 “Texture Mapping” • http://www.opengl.org/documentation/red_book_1.0/OpenGL_PG_ch09.pdf • An online tutorial on shadow map • http://www.paulsprojects.net/tutorials/smt/smt.html

  5. Example: Shadow map • What is shadow light eye Object Under shadow

  6. What is a shadow map • A depth image as seen from the light • When the depth of a point is greater than the depth in the shadow map, it is under shadow • If you move the viewpoint to the light source position, there are no shadows from that perspective

  7. Overview • 3-pass algorithm • First pass: render the scene from the point of view of the light,and store the depth in the texture (shadow map) • projection * modelview,… • Second pass: render the scene with only ambient light • Third pass: render the scene,and “compare” the depth of the fragment to the shadow map, if it’s greater than the depth in the shadow map, it’s under shadow. if it’s not under shadow, render the fragment with diffuse and specular light. • How can we “compare” in different coordinate?

  8. How can we “compare” in different coordinate

  9. The transformation matrix

  10. In OpenGL • First pass Setup the projection and modelview matrix as seen from the light draw your scene glGenTextures(1, &texID); glBindTexture(GL_TEXTURE_2D, texID); glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, SHADOW_MAP_WIDTH, SHADOW_MAP_HEIGHT, 0 );

  11. void glCopyTexImage2D( GLenum target, GLint level, GLint internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);

  12. Third pass void generateTextureMatrix( float* lightPos ) { glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef( 0.5, 0.5, 0.0 ); glScalef( 0.5, 0.5, 1.0 ); gluPerspective( 80.0, 1.0, 10.0, 100.0 ); gluLookAt( lightPos[0], lightPos[1], lightPos[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glEnable( GL_TEXTURE_GEN_R ); glEnable( GL_TEXTURE_GEN_Q );

  13. float sPlane[4] = {1.0, 0.0, 0.0, 0.0}; float tPlane[4] = {0.0, 1.0, 0.0, 0.0}; float rPlane[4] = {0.0, 0.0, 1.0, 0.0}; float qPlane[4] = {0.0, 0.0, 0.0, 1.0}; glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR ); glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR ); glTexGenfv( GL_S, GL_EYE_PLANE, sPlane ); glTexGenfv( GL_T, GL_EYE_PLANE, tPlane ); glTexGenfv( GL_R, GL_EYE_PLANE, rPlane ); glTexGenfv( GL_Q, GL_EYE_PLANE, qPlane );

  14. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL ); glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE ); glMatrixMode(GL_MODELVIEW); }

  15. Not so easy… • Self shadow • Add bias • glPolygonOffset(GLfloat factor, GLfloat units); • Render backface and cull front face when gererating shadow map • Aliasing

More Related