Update of /cvsroot/playerstage/code/stage/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14412/src

Modified Files:
      Tag: opengl
        gui_gl.c 
Log Message:
working on vertex shader to linearize Z buffer

Index: gui_gl.c
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/Attic/gui_gl.c,v
retrieving revision 1.1.2.13
retrieving revision 1.1.2.14
diff -C2 -d -r1.1.2.13 -r1.1.2.14
*** gui_gl.c    5 Mar 2007 00:42:29 -0000       1.1.2.13
--- gui_gl.c    23 Mar 2007 02:19:36 -0000      1.1.2.14
***************
*** 20,23 ****
--- 20,24 ----
  #include <GL/gl.h>
  #include <GL/glu.h>
+ #include <GL/glext.h>
  //#include <GLUT/glut.h>
  #include <GL/glx.h> // for XFont for drawing text from X fonts
***************
*** 1392,1395 ****
--- 1393,1424 ----
  }
  
+ static GLuint VertShader;
+ static char * VertSrc = \
+ /* "!!ARBvp1.0                                                \n\ */
+ /* PARAM      CTM[4]  = { state.matrix.mvp };                 \n\ */
+ /* ## Standard transform                                      \n\ */
+ /* DP4  result.position.x, CTM[0], vertex.position;   \n\ */
+ /* DP4  result.position.y, CTM[1], vertex.position;   \n\ */
+ /* DP4  result.position.z, CTM[2], vertex.position;   \n\ */
+ /* DP4  result.position.w, CTM[3], vertex.position;   \n\ */
+ /* # Rotate color     values                                  \n\ */
+ /* MOV  result.color, vertex.color.zxyw;                      \n\ */
+ /* END\n" */
+ /* ; */
+ "!!ARBvp1.0 \n\
+ #This vp is used in zprecision demo for solving the z-precision problem\n\
+ #in a perspective projection.\n\
+ #AUTHOR: Vrej Melkonian\n\
+ #DATE: Monday, June 23, 2003\n\
+ PARAM m[4]={state.matrix.modelview}; \n\
+ PARAM mvp[4]={state.matrix.mvp}; \n\
+ ATTRIB iPos=vertex.position; \n\
+ OUTPUT oPos=result.position;\n\
+ #Transform the vertex to clip coordinates.\n\
+ DP4   r0.x, iPos, mvp[0];\n\
+ DP4   r0.y, iPos, mvp[1];\n\
+ DP4   r0.z, iPos, mvp[2];\n\
+ DP4   r0.w, iPos, mvp[3];\n\
+ END\n ";
  
  void draw_world(  stg_world_t* world )
***************
*** 1616,1620 ****
--- 1645,1668 ----
  /*      glPopMatrix(); */
  /*    }    */
+      
+ 
+       int err;
        
+       //if (! glutExtensionSupported("GL_ARB_vertex_program"))
+       //Fail("GL_ARB_vertex_program not available on this machine");
+       
+       /* Vertex shader */
+       glEnable(GL_VERTEX_PROGRAM_ARB);
+       glGenProgramsARB(1, &VertShader);
+       glBindProgramARB(GL_VERTEX_PROGRAM_ARB, VertShader);
+       glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+                        strlen(VertSrc), VertSrc);
+ 
+       glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err);
+       if (err >= 0)
+       printf("Error in vertex shader %s\n",
+              glGetString(GL_PROGRAM_ERROR_STRING_ARB));
+       
+  
        
        glPushAttrib( GL_ALL_ATTRIB_BITS );
***************
*** 1630,1639 ****
        glLoadIdentity ();
        //glScalef( win->scale, win->scale, win->scale );
-       glFrustum( -1,1,-1,1,1,800 );
  
!       // map the viewport to pixel units by scaling it the same as the window
!       //  glOrtho( 0, pixels_width,
!       //   0, pixels_height,
!       //glOrtho( -1,1,-1,1,-1,1 );
        
        glMatrixMode( GL_MODELVIEW );
--- 1678,1695 ----
        glLoadIdentity ();
        //glScalef( win->scale, win->scale, win->scale );
  
!       double far = 8.0;
!       double near = 0.1;
! 
!       gluPerspective( 45, 361/100, near, far );
! 
!       GLdouble projection[16];        
!       glGetDoublev(GL_PROJECTION_MATRIX, projection); 
! 
!       // hack the projection matric to simulate a w-buffer
!       projection[10] = -2.0/(far-near);
!       projection[11] = (-far-near) / (far-near);
! 
!       glLoadMatrixd( projection );
        
        glMatrixMode( GL_MODELVIEW );
***************
*** 1706,1710 ****
  
        glMatrixMode( GL_PROJECTION );
!       glPopMatrix();     
      }
    
--- 1762,1781 ----
  
        glMatrixMode( GL_PROJECTION );
!       glPopMatrix();  
! 
!       
!       GLfloat* depths = calloc( sizeof(GLfloat), 361 );
!       glReadPixels( 0,50, 361, 1, GL_DEPTH_COMPONENT, GL_FLOAT, depths );
!    
!       puts("");
!       for( int c=0; c<361; c++ )
!       printf( "%.3f ", depths[c] );
!       puts("");            
! 
!       puts("");
!       for( int c=0; c<361; c++ )
!       printf( "%.3f ", near + depths[c] * (far-near) );
!       puts("");
! 
      }
    


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to