consolidate cg examples
svn path=/trunk/tao/; revision=67697
This commit is contained in:
Родитель
0e71dbd7be
Коммит
3ce6f7d009
|
@ -1,22 +0,0 @@
|
|||
MIT License
|
||||
Copyright ©2003-2005 Tao Framework Team
|
||||
http://www.taoframework.com
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -1,23 +0,0 @@
|
|||
CgIlExamples
|
||||
Copyright ©2003-2006 Tao Framework Team
|
||||
http://www.taoframework.com
|
||||
All rights reserved.
|
||||
|
||||
These are C# ports of some Cg examples. The originals
|
||||
are available from http://www.nvidia.com/.
|
||||
|
||||
These examples use Tao.Cg, Tao.FreeGlut, and Tao.OpenGl. Make sure you
|
||||
have the appropriate native libraries for your system installed.
|
||||
|
||||
These examples are fairly well documented, however, do not take
|
||||
them to be 'best practices' for .NET Cg development. The
|
||||
intent of these ports is as an introduction or as a comparison
|
||||
against the original native versions.
|
||||
|
||||
David Hudson
|
||||
http://www.taoframework.com
|
||||
|
||||
Change Log:
|
||||
|
||||
August 11, 2006
|
||||
Initial release, version 1.0.0.0.
|
|
@ -1,51 +0,0 @@
|
|||
#region License
|
||||
/*
|
||||
MIT License
|
||||
Copyright ©2003-2005 Tao Framework Team
|
||||
http://www.taoframework.com
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion License
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
[assembly: AllowPartiallyTrustedCallers]
|
||||
[assembly: AssemblyCompany("Tao Framework - http://www.taoframework.com")]
|
||||
[assembly: AssemblyConfiguration("Retail")]
|
||||
[assembly: AssemblyCopyright("Copyright ©2003-2005 Tao Framework Team. All rights reserved.")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyDefaultAlias("CgExamples.Gl_01_vertex_program")]
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
[assembly: AssemblyDescription("Cg GL 01 vertex example.")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
||||
[assembly: AssemblyKeyName("")]
|
||||
[assembly: AssemblyProduct("CgExamples.Gl_01_vertex_program")]
|
||||
[assembly: AssemblyTitle("CgExamples.Gl_01_vertex_program")]
|
||||
[assembly: AssemblyTrademark("Tao Framework - http://www.taoframework.com")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: CLSCompliant(true)]
|
||||
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.Execution)]
|
||||
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.SkipVerification)]
|
||||
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
|
@ -1,17 +0,0 @@
|
|||
// This is C2E1v_green from "The Cg Tutorial" (Addison-Wesley, ISBN
|
||||
// 0321194969) by Randima Fernando and Mark J. Kilgard. See page 38.
|
||||
|
||||
struct C2E1v_Output {
|
||||
float4 position : POSITION;
|
||||
float3 color : COLOR;
|
||||
};
|
||||
|
||||
C2E1v_Output C2E1v_green(float2 position : POSITION)
|
||||
{
|
||||
C2E1v_Output OUT;
|
||||
|
||||
OUT.position = float4(position,0,1);
|
||||
OUT.color = float3(0,1,0);
|
||||
|
||||
return OUT;
|
||||
}
|
|
@ -1,186 +0,0 @@
|
|||
#region License
|
||||
/*
|
||||
MIT License
|
||||
Copyright ©2003-2005 Tao Framework Team
|
||||
http://www.taoframework.com
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion License
|
||||
|
||||
#region Original Credits / License
|
||||
//-----------------------------------------------------------------------------
|
||||
/* 01_vertex_program.c - OpenGL-based very simple vertex program example
|
||||
using Cg program from Chapter 2 of "The Cg Tutorial" (Addison-Wesley,
|
||||
ISBN 0321194969). */
|
||||
|
||||
/* Requires the OpenGL Utility Toolkit (GLUT) and Cg runtime (version
|
||||
1.0 or higher). */
|
||||
//-----------------------------------------------------------------------------
|
||||
#endregion Original Credits / License
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Tao.FreeGlut;
|
||||
using Tao.OpenGl;
|
||||
using Tao.Cg;
|
||||
|
||||
namespace CgExamples
|
||||
{
|
||||
#region Class Documentation
|
||||
/// <summary>
|
||||
/// Displays a triangle
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// OpenGL-based very simple vertex program example
|
||||
/// using Cg program from Chapter 2 of "The Cg Tutorial" (Addison-Wesley,
|
||||
/// ISBN 0321194969)
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
#endregion Class Documentation
|
||||
public sealed class Gl_01_vertex_program
|
||||
{
|
||||
static string myProgramName = "01_vertex_program";
|
||||
static string myVertexProgramName = "C2E1v_green";
|
||||
|
||||
static IntPtr myCgContext;
|
||||
static int myCgVertexProfile;
|
||||
static IntPtr myCgVertexProgram;
|
||||
static Glut.KeyboardCallback KeyboardDelegate;
|
||||
|
||||
// --- Entry Point ---
|
||||
#region Main(string[] args)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string filePath = Path.Combine("..", "..");
|
||||
string fileDirectory = "Data";
|
||||
string vertexFileName = "C2E1v_green.cg";
|
||||
if (File.Exists(vertexFileName))
|
||||
{
|
||||
filePath = "";
|
||||
fileDirectory = "";
|
||||
}
|
||||
else if (File.Exists(Path.Combine(fileDirectory, vertexFileName)))
|
||||
{
|
||||
filePath = "";
|
||||
}
|
||||
|
||||
string myVertexProgramFileName = Path.Combine(Path.Combine(filePath, fileDirectory), vertexFileName);
|
||||
|
||||
KeyboardDelegate += Keyboard;
|
||||
Glut.glutInitWindowSize(400, 400);
|
||||
Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
|
||||
Glut.glutInit();
|
||||
|
||||
Glut.glutCreateWindow(myProgramName);
|
||||
Glut.glutDisplayFunc(Display);
|
||||
Glut.glutKeyboardFunc(KeyboardDelegate);
|
||||
|
||||
Gl.glClearColor(0.1f, 0.3f, 0.6f, 0.0f); /* Blue background */
|
||||
|
||||
myCgContext = Cg.cgCreateContext();
|
||||
checkForCgError("creating context");
|
||||
|
||||
myCgVertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX);
|
||||
CgGl.cgGLSetOptimalOptions(myCgVertexProfile);
|
||||
checkForCgError("selecting vertex profile");
|
||||
|
||||
myCgVertexProgram =
|
||||
Cg.cgCreateProgramFromFile(
|
||||
myCgContext, /* Cg runtime context */
|
||||
Cg.CG_SOURCE, /* Program in human-readable form */
|
||||
myVertexProgramFileName, /* Name of file containing program */
|
||||
myCgVertexProfile, /* Profile: OpenGL ARB vertex program */
|
||||
myVertexProgramName, /* Entry function name */
|
||||
null); /* No extra compiler options */
|
||||
checkForCgError("creating vertex program from file");
|
||||
CgGl.cgGLLoadProgram(myCgVertexProgram);
|
||||
checkForCgError("loading vertex program");
|
||||
|
||||
Glut.glutMainLoop();
|
||||
}
|
||||
|
||||
#endregion Main(string[] args)
|
||||
|
||||
static void checkForCgError(string situation)
|
||||
{
|
||||
int error;
|
||||
string errorString = Cg.cgGetLastErrorString(out error);
|
||||
|
||||
if (error != Cg.CG_NO_ERROR)
|
||||
{
|
||||
Console.WriteLine("{0}- {1}- {2}",
|
||||
myProgramName, situation, errorString);
|
||||
if (error == Cg.CG_COMPILER_ERROR)
|
||||
{
|
||||
Console.WriteLine("{0}", Cg.cgGetLastListing(myCgContext));
|
||||
}
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void Display()
|
||||
{
|
||||
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
CgGl.cgGLBindProgram(myCgVertexProgram);
|
||||
checkForCgError("binding vertex program");
|
||||
|
||||
CgGl.cgGLEnableProfile(myCgVertexProfile);
|
||||
checkForCgError("enabling vertex profile");
|
||||
|
||||
/* Rendering code verbatim from Chapter 1, Section 2.4.1 "Rendering
|
||||
a Triangle with OpenGL" (page 57). */
|
||||
Gl.glBegin(Gl.GL_TRIANGLES);
|
||||
Gl.glVertex2f(-0.8f, 0.8f);
|
||||
Gl.glVertex2f(0.8f, 0.8f);
|
||||
Gl.glVertex2f(0.0f, -0.8f);
|
||||
Gl.glEnd();
|
||||
|
||||
CgGl.cgGLDisableProfile(myCgVertexProfile);
|
||||
checkForCgError("disabling vertex profile");
|
||||
|
||||
Glut.glutSwapBuffers();
|
||||
}
|
||||
|
||||
#region Keyboard()
|
||||
/// <summary>
|
||||
/// Exits application.
|
||||
/// </summary>
|
||||
private static void Keyboard(byte key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 27:
|
||||
Cg.cgDestroyProgram(myCgVertexProgram);
|
||||
Cg.cgDestroyContext(myCgContext);
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion Exit()
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
#region License
|
||||
/*
|
||||
MIT License
|
||||
Copyright ©2003-2005 Tao Framework Team
|
||||
http://www.taoframework.com
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion License
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
[assembly: AllowPartiallyTrustedCallers]
|
||||
[assembly: AssemblyCompany("Tao Framework - http://www.taoframework.com")]
|
||||
[assembly: AssemblyConfiguration("Retail")]
|
||||
[assembly: AssemblyCopyright("Copyright ©2003-2005 Tao Framework Team. All rights reserved.")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyDefaultAlias("CgExamples.Gl_02_vertex_and_fragment_program")]
|
||||
[assembly: AssemblyDelaySign(false)]
|
||||
[assembly: AssemblyDescription("Cg Gl_02_vertex_and_fragment_program")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
||||
[assembly: AssemblyKeyName("")]
|
||||
[assembly: AssemblyProduct("CgExamples.Gl_02_vertex_and_fragment_program")]
|
||||
[assembly: AssemblyTitle("CgExamples.Gl_02_vertex_and_fragment_program")]
|
||||
[assembly: AssemblyTrademark("Tao Framework - http://www.taoframework.com")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: CLSCompliant(true)]
|
||||
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.Execution)]
|
||||
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.SkipVerification)]
|
||||
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
|
@ -1,17 +0,0 @@
|
|||
// This is C2E1v_green from "The Cg Tutorial" (Addison-Wesley, ISBN
|
||||
// 0321194969) by Randima Fernando and Mark J. Kilgard. See page 38.
|
||||
|
||||
struct C2E1v_Output {
|
||||
float4 position : POSITION;
|
||||
float3 color : COLOR;
|
||||
};
|
||||
|
||||
C2E1v_Output C2E1v_green(float2 position : POSITION)
|
||||
{
|
||||
C2E1v_Output OUT;
|
||||
|
||||
OUT.position = float4(position,0,1);
|
||||
OUT.color = float3(0,1,0);
|
||||
|
||||
return OUT;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
// This is C2E2f_passthru from "The Cg Tutorial" (Addison-Wesley, ISBN
|
||||
// 0321194969) by Randima Fernando and Mark J. Kilgard. See page 53.
|
||||
|
||||
struct C2E2f_Output {
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
C2E2f_Output C2E2f_passthru(float4 color : COLOR)
|
||||
{
|
||||
C2E2f_Output OUT;
|
||||
OUT.color = color;
|
||||
return OUT;
|
||||
}
|
|
@ -1,244 +0,0 @@
|
|||
#region License
|
||||
/*
|
||||
MIT License
|
||||
Copyright ©2003-2005 Tao Framework Team
|
||||
http://www.taoframework.com
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion License
|
||||
|
||||
#region Original Credits / License
|
||||
//-----------------------------------------------------------------------------
|
||||
/* 02_vertex_and_fragment_program.c - OpenGL-based example using a Cg
|
||||
vertex and a Cg fragment programs from Chapter 2 of "The Cg Tutorial"
|
||||
(Addison-Wesley, ISBN 0321194969). */
|
||||
|
||||
/* Requires the OpenGL Utility Toolkit (GLUT) and Cg runtime (version
|
||||
1.0 or higher). */
|
||||
//-----------------------------------------------------------------------------
|
||||
#endregion Original Credits / License
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Tao.FreeGlut;
|
||||
using Tao.OpenGl;
|
||||
using Tao.Cg;
|
||||
|
||||
namespace CgExamples
|
||||
{
|
||||
#region Class Documentation
|
||||
/// <summary>
|
||||
/// Displays some stars
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
#endregion Class Documentation
|
||||
public sealed class Gl_02_vertex_and_fragment_program
|
||||
{
|
||||
static string myProgramName = "02_vertex_and_fragment_program";
|
||||
static string myVertexProgramName = "C2E1v_green";
|
||||
static string myFragmentProgramName = "C2E2f_passthru";
|
||||
|
||||
static IntPtr myCgContext;
|
||||
static int myCgVertexProfile;
|
||||
static int myCgFragmentProfile;
|
||||
static IntPtr myCgVertexProgram;
|
||||
static IntPtr myCgFragmentProgram;
|
||||
static Glut.KeyboardCallback KeyboardDelegate;
|
||||
|
||||
// --- Entry Point ---
|
||||
#region Main(string[] args)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string filePath = Path.Combine("..", "..");
|
||||
string fileDirectory = "Data";
|
||||
string vertexFileName = "C2E1v_green.cg";
|
||||
string fragmentFileName = "C2E2f_passthru.cg";
|
||||
if (File.Exists(vertexFileName))
|
||||
{
|
||||
filePath = "";
|
||||
fileDirectory = "";
|
||||
}
|
||||
else if (File.Exists(Path.Combine(fileDirectory, vertexFileName)))
|
||||
{
|
||||
filePath = "";
|
||||
}
|
||||
|
||||
string myVertexProgramFileName = Path.Combine(Path.Combine(filePath, fileDirectory), vertexFileName);
|
||||
string myFragmentProgramFileName = Path.Combine(Path.Combine(filePath, fileDirectory), fragmentFileName);
|
||||
|
||||
KeyboardDelegate += Keyboard;
|
||||
Glut.glutInitWindowSize(400, 400);
|
||||
Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH);
|
||||
Glut.glutInit();
|
||||
|
||||
Glut.glutCreateWindow(myProgramName);
|
||||
Glut.glutDisplayFunc(Display);
|
||||
Glut.glutKeyboardFunc(KeyboardDelegate);
|
||||
|
||||
Gl.glClearColor(0.1f, 0.3f, 0.6f, 0.0f); /* Blue background */
|
||||
|
||||
myCgContext = Cg.cgCreateContext();
|
||||
checkForCgError("creating context");
|
||||
|
||||
myCgVertexProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_VERTEX);
|
||||
CgGl.cgGLSetOptimalOptions(myCgVertexProfile);
|
||||
checkForCgError("selecting vertex profile");
|
||||
|
||||
myCgVertexProgram =
|
||||
Cg.cgCreateProgramFromFile(
|
||||
myCgContext, /* Cg runtime context */
|
||||
Cg.CG_SOURCE, /* Program in human-readable form */
|
||||
myVertexProgramFileName, /* Name of file containing program */
|
||||
myCgVertexProfile, /* Profile: OpenGL ARB vertex program */
|
||||
myVertexProgramName, /* Entry function name */
|
||||
null); /* No extra compiler options */
|
||||
checkForCgError("creating vertex program from file");
|
||||
CgGl.cgGLLoadProgram(myCgVertexProgram);
|
||||
checkForCgError("loading vertex program");
|
||||
|
||||
myCgFragmentProfile = CgGl.cgGLGetLatestProfile(CgGl.CG_GL_FRAGMENT);
|
||||
CgGl.cgGLSetOptimalOptions(myCgFragmentProfile);
|
||||
checkForCgError("selecting fragment profile");
|
||||
|
||||
myCgFragmentProgram =
|
||||
Cg.cgCreateProgramFromFile(
|
||||
myCgContext, /* Cg runtime context */
|
||||
Cg.CG_SOURCE, /* Program in human-readable form */
|
||||
myFragmentProgramFileName, /* Name of file containing program */
|
||||
myCgFragmentProfile, /* Profile: OpenGL ARB vertex program */
|
||||
myFragmentProgramName, /* Entry function name */
|
||||
null); /* No extra compiler options */
|
||||
checkForCgError("creating fragment program from file");
|
||||
CgGl.cgGLLoadProgram(myCgFragmentProgram);
|
||||
checkForCgError("loading fragment program");
|
||||
|
||||
Glut.glutMainLoop();
|
||||
}
|
||||
|
||||
#endregion Main(string[] args)
|
||||
|
||||
static void DrawStar(float x, float y,
|
||||
int starPoints, float R, float r)
|
||||
{
|
||||
int i;
|
||||
double piOverStarPoints = Math.PI / starPoints,
|
||||
angle = 0.0;
|
||||
|
||||
Gl.glBegin(Gl.GL_TRIANGLE_FAN);
|
||||
Gl.glVertex2f(x, y); /* Center of star */
|
||||
/* Emit exterior vertices for star's points. */
|
||||
for (i = 0; i < starPoints; i++)
|
||||
{
|
||||
Gl.glVertex2f((float)(x + R * Math.Cos(angle)), (float)(y + R * Math.Sin(angle)));
|
||||
angle += piOverStarPoints;
|
||||
Gl.glVertex2f((float)(x + r * Math.Cos(angle)), (float)(y + r * Math.Sin(angle)));
|
||||
angle += piOverStarPoints;
|
||||
}
|
||||
/* End by repeating first exterior vertex of star. */
|
||||
angle = 0;
|
||||
Gl.glVertex2f((float)(x + R * Math.Cos(angle)), (float)(y + R * Math.Sin(angle)));
|
||||
Gl.glEnd();
|
||||
}
|
||||
|
||||
static void DrawStars()
|
||||
{
|
||||
/* star outer inner */
|
||||
/* x y Points radius radius */
|
||||
/* ===== ===== ====== ====== ====== */
|
||||
DrawStar(-0.1f, 0f, 5, 0.5f, 0.2f);
|
||||
DrawStar(-0.84f, 0.1f, 5, 0.3f, 0.12f);
|
||||
DrawStar(0.92f, -0.5f, 5, 0.25f, 0.11f);
|
||||
DrawStar(0.3f, 0.97f, 5, 0.3f, 0.1f);
|
||||
DrawStar(0.94f, 0.3f, 5, 0.5f, 0.2f);
|
||||
DrawStar(-0.97f, -0.8f, 5, 0.6f, 0.2f);
|
||||
}
|
||||
|
||||
static void checkForCgError(string situation)
|
||||
{
|
||||
int error;
|
||||
string errorString = Cg.cgGetLastErrorString(out error);
|
||||
|
||||
if (error != Cg.CG_NO_ERROR)
|
||||
{
|
||||
Console.WriteLine("{0}- {1}- {2}",
|
||||
myProgramName, situation, errorString);
|
||||
if (error == Cg.CG_COMPILER_ERROR)
|
||||
{
|
||||
Console.WriteLine("{0}", Cg.cgGetLastListing(myCgContext));
|
||||
}
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void Display()
|
||||
{
|
||||
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
CgGl.cgGLBindProgram(myCgVertexProgram);
|
||||
checkForCgError("binding vertex program");
|
||||
|
||||
CgGl.cgGLEnableProfile(myCgVertexProfile);
|
||||
checkForCgError("enabling vertex profile");
|
||||
|
||||
CgGl.cgGLBindProgram(myCgFragmentProgram);
|
||||
checkForCgError("binding fragment program");
|
||||
|
||||
CgGl.cgGLEnableProfile(myCgFragmentProfile);
|
||||
checkForCgError("enabling fragment profile");
|
||||
|
||||
DrawStars();
|
||||
|
||||
CgGl.cgGLDisableProfile(myCgVertexProfile);
|
||||
checkForCgError("disabling vertex profile");
|
||||
|
||||
CgGl.cgGLDisableProfile(myCgFragmentProfile);
|
||||
checkForCgError("disabling fragment profile");
|
||||
|
||||
Glut.glutSwapBuffers();
|
||||
}
|
||||
|
||||
#region Keyboard()
|
||||
/// <summary>
|
||||
/// Exits application.
|
||||
/// </summary>
|
||||
private static void Keyboard(byte key, int x, int y)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case 27:
|
||||
Cg.cgDestroyProgram(myCgVertexProgram);
|
||||
Cg.cgDestroyProgram(myCgFragmentProgram);
|
||||
Cg.cgDestroyContext(myCgContext);
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion Exit()
|
||||
}
|
||||
}
|
|
@ -290,7 +290,7 @@
|
|||
<OptimizeCode>false</OptimizeCode>
|
||||
<AllowUnsafe>false</AllowUnsafe>
|
||||
<OutputPath>bin/Debug</OutputPath>
|
||||
<KeyFile>../../src/Tao.OpenGl/Tao.OpenGl.snk</KeyFile>
|
||||
<KeyFile>../../src/Tao.Glfw/Tao.Glfw.snk</KeyFile>
|
||||
<DebugInformation>true</DebugInformation>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
@ -300,7 +300,7 @@
|
|||
<OptimizeCode>true</OptimizeCode>
|
||||
<AllowUnsafe>false</AllowUnsafe>
|
||||
<OutputPath>bin/Release</OutputPath>
|
||||
<KeyFile>../../src/Tao.OpenGl/Tao.OpenGl.snk</KeyFile>
|
||||
<KeyFile>../../src/Tao.Glfw/Tao.Glfw.snk</KeyFile>
|
||||
<DebugInformation>false</DebugInformation>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
@ -455,14 +455,14 @@
|
|||
</Match>
|
||||
</Files>
|
||||
</Project>
|
||||
<Project name="CgExamples.Gl_01_vertex_program" path="../../examples/CgExamples/Gl_01_vertex_program" language="C#" type="WinExe" startupObject="CgExamples.Gl_01_vertex_program">
|
||||
<Project name="CgExamples" path="../../examples/CgExamples" language="C#" type="WinExe" startupObject="CgExamples.Program" designerFolder="Properties">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<CompilerDefines>DEBUG;TRACE;WIN32</CompilerDefines>
|
||||
<OptimizeCode>false</OptimizeCode>
|
||||
<AllowUnsafe>false</AllowUnsafe>
|
||||
<OutputPath>bin/Debug</OutputPath>
|
||||
<KeyFile>../../../src/Tao.Cg/Tao.Cg.snk</KeyFile>
|
||||
<KeyFile>../../src/Tao.Cg/Tao.Cg.snk</KeyFile>
|
||||
<DebugInformation>true</DebugInformation>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
@ -471,48 +471,23 @@
|
|||
<CompilerDefines>TRACE;WIN32</CompilerDefines>
|
||||
<OptimizeCode>true</OptimizeCode>
|
||||
<AllowUnsafe>false</AllowUnsafe>
|
||||
<KeyFile>../../../src/Tao.Cg/Tao.Cg.snk</KeyFile>
|
||||
<OutputPath>bin/Release</OutputPath>
|
||||
<KeyFile>../../src/Tao.Cg/Tao.Cg.snk</KeyFile>
|
||||
<DebugInformation>false</DebugInformation>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Reference name="System" />
|
||||
<Reference name="System.Windows.Forms" />
|
||||
<Reference name="System.Data" />
|
||||
<Reference name="System.Drawing" />
|
||||
<Reference name="Tao.Cg" />
|
||||
<Reference name="Tao.OpenGl" />
|
||||
<Reference name="Tao.FreeGlut" />
|
||||
<Files>
|
||||
<Match path="." pattern="*.cs" recurse="true"/>
|
||||
</Files>
|
||||
</Project>
|
||||
<Project name="CgExamples.Gl_02_vertex_and_fragment_program" path="../../examples/CgExamples/Gl_02_vertex_and_fragment_program" language="C#" type="WinExe" startupObject="CgExamples.Gl_02_vertex_and_fragment_program">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<CompilerDefines>DEBUG;TRACE;WIN32</CompilerDefines>
|
||||
<OptimizeCode>false</OptimizeCode>
|
||||
<AllowUnsafe>false</AllowUnsafe>
|
||||
<OutputPath>bin/Debug</OutputPath>
|
||||
<KeyFile>../../../src/Tao.Cg/Tao.Cg.snk</KeyFile>
|
||||
<DebugInformation>true</DebugInformation>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Configuration name="Release">
|
||||
<Options>
|
||||
<CompilerDefines>TRACE;WIN32</CompilerDefines>
|
||||
<OptimizeCode>true</OptimizeCode>
|
||||
<AllowUnsafe>false</AllowUnsafe>
|
||||
<KeyFile>../../../src/Tao.Cg/Tao.Cg.snk</KeyFile>
|
||||
<OutputPath>bin/Release</OutputPath>
|
||||
<DebugInformation>false</DebugInformation>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Reference name="System" />
|
||||
<Reference name="Tao.Cg" />
|
||||
<Reference name="Tao.OpenGl" />
|
||||
|
||||
|
||||
<Reference name="Tao.FreeGlut" />
|
||||
<Files>
|
||||
<Match path="." pattern="*.cs" recurse="true"/>
|
||||
<File subType="Form" resourceName="CgExamples">CgExamples.cs</File>
|
||||
<Match path="." pattern="*.cs" recurse="true">
|
||||
<Exclude name="CgExamples.cs"/>
|
||||
</Match>
|
||||
</Files>
|
||||
</Project>
|
||||
<Project name="GlslExamples.Lesson01" path="../../examples/GlslExamples/Lesson01" language="C#" type="WinExe" startupObject="GlslExamples.Lesson01" designerFolder="Properties">
|
||||
|
|
Загрузка…
Ссылка в новой задаче