컴파일에 필요한 dll 파일들은 CsGL 을 다운로드하면 들어 있다.

이전에 올린 C 언어용 소스와 Python 언어용 소스와 비교하면 이해할 수 있을 것이다.

 

#region BSD License
/*
 BSD License
Copyright (c) 2002, Randy Ridge, The CsGL Development Team
http://csgl.sourceforge.net/
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of The CsGL Development Team nor the names of its
   contributors may be used to endorse or promote products derived from this
   software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   POSSIBILITY OF SUCH DAMAGE.
 */
#endregion BSD License

#region Original Credits / License
/*
 * Copyright (c) 1993-1997, Silicon Graphics, Inc.
 * ALL RIGHTS RESERVED
 * Permission to use, copy, modify, and distribute this software for
 * any purpose and without fee is hereby granted, provided that the above
 * copyright notice appear in all copies and that both the copyright notice
 * and this permission notice appear in supporting documentation, and that
 * the name of Silicon Graphics, Inc. not be used in advertising
 * or publicity pertaining to distribution of the software without specific,
 * written prior permission.
 *
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * US Government Users Restricted Rights
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
 * clause at DFARS 252.227-7013 and/or in similar or successor
 * clauses in the FAR or the DOD or NASA FAR Supplement.
 * Unpublished-- rights reserved under the copyright laws of the
 * United States.  Contractor/manufacturer is Silicon Graphics,
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
 *
 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
 */
#endregion Original Credits / License

using CsGL.OpenGL;
using CsGL.Pointers;
using CsGL.Util;
using System;
using CsGL.Basecode;
using System.Reflection;

#region AssemblyInfo
[assembly: AssemblyCompany("The CsGL Development Team (http://csgl.sourceforge.net)")]
[assembly: AssemblyCopyright("2002 The CsGL Development Team (http://csgl.sourceforge.net)")]
[assembly: AssemblyDescription("Redbook Teapots")]
[assembly: AssemblyProduct("Redbook Teapots")]
[assembly: AssemblyTitle("Redbook Teapots")]
[assembly: AssemblyVersion("1.0.0.0")]
#endregion AssemblyInfo

namespace RedbookExamples {
 /// <summary>
 /// Redbook Teapots -- Material Properties (http://www.opengl.org/developers/code/examples/redbook/redbook.html)
 /// Implemented In C# By The CsGL Development Team (http://csgl.sourceforge.net)
 /// </summary>
 public sealed class RedbookTeapots : Model {
  // --- Fields ---
  #region Private Fields
  private static uint teapotList;
  #endregion Private Fields

  #region Public Properties
  /// <summary>
  /// Example title.
  /// </summary>
  public override string Title {
   get {
    return "Redbook Teapots -- Material Properties";
   }
  }

  /// <summary>
  /// Example description.
  /// </summary>
  public override string Description {
   get {
    return "This program demonstrates lots of material properties.  A single light source illuminates the objects.";
   }
  }

  /// <summary>
  /// Example URL.
  /// </summary>
  public override string Url {
   get {
    return "http://www.opengl.org/developers/code/examples/redbook/redbook.html";
   }
  }
  #endregion Public Properties

  // --- Entry Point ---
  #region Main()
  /// <summary>
  /// Application's entry point, runs this Redbook example.
  /// </summary>
  public static void Main() {              // Entry Point
   App.Run(new RedbookTeapots());            // Run Our Example As A Windows Forms Application
  }
  #endregion Main()

  // --- Basecode Methods ---
  #region Initialize()
  /// <summary>
  /// Overrides OpenGL's initialization.
  /// </summary>
  public override void Initialize() {
   // Initialize depth buffer, projection matrix, light source, and lighting
   // model.  Do not specify a material property here
   float[] ambient = {0.0f, 0.0f, 0.0f, 1.0f};
   float[] diffuse = {1.0f, 1.0f, 1.0f, 1.0f};
   float[] specular = {1.0f, 1.0f, 1.0f, 1.0f};
   float[] position = {0.0f, 3.0f, 3.0f, 0.0f};
   float[] lmodel_ambient = {0.2f, 0.2f, 0.2f, 1.0f};
   float[] local_view = {0.0f};

   glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
   glLightfv(GL_LIGHT0, GL_POSITION, position);
   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
   glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);

   glFrontFace(GL_CW);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_AUTO_NORMAL);
   glEnable(GL_NORMALIZE);
   glEnable(GL_DEPTH_TEST);
   // be efficient--make teapot display list
   teapotList = glGenLists(1);
   glNewList(teapotList, GL_COMPILE);
    glutSolidTeapot(1.0f);
   glEndList ();
   
   System.Console.WriteLine(OpenGLContext.Current.PixelFormat);
   System.Console.WriteLine(OpenGLContext.Current.PixelFormat.flags);
   System.Console.WriteLine((uint)OpenGLContext.Current.PixelFormat.flags);
  }
  #endregion Initialize()

  #region Draw()
  /// <summary>
  /// Draws Redbook Teapots scene.
  /// </summary>
  public override void Draw() {
   long t = System.DateTime.Now.Ticks;
   // Here's Where We Do All The Drawing
   // First column:  emerald, jade, obsidian, pearl, ruby, turquoise
   // 2nd column:  brass, bronze, chrome, copper, gold, silver
   // 3rd column:  black, cyan, green, red, white, yellow plastic
   // 4th column:  black, cyan, green, red, white, yellow rubber
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   RenderTeapot(2.0f, 17.0f, 0.0215f, 0.1745f, 0.0215f, 0.07568f, 0.61424f, 0.07568f, 0.633f, 0.727811f, 0.633f, 0.6f);
   RenderTeapot(2.0f, 14.0f, 0.135f, 0.2225f, 0.1575f, 0.54f, 0.89f, 0.63f, 0.316228f, 0.316228f, 0.316228f, 0.1f);
   RenderTeapot(2.0f, 11.0f, 0.05375f, 0.05f, 0.06625f, 0.18275f, 0.17f, 0.22525f, 0.332741f, 0.328634f, 0.346435f, 0.3f);
   RenderTeapot(2.0f, 8.0f, 0.25f, 0.20725f, 0.20725f, 1.0f, 0.829f, 0.829f, 0.296648f, 0.296648f, 0.296648f, 0.088f);
   RenderTeapot(2.0f, 5.0f, 0.1745f, 0.01175f, 0.01175f, 0.61424f, 0.04136f, 0.04136f, 0.727811f, 0.626959f, 0.626959f, 0.6f);
   RenderTeapot(2.0f, 2.0f, 0.1f, 0.18725f, 0.1745f, 0.396f, 0.74151f, 0.69102f, 0.297254f, 0.30829f, 0.306678f, 0.1f);
   RenderTeapot(6.0f, 17.0f, 0.329412f, 0.223529f, 0.027451f, 0.780392f, 0.568627f, 0.113725f, 0.992157f, 0.941176f, 0.807843f, 0.21794872f);
   RenderTeapot(6.0f, 14.0f, 0.2125f, 0.1275f, 0.054f, 0.714f, 0.4284f, 0.18144f, 0.393548f, 0.271906f, 0.166721f, 0.2f);
   RenderTeapot(6.0f, 11.0f, 0.25f, 0.25f, 0.25f, 0.4f, 0.4f, 0.4f, 0.774597f, 0.774597f, 0.774597f, 0.6f);
   RenderTeapot(6.0f, 8.0f, 0.19125f, 0.0735f, 0.0225f, 0.7038f, 0.27048f, 0.0828f, 0.256777f, 0.137622f, 0.086014f, 0.1f);
   RenderTeapot(6.0f, 5.0f, 0.24725f, 0.1995f, 0.0745f, 0.75164f, 0.60648f, 0.22648f, 0.628281f, 0.555802f, 0.366065f, 0.4f);
   RenderTeapot(6.0f, 2.0f, 0.19225f, 0.19225f, 0.19225f, 0.50754f, 0.50754f, 0.50754f, 0.508273f, 0.508273f, 0.508273f, 0.4f);
   RenderTeapot(10.0f, 17.0f, 0.0f, 0.0f, 0.0f, 0.01f, 0.01f, 0.01f, 0.50f, 0.50f, 0.50f, 0.25f);
   RenderTeapot(10.0f, 14.0f, 0.0f, 0.1f, 0.06f, 0.0f, 0.50980392f, 0.50980392f, 0.50196078f, 0.50196078f, 0.50196078f, 0.25f);
   RenderTeapot(10.0f, 11.0f, 0.0f, 0.0f, 0.0f, 0.1f, 0.35f, 0.1f, 0.45f, 0.55f, 0.45f, 0.25f);
   RenderTeapot(10.0f, 8.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.7f, 0.6f, 0.6f, 0.25f);
   RenderTeapot(10.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.55f, 0.55f, 0.55f, 0.70f, 0.70f, 0.70f, 0.25f);
   RenderTeapot(10.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.0f, 0.60f, 0.60f, 0.50f, 0.25f);
   RenderTeapot(14.0f, 17.0f, 0.02f, 0.02f, 0.02f, 0.01f, 0.01f, 0.01f, 0.4f, 0.4f, 0.4f, 0.078125f);
   RenderTeapot(14.0f, 14.0f, 0.0f, 0.05f, 0.05f, 0.4f, 0.5f, 0.5f, 0.04f, 0.7f, 0.7f, 0.078125f);
   RenderTeapot(14.0f, 11.0f, 0.0f, 0.05f, 0.0f, 0.4f, 0.5f, 0.4f, 0.04f, 0.7f, 0.04f, 0.078125f);
   RenderTeapot(14.0f, 8.0f, 0.05f, 0.0f, 0.0f, 0.5f, 0.4f, 0.4f, 0.7f, 0.04f, 0.04f, 0.078125f);
   RenderTeapot(14.0f, 5.0f, 0.05f, 0.05f, 0.05f, 0.5f, 0.5f, 0.5f, 0.7f, 0.7f, 0.7f, 0.078125f);
   RenderTeapot(14.0f, 2.0f, 0.05f, 0.05f, 0.0f, 0.5f, 0.5f, 0.4f, 0.7f, 0.7f, 0.04f, 0.078125f);

   glFlush();
   t = System.DateTime.Now.Ticks - t;
   System.Console.WriteLine("time "+(1e-7*t));
  }
  #endregion Draw()

  #region Reshape(int width, int height)
  /// <summary>
  /// Overrides OpenGL reshaping.
  /// </summary>
  /// <param name="width">New width.</param>
  /// <param name="height">New height.</param>
  public override void Reshape(int width, int height) {       // Resize And Initialize The GL Window
   glViewport(0, 0, width, height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   if(width <= height) {
    glOrtho(0.0f, 16.0f, 0.0f, 16.0f * (float) height / (float) width, -10.0f, 10.0f);
   }
   else {
    glOrtho(0.0f, 16.0f * (float) width / (float) height, 0.0f, 16.0f, -10.0f, 10.0f);
   }
   glMatrixMode(GL_MODELVIEW);
  }
  #endregion Reshape(int width, int height)

  // --- Example Methods ---
  #region RenderTeapot(float x, float y, float ambr, float ambg, float ambb, float difr, float difg, float difb, float specr, float specg, float specb, float shine)
  /// <summary>
  /// Renders a teapot into position with the supplied properties.
  /// </summary>
  /// <param name="x">X coordinate.</param>
  /// <param name="y">Y coordinate.</param>
  /// <param name="ambr">Ambient red.</param>
  /// <param name="ambg">Ambient green.</param>
  /// <param name="ambb">Ambient blue.</param>
  /// <param name="difr">Diffuse red.</param>
  /// <param name="difg">Diffuse green.</param>
  /// <param name="difb">Diffuse blue.</param>
  /// <param name="specr">Specular red.</param>
  /// <param name="specg">Specular green.</param>
  /// <param name="specb">Specular blue.</param>
  /// <param name="shine">Shininess.</param>
  private static void RenderTeapot(float x, float y, float ambr, float ambg, float ambb, float difr, float difg, float difb, float specr, float specg, float specb, float shine)
  {
   float[] mat = new float[4];
   glPushMatrix();
    glTranslatef(x, y, 0.0f);
    mat[0] = ambr;
    mat[1] = ambg;
    mat[2] = ambb;
    mat[3] = 1.0f;
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat);

    mat[0] = difr;
    mat[1] = difg;
    mat[2] = difb;
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);

    mat[0] = specr;
    mat[1] = specg;
    mat[2] = specb;
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat);

    glMaterialf(GL_FRONT, GL_SHININESS, shine * 128.0f);
    glCallList(teapotList);
   glPopMatrix();
  }
  #endregion RenderTeapot(float x, float y, float ambr, float ambg, float ambb, float difr, float difg, float difb, float specr, float specg, float specb, float shine)
 }
}

 

컴파일하기: csc RedbookTeapots.cs /r:csgl.dll,CsGL.Basecode.dll

실행하기: RedbookTeapots

실행 결과:

 

 

 

Posted by Scripter
,