|
From: Tim R. <ti...@us...> - 2004-08-13 08:26:52
|
Update of /cvsroot/csdopenglnet/csdOpenGL/Cg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9811/Cg Modified Files: demo.cs Log Message: first Cg example is running Index: demo.cs =================================================================== RCS file: /cvsroot/csdopenglnet/csdOpenGL/Cg/demo.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** demo.cs 7 Aug 2004 06:58:39 -0000 1.4 --- demo.cs 13 Aug 2004 08:26:43 -0000 1.5 *************** *** 14,19 **** protected bool haveLoadedPrograms = false; protected int res=512; ! protected float[] P, N, uv; ! protected uint[] indices; public Demo() { --- 14,21 ---- protected bool haveLoadedPrograms = false; protected int res=512; ! protected float[] P = null; ! protected float[] N = null; ! protected float[] uv = null; ! protected uint[] indices = null; public Demo() { *************** *** 37,40 **** --- 39,43 ---- Debug.WriteLine( "Exiting Demo()" ); + Debug.Unindent(); } *************** *** 83,93 **** glRotatef( curTime, 0, 1, 0 ); ! Debug.WriteLine( "Bing Cg programs" ); cgGLBindProgram( vertexProgram ); cgGLBindProgram( fragmentProgram ); Debug.WriteLine( "Bind uniform parameters to vertex shader" ); cgGLSetStateMatrixParameter(cgGetNamedParameter(vertexProgram, "ModelViewProj"), CGGLenum.CG_GL_MODELVIEW_PROJECTION_MATRIX, CGGLenum.CG_GL_MATRIX_IDENTITY); cgGLSetStateMatrixParameter(cgGetNamedParameter(vertexProgram, "ModelView"), CGGLenum.CG_GL_MODELVIEW_MATRIX, CGGLenum.CG_GL_MATRIX_IDENTITY); cgGLSetStateMatrixParameter(cgGetNamedParameter(vertexProgram, "ModelViewIT"), CGGLenum.CG_GL_MODELVIEW_MATRIX, CGGLenum.CG_GL_MATRIX_INVERSE_TRANSPOSE); --- 86,99 ---- glRotatef( curTime, 0, 1, 0 ); ! Debug.WriteLine( "Bind Cg programs" ); cgGLBindProgram( vertexProgram ); cgGLBindProgram( fragmentProgram ); Debug.WriteLine( "Bind uniform parameters to vertex shader" ); + Debug.WriteLine( "==> ModelViewProj" ); cgGLSetStateMatrixParameter(cgGetNamedParameter(vertexProgram, "ModelViewProj"), CGGLenum.CG_GL_MODELVIEW_PROJECTION_MATRIX, CGGLenum.CG_GL_MATRIX_IDENTITY); + Debug.WriteLine( "==> ModelView" ); cgGLSetStateMatrixParameter(cgGetNamedParameter(vertexProgram, "ModelView"), CGGLenum.CG_GL_MODELVIEW_MATRIX, CGGLenum.CG_GL_MATRIX_IDENTITY); + Debug.WriteLine( "==> ModelViewIT" ); cgGLSetStateMatrixParameter(cgGetNamedParameter(vertexProgram, "ModelViewIT"), CGGLenum.CG_GL_MODELVIEW_MATRIX, CGGLenum.CG_GL_MATRIX_INVERSE_TRANSPOSE); *************** *** 99,107 **** Debug.WriteLine( "Bind uniform parameters to fragment shader" ); ! float[] lightPos = { 3, 2, -3 }; cgGLSetParameter3fv(cgGetNamedParameter(fragmentProgram, "Plight"), lightPos); ! float[] lightColor = { 1, 1, 1 }; cgGLSetParameter3fv(cgGetNamedParameter(fragmentProgram, "lightColor"), lightColor); ! cgGLSetParameter1f(cgGetNamedParameter(fragmentProgram, "shininess"), 40); Debug.WriteLine( "Enable approprate texture for fragment shader" ); --- 105,116 ---- Debug.WriteLine( "Bind uniform parameters to fragment shader" ); ! float[] lightPos = { 3.0f, 2.0f, -3.0f }; ! float[] lightColor = { 1.0f, 1.0f, 1.0f }; ! Debug.WriteLine( "==> Plight" ); cgGLSetParameter3fv(cgGetNamedParameter(fragmentProgram, "Plight"), lightPos); ! Debug.WriteLine( "==> lightColor" ); cgGLSetParameter3fv(cgGetNamedParameter(fragmentProgram, "lightColor"), lightColor); ! Debug.WriteLine( "==> shininess" ); ! cgGLSetParameter1f(cgGetNamedParameter(fragmentProgram, "shininess"), 40.0f ); Debug.WriteLine( "Enable approprate texture for fragment shader" ); *************** *** 124,128 **** protected void DrawGeometry() { Debug.Indent(); ! Debug.WriteLine( "Demo.DrawGeometry()" ); int nu = 30; --- 133,137 ---- protected void DrawGeometry() { Debug.Indent(); ! Debug.WriteLine( "Entering Demo.DrawGeometry()" ); int nu = 30; *************** *** 143,151 **** Debug.WriteLine( "Fill position, normal and texture coordinate arrays" ); for ( v=0; v<nv; ++v ) { ! float fv = (float)(v/(nv-1)); for (u=0; u<nu; ++u ) { ! float fu=(float)(u/(nu-1)); uv[uvp] = fu; ! uv[uvp+1] = fu; parametricEval( fu, fv, pp, np ); pp += 3; --- 152,161 ---- Debug.WriteLine( "Fill position, normal and texture coordinate arrays" ); for ( v=0; v<nv; ++v ) { ! float fv = ((float)v)/((float)(nv-1)); ! Console.WriteLine( fv ); for (u=0; u<nu; ++u ) { ! float fu= ((float)u) /((float)(nu-1)); uv[uvp] = fu; ! uv[uvp+1] = fv; parametricEval( fu, fv, pp, np ); pp += 3; *************** *** 171,211 **** Debug.WriteLine( "Associate data 'pointers' with vertex shader" ); param = cgGetNamedParameter( vertexProgram, "Pobject" ); cgGLSetParameterPointer( param, 3, GL_FLOAT, 0, P ); param = cgGetNamedParameter( vertexProgram, "Nobject" ); cgGLSetParameterPointer( param, 3, GL_FLOAT, 0, N ); param = cgGetNamedParameter( vertexProgram, "TexUV" ); cgGLSetParameterPointer( param, 2, GL_FLOAT, 0, uv ); - param = cgGetNamedParameter( fragmentProgram, "diffuseMap" ); - cgGLEnableTextureParameter( param ); } Debug.WriteLine( "Enable bindings to parameters" ); param = cgGetNamedParameter( vertexProgram, "Pobject" ); cgGLEnableClientState( param ); param = cgGetNamedParameter( vertexProgram, "Nobject" ); cgGLEnableClientState( param ); param = cgGetNamedParameter( vertexProgram, "TexUV" ); cgGLEnableClientState( param ); param = cgGetNamedParameter( fragmentProgram, "diffuseMap" ); ! cgGLEnableClientState( param); ! Debug.WriteLine( "Draw geometry" ); glDrawElements( GL_TRIANGLES, 3*nTris, GL_UNSIGNED_INT, indices ); ! Debug.WriteLine( "Disable bindings to parameters" ); param = cgGetNamedParameter( vertexProgram, "Pobject" ); cgGLDisableClientState( param ); param = cgGetNamedParameter( vertexProgram, "Nobject" ); cgGLDisableClientState( param ); param = cgGetNamedParameter( vertexProgram, "TexUV" ); cgGLDisableClientState( param ); ! param = cgGetNamedParameter(fragmentProgram, "diffuseMap"); ! cgGLDisableTextureParameter(param); } protected void parametricEval( float u, float v, int pp, int np ) { ! Console.WriteLine( "parametricEval" ); double theta = System.Math.PI * u; double phi = 2.0 * System.Math.PI * v; --- 181,234 ---- Debug.WriteLine( "Associate data 'pointers' with vertex shader" ); + Debug.WriteLine( "==> Pobject" ); param = cgGetNamedParameter( vertexProgram, "Pobject" ); cgGLSetParameterPointer( param, 3, GL_FLOAT, 0, P ); + Debug.WriteLine( "==> Nobject "); param = cgGetNamedParameter( vertexProgram, "Nobject" ); cgGLSetParameterPointer( param, 3, GL_FLOAT, 0, N ); + Debug.WriteLine( "==> TexUV" ); param = cgGetNamedParameter( vertexProgram, "TexUV" ); cgGLSetParameterPointer( param, 2, GL_FLOAT, 0, uv ); } Debug.WriteLine( "Enable bindings to parameters" ); + Debug.WriteLine( "==> Pobject" ); param = cgGetNamedParameter( vertexProgram, "Pobject" ); cgGLEnableClientState( param ); + Debug.WriteLine( "==> Nobject" ); param = cgGetNamedParameter( vertexProgram, "Nobject" ); cgGLEnableClientState( param ); + Debug.WriteLine( "==> TexUV" ); param = cgGetNamedParameter( vertexProgram, "TexUV" ); cgGLEnableClientState( param ); + Debug.WriteLine( "==> diffuseMap" ); param = cgGetNamedParameter( fragmentProgram, "diffuseMap" ); ! cgGLEnableTextureParameter( param ); ! Debug.WriteLine( "Draw geometry" ); glDrawElements( GL_TRIANGLES, 3*nTris, GL_UNSIGNED_INT, indices ); ! Debug.WriteLine( "Disable bindings to parameters" ); + Debug.WriteLine( "==> Pobject" ); param = cgGetNamedParameter( vertexProgram, "Pobject" ); cgGLDisableClientState( param ); + Debug.WriteLine( "==> Nobject" ); param = cgGetNamedParameter( vertexProgram, "Nobject" ); cgGLDisableClientState( param ); + Debug.WriteLine( "==> TexUV" ); param = cgGetNamedParameter( vertexProgram, "TexUV" ); cgGLDisableClientState( param ); ! Debug.WriteLine( "==> diffuseMap" ); ! param = cgGetNamedParameter( fragmentProgram, "diffuseMap" ); ! cgGLDisableTextureParameter( param ); + Debug.WriteLine( "Exiting Demo.DrawGeometry()" ); + Debug.Unindent(); } protected void parametricEval( float u, float v, int pp, int np ) { ! Debug.Indent(); ! Debug.WriteLine( "Entering Demo.parametricEval(float,float,int,int)" ); ! double theta = System.Math.PI * u; double phi = 2.0 * System.Math.PI * v; *************** *** 215,229 **** P[pp+2] = (float)(System.Math.Cos(theta)); ! N[pp] = P[pp]; ! N[pp+1] = P[pp+1]; ! N[pp+2] = P[pp+2]; } ! protected void ChooseProfiles() { ! Console.WriteLine( "ChooseProfiles" ); if ( CG_TRUE==cgGLIsProfileSupported( CGprofile.CG_PROFILE_ARBVP1 ) ) { vertexProfile = CGprofile.CG_PROFILE_ARBVP1; } else if ( CG_TRUE==cgGLIsProfileSupported( CGprofile.CG_PROFILE_VP30 ) ) { vertexProfile = CGprofile.CG_PROFILE_VP30; } else { Console.WriteLine( "Neither arbvp1 or vp30 vertex profiles supported on this system!" ); --- 238,277 ---- P[pp+2] = (float)(System.Math.Cos(theta)); ! N[np] = P[pp]; ! N[np+1] = P[pp+1]; ! N[np+2] = P[pp+2]; ! ! Debug.WriteLine( "Exiting Demo.parametricEval(float,float,int,int)" ); ! Debug.Unindent(); } ! ! protected void drawTriangles( uint[] indices ) { ! Debug.Indent(); ! Debug.WriteLine( "Entering Demo.drawTriangls(uint[])" ); ! ! int i = 0; ! while ( i+8<indices.Length ) { ! glBegin( GL_TRIANGLES ); ! glVertex3f( indices[i], indices[i+1], indices[i+2] ); ! glVertex3f( indices[i+3], indices[i+4], indices[i+5] ); ! glVertex3f( indices[i+6], indices[i+7], indices[i+8] ); ! glEnd(); ! i+=9; ! } ! ! Debug.WriteLine( "Exiting Demo.drawTriangles(uint[])" ); ! Debug.Unindent(); ! } ! protected void ChooseProfiles() { ! Debug.Indent(); ! Debug.WriteLine( "Entering Demo.ChooseProfiles()" ); ! if ( CG_TRUE==cgGLIsProfileSupported( CGprofile.CG_PROFILE_ARBVP1 ) ) { vertexProfile = CGprofile.CG_PROFILE_ARBVP1; + Console.WriteLine( "Vertex Profile: ARBVP1" ); } else if ( CG_TRUE==cgGLIsProfileSupported( CGprofile.CG_PROFILE_VP30 ) ) { vertexProfile = CGprofile.CG_PROFILE_VP30; + Console.WriteLine( "Vertex Profile: VP30" ); } else { Console.WriteLine( "Neither arbvp1 or vp30 vertex profiles supported on this system!" ); *************** *** 233,249 **** if ( CG_TRUE==cgGLIsProfileSupported( CGprofile.CG_PROFILE_ARBFP1 ) ) { fragmentProfile = CGprofile.CG_PROFILE_ARBFP1; } else if ( CG_TRUE==cgGLIsProfileSupported( CGprofile.CG_PROFILE_FP30 ) ) { fragmentProfile = CGprofile.CG_PROFILE_FP30; } else { Console.WriteLine( "Netiher arbfp1 or fp30 fragment profiles supported on this system!" ); System.Environment.Exit(2); } } protected void LoadCgPrograms() { ! Console.WriteLine( "LoadCgPrograms" ); Debug.Assert( CG_TRUE==cgIsContext( context ) ); vertexProgram = cgCreateProgramFromFile( context, CGenum.CG_SOURCE, "demo_vert.cg", vertexProfile, null, null ); cgGLEnableProfile( vertexProfile ); cgGLLoadProgram( vertexProgram ); --- 281,305 ---- if ( CG_TRUE==cgGLIsProfileSupported( CGprofile.CG_PROFILE_ARBFP1 ) ) { fragmentProfile = CGprofile.CG_PROFILE_ARBFP1; + Console.WriteLine( "Fargment Profile: ARBFP1" ); } else if ( CG_TRUE==cgGLIsProfileSupported( CGprofile.CG_PROFILE_FP30 ) ) { fragmentProfile = CGprofile.CG_PROFILE_FP30; + Console.WriteLine( "Fragmen Profile: FP30" ); } else { Console.WriteLine( "Netiher arbfp1 or fp30 fragment profiles supported on this system!" ); System.Environment.Exit(2); } + + Debug.WriteLine( "Exiting Demo.ChooseProfiles()" ); + Debug.Unindent(); } protected void LoadCgPrograms() { ! Debug.Indent(); ! Debug.WriteLine( "Entering Demo.LoadCgPrograms()" ); ! Debug.Assert( CG_TRUE==cgIsContext( context ) ); vertexProgram = cgCreateProgramFromFile( context, CGenum.CG_SOURCE, "demo_vert.cg", vertexProfile, null, null ); + if (CG_FALSE==cgIsProgramCompiled(vertexProgram)) cgCompileProgram(vertexProgram); cgGLEnableProfile( vertexProfile ); cgGLLoadProgram( vertexProgram ); *************** *** 253,260 **** cgGLEnableProfile( fragmentProfile ); cgGLLoadProgram( fragmentProgram ); } protected void LoadTextures() { ! Console.WriteLine( "LoadTextures" ); uint handle ; uint[] h = new uint[1]; --- 309,321 ---- cgGLEnableProfile( fragmentProfile ); cgGLLoadProgram( fragmentProgram ); + + Debug.WriteLine( "Exiting Demo.LoadCgPrograms()" ); + Debug.Unindent(); } protected void LoadTextures() { ! Debug.Indent(); ! Debug.WriteLine( "Entering Demo.LoadTextures()" ); ! uint handle ; uint[] h = new uint[1]; *************** *** 263,267 **** glBindTexture( GL_TEXTURE_2D, handle ); ! glTexParameterf(GL_TEXTURE_2D, 33169, GL_TRUE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); --- 324,328 ---- glBindTexture( GL_TEXTURE_2D, handle ); ! glTexParameterf(GL_TEXTURE_2D, 0x8191, GL_TRUE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); *************** *** 270,273 **** --- 331,335 ---- float[] data = new float[res*res*4]; + for ( int i=0; i<res; i++ ) { for ( int j=0; j<res; j++ ) { *************** *** 288,291 **** --- 350,356 ---- glTexImage2D( GL_TEXTURE_2D, 0, 4, res, res, 0, GL_RGBA, GL_FLOAT, data ); cgGLSetTextureParameter( cgGetNamedParameter( fragmentProgram, "diffuseMap" ), handle ); + + Debug.WriteLine( "Exiting Demo.LoadTextures()" ); + Debug.Unindent(); } |