示例#1
0
 public static void Initialize(int width, int height)
 {
     Scenes = new Dictionary<string, SceneBase>();
     #if PC
     window = new GameWindow(width, height);
     cgContext = Context.Create();
     window.RenderFrame += (a, b) =>
     {
         curScene.Render(b.Time);
     };
     window.UpdateFrame += (a, b) =>
     {
         curScene.Update(b.Time);
     };
     window.Run(30, 30);
     #elif PSM
     graphics = new GraphicsContext(
         width, height, PixelFormat.Rgba, PixelFormat.Depth24, MultiSampleMode.Msaa2x);
     #endif
 }
示例#2
0
 public static Parameter Create(Context context, ParameterType type)
 {
     return context.CreateParameter(type);
 }
示例#3
0
文件: Obj.cs 项目: corngood/cgnet
 public static Obj CreateFromFile(Context context, ProgramType programType, string sourceFile, ProfileType profile, params string[] args)
 {
     return context.CreateObjFromFile(programType, sourceFile, profile, args);
 }
示例#4
0
文件: Effect.cs 项目: corngood/cgnet
 public static Effect CreateFromFile(Context context, string filename, params string[] args)
 {
     return context.CreateEffectFromFile(filename, args);
 }
示例#5
0
文件: Effect.cs 项目: corngood/cgnet
 public static Effect Create(Context context, string code, params string[] args)
 {
     return context.CreateEffect(code, args);
 }
        public override void Start()
        {
            base.Start();
            var form = new RenderForm("02_vertex_and_fragment_program");
            this.device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters
                                                                                                                                {
                                                                                                                                    BackBufferWidth = form.ClientSize.Width,
                                                                                                                                    BackBufferHeight = form.ClientSize.Height
                                                                                                                                });
            int vertexCount = 0;

            for (int i = 0; i < MyStarCount; i++)
            {
                vertexCount += myStarList[i].Points * 2 + 2;
            }

            vertexBuffer = new VertexBuffer(device, vertexCount * 12, Usage.WriteOnly, VertexFormat.Position, Pool.Default);

            Vector3[] starVertices = new Vector3[vertexCount];
            var dataStream = vertexBuffer.Lock(0, 0, LockFlags.Discard);
            for (int i = 0, n = 0; i < myStarList.Length; i++)
            {
                double piOverStarPoints = 3.14159 / myStarList[i].Points;
                float x = myStarList[i].X,
                      y = myStarList[i].Y,
                      outerRadius = myStarList[i].OuterRadius,
                      r = myStarList[i].InnerRadius;
                double angle = 0.0;

                /* Center of star */
                starVertices[n++] = new Vector3(x, y, 0);
                /* Emit exterior vertices for star's points. */
                for (int j = 0; j < myStarList[i].Points; j++)
                {
                    starVertices[n++] = new Vector3(x + outerRadius * (float)Math.Cos(angle), y + outerRadius * (float)Math.Sin(angle), 0);
                    angle -= piOverStarPoints;
                    starVertices[n++] = new Vector3(x + r * (float)Math.Cos(angle), y + r * (float)Math.Sin(angle), 0);
                    angle -= piOverStarPoints;
                }
                /* End by repeating first exterior vertex of star. */
                angle = 0;
                starVertices[n++] = new Vector3(x + outerRadius * (float)Math.Cos(angle), y + outerRadius * (float)Math.Sin(angle), 0);
            }
            dataStream.WriteRange(starVertices);
            dataStream.Position = 0;
            vertexBuffer.Unlock();

            this.CgContext = Context.Create();
            this.CgContext.ParameterSettingMode = ParameterSettingMode.Deferred;
            this.CreateCgPrograms();

            form.Show();
            while (form.Visible)
            {
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0.1f, 0.3f, 0.6f), 1.0f, 0);
                device.BeginScene();

                vertexProgram.Bind();
                fragmentProgram.Bind();

                /* Render the triangle. */
                device.SetStreamSource(0, vertexBuffer, 0, 12);
                device.VertexFormat = VertexFormat.Position;
                for (int i = 0; i < MyStarCount; i++)
                {
                    device.DrawPrimitives(PrimitiveType.TriangleFan, i * 12, 10);
                }
                device.EndScene();
                device.Present();
                Application.DoEvents();
            }

            fragmentProgram.Dispose();
            vertexProgram.Dispose();
            this.CgContext.Dispose();
            foreach (var item in ObjectTable.Objects)
            {
                item.Dispose();
            }
        }
示例#7
0
 public static State CreateArrayState(Context context, string name, ParameterType type, int elementCount)
 {
     return context.CreateArrayState(name, type, elementCount);
 }
示例#8
0
 public static State Create(Context context, string name, ParameterType type)
 {
     return context.CreateState(name, type);
 }
示例#9
0
 /// <summary>
 /// Create a buffer object managed by the runtime.
 /// </summary>
 /// <param name="context">The context to which the new buffer will be added.</param>
 /// <param name="size">The length in bytes of the buffer to create.</param>
 /// <param name="data">Pointer to inital buffer data. NULL will fill the buffer with zero.</param>
 /// <param name="bufferUsage">Indicates the intended usage method of the buffer.</param>
 /// <returns>Returns a Buffer on success.</returns>
 public static Buffer Create(Context context, int size, IntPtr data, BufferUsage bufferUsage)
 {
     return new Buffer(NativeMethods.cgCreateBuffer(context.Handle, size, data, bufferUsage), true);
 }
示例#10
0
文件: Program.cs 项目: corngood/cgnet
 public static Program CreateFromFile(Context context, ProgramType type, string file, ProfileType profile, string entry, params string[] args)
 {
     return context.CreateProgramFromFile(type, file, profile, entry, args);
 }