<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Comment Feed for Channel 9 - Asteroids, C#, 3D and OpenGL</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL/RSS"></atom:link>
	<image>
		<url>http://files.channel9.msdn.com/thumbnail/2a9ffea8-d499-4e74-b58e-8f64e9ef042f.png</url>
		<title>Channel 9 - Asteroids, C#, 3D and OpenGL</title>
		<link></link>
	</image>
	<description>Today&#39;s project is a simple example of using OpenGL, C#/WinForm to build a introductory game. What I liked about it is that it really is pretty simple, simple to follow the code, simple to understand and simply easy to get started with... A Basic 3D Asteroid Game in openGL with C#This article is intended for beginners who want to start with 3D game programming and don’t know where to start. It is programmed in Opengl using VS 2008 and a small graphic engine I made myself called Shadowengine. It has the basics of what a game should have: a Score, levels of difficulty and a life counter. All this is written in a small number of code lines, with the objective of being simple and understandable. The first problem I had to achieve is the scene to look like outer space. For that issue, I set the background color to black. In opengl, it is set this way: ... The score is a number which increases over time and it grows faster everytime I pass a level. The level increases every 450 frames. The last issue I had to address is the problem of asteroid collision. I make for the ship three positions (one for the ship and two for the wings) and every once in a while, I check the distance between all the asteroids and those three positions. If it is under a predefined value, I execute the collision event. The project has 6 classes: AsteroidGenerator.cs - It handles the creation of asteroids in random places and with random sizes and speeds. It also has the method to query whether or not there has been a collision between the spaceship and an asteroid. Asteroid.cs - It handles all concerning an asteroid such as the movement, texture selection, drawing, among others. Star.cs - It has a method to create random white points and to draw them. Camera.cs - It handles the selection of the user camera and to set the right perspective view of the scene. SpaceShip.cs - This class contains all methods and attributes regarding the spaceship, such as movement, drawing, etc. Controller.cs - This class manages the game creation, game logic and contains all the classes needed to run the game. Here is a portion of code: ... Main.cs - This is the form which contains this visual components of the game. It contains the controller class and gives the player information through proper windows controls. It has a timer to periodically draw the scene and has the code for texture and object loading. ... While written for VS2008, for me it loaded in VS2010 just fine (once it converted). Once loaded it compiled and ran the first time...   The game is very simple. Using WASD you move your ship to avoid the oncoming asteroids. And while the comments/strings are not in English the code is easy enough to understand; public Main()
  {
      InitializeComponent();
      hdc = (uint)pnlViewPort.Handle;
      string error = &amp;quot;&amp;quot;;
      //Comando de inicializacion de la ventana grafica
      OpenGLControl.OpenGLInit(ref hdc, pnlViewPort.Width, pnlViewPort.Height, ref error);
      //inicia la posicion de la camara asi como define en angulo de perspectiva,etc etc
      controladora.Camara.SetPerspective();
      if (error != &amp;quot;&amp;quot;)
      {
          MessageBox.Show(&amp;quot;Something happened&amp;quot;);
      }

      #region lights

      //Configuracion de las luces
      float[] materialAmbient = { 0.5F, 0.5F, 0.5F, 1.0F };
      float[] materialDiffuse = { 1f, 1f, 1f, 1.0f };
      float[] materialSpecular = { 1.0F, 1.0F, 1.0F, 1.0F };
      //brillo del material
      float[] materialShininess = { 1.0F };
      //posicion de la luz
      float[] ambientLightPosition = { 10F, -10F, 10F, 1.0F };
      // intensidad de la luz en RGB
      float[] lightAmbient = { 0.85F, 0.85F, 0.85F, 1.0F };

      Lighting.MaterialAmbient = materialAmbient;
      Lighting.MaterialDiffuse = materialDiffuse;
      Lighting.MaterialSpecular = materialSpecular;
      Lighting.MaterialShininess = materialShininess;
      Lighting.AmbientLightPosition = ambientLightPosition;
      Lighting.LightAmbient = lightAmbient;

      #endregion

      //Habilita las luces
      Lighting.SetupLighting();
      //cargar texturas
      ContentManager.SetModelList(&amp;quot;modelos\\&amp;quot;);
      ContentManager.LoadModels();
      ContentManager.SetTextureList(&amp;quot;texturas\\&amp;quot;);
      ContentManager.LoadTextures();
      //AudioPlayback.SoundDir = &amp;quot;sonidos\\&amp;quot;;
      //AudioPlayback.LoadSounds();
      controladora.CreateObjects();
      //Color de fondo
      Gl.glClearColor(0, 0, 0, 1);//red green blue alpha 
      Gl.glShadeModel(Gl.GL_SMOOTH);  
  }

  private void tmrPaint_Tick(object sender, EventArgs e)
  {
      // limpia opengl
      Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
      //dibuja la escena
      controladora.DrawScene();
      //cambia los buffer
      Winapi.SwapBuffers(hdc);
      //termina de pintar
      Gl.glFlush();

      if (started)
      {
          score &amp;#43;= 1;
          count1&amp;#43;&amp;#43;;
          count2&amp;#43;&amp;#43;;
          levelCount&amp;#43;&amp;#43;;
          if (levelCount == 450)
          {
              level&amp;#43;&amp;#43;;
              AsteroidGenerator.GenerateAsteroid(35, false);
              lblLevel.Text = level.ToString();
              levelCount = 0;
          }
          if (count1 == 4)
          {
              lblScore.Text = score.ToString();
              count1 = 0;
              lives = controladora.Nave.Vidas;
          }
          if (count2 == 20)
          {
              ShowLife(lives);
              count2 = 0;
              if (lives == 0)
              {
                  started = false; 
                  MessageBox.Show(&amp;quot;Game Over&amp;quot;);
                  controladora.ResetGame();
                  score = 0;
                  level = 1;
                  lives = 3;
                  started = true;
                  count1 = 0;
                  count2 = 0;
                  lblLevel.Text = level.ToString();   
              }
          }
      }
  }
 If you&#39;ve thought about writing a 3D game, be it space or not, this project might be a good starting place for you... </description>
	<link></link>
	<language>en</language>
	<pubDate>Sat, 18 May 2013 17:22:06 GMT</pubDate>
	<lastBuildDate>Sat, 18 May 2013 17:22:06 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[<p>since this is in C# could this be converted to a Windows Phone game?</p><p>posted by Omega_Ra</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634655179503948247</link>
		<pubDate>Wed, 22 Feb 2012 14:32:30 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634655179503948247</guid>
		<dc:creator>Omega_Ra</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[Windows Phone doesn&#39;t support OpenGL, does it&#63;  If not, then the game would have to be converted to Directx in order to be ported to WP7.<p>posted by JasonK</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634655397378331584</link>
		<pubDate>Wed, 22 Feb 2012 20:35:37 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634655397378331584</guid>
		<dc:creator>JasonK</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[<p>Yup, &quot;OpenGL ES&quot; <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif?v=c9' alt='Wink' /> But on Windows Phone? ermm... don't think so, no.</p><p>posted by Gunslinger_x</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634655425265365749</link>
		<pubDate>Wed, 22 Feb 2012 21:22:06 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634655425265365749</guid>
		<dc:creator>Gunslinger_x</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[<p>Does anyone else find it poignant that this sample is using OpenGL rather than DirectX?</p><p>Microsoft should actively support and promote a world class .NET API for DirectX running on desktop PCs.</p><p>posted by geoMcC</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634664951264378916</link>
		<pubDate>Sun, 04 Mar 2012 21:58:46 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634664951264378916</guid>
		<dc:creator>geoMcC</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[<p>Does anyone else find it poignant that this project uses OpenGL rather than DirectX?</p><p>Microsoft should actively support and promote a world class .NET API for DirectX.</p><p>posted by geoMcC</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634664958427037574</link>
		<pubDate>Sun, 04 Mar 2012 22:10:42 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634664958427037574</guid>
		<dc:creator>geoMcC</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[Does anyone else realize the lives are the original starcraft icon&#63;<p>posted by Drinkfloridaoj</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634665929364960726</link>
		<pubDate>Tue, 06 Mar 2012 01:08:56 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634665929364960726</guid>
		<dc:creator>Drinkfloridaoj</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[<p>@<a href="/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634664958427037574?areaType=Blogs&amp;areaName=Coding4FunBlog">geoMcC</a>: I think it's good that you can have your pick of 3D platforms when working with C# and I welcome OpenGL to the pool. Besides, I though Microsoft were in fact actively supporting and promoting XNA Game Studio - the official&nbsp;DirectX API for managed code. Whether XNA is &quot;world class&quot;, I honestly wouldn't know...</p><p>posted by helgihaf</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634666211250947215</link>
		<pubDate>Tue, 06 Mar 2012 08:58:45 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634666211250947215</guid>
		<dc:creator>helgihaf</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[I made that sample game it was for a 3d project in school if you liked visit my dev blog www.vasilydev.blogspot.com<p>posted by Vasily Tserekh</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634666929510394079</link>
		<pubDate>Wed, 07 Mar 2012 04:55:51 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634666929510394079</guid>
		<dc:creator>Vasily Tserekh</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[呵呵呵<p>posted by Chairperson</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634667142767908824</link>
		<pubDate>Wed, 07 Mar 2012 10:51:16 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634667142767908824</guid>
		<dc:creator>Chairperson</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[<p>大家好呀！</p><p>posted by Chairperson</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634667143559390268</link>
		<pubDate>Wed, 07 Mar 2012 10:52:35 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634667143559390268</guid>
		<dc:creator>Chairperson</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[Is there any possibility to get sources of this game&#63;<p>posted by WhiteAngel</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634669764622193284</link>
		<pubDate>Sat, 10 Mar 2012 11:41:02 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634669764622193284</guid>
		<dc:creator>WhiteAngel</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[<p>@<a href="/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634669764622193284?areaType=Blogs&amp;areaName=Coding4FunBlog">WhiteAngel</a>:If you click through to the article, you can download it there...</p><p>posted by gduncan411</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634669955493787274</link>
		<pubDate>Sat, 10 Mar 2012 16:59:09 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634669955493787274</guid>
		<dc:creator>gduncan411</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[ .<p>posted by avatar hd</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634685010200504286</link>
		<pubDate>Wed, 28 Mar 2012 03:10:20 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634685010200504286</guid>
		<dc:creator>avatar hd</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[Thanks, I learn C&#35; and I need this code to research.<br><br>I can&#39;t use &#34;quote&#34; function. why &#63;<p>posted by avatar hd</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634685011516963113</link>
		<pubDate>Wed, 28 Mar 2012 03:12:31 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634685011516963113</guid>
		<dc:creator>avatar hd</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[This is the best example Program I have seen on this website<p>posted by Stephen</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634685591905447391</link>
		<pubDate>Wed, 28 Mar 2012 19:19:50 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634685591905447391</guid>
		<dc:creator>Stephen</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[i made another game demo its about a car race<br>http&#58;&#47;&#47;www.codeproject.com&#47;Tips&#47;357063&#47;A-very-simple-car-race-game-in-Csharp-and-OpenGL<p>posted by Vasily Tserekh</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634689060056414719</link>
		<pubDate>Sun, 01 Apr 2012 19:40:05 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634689060056414719</guid>
		<dc:creator>Vasily Tserekh</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[This really is a very good demonstration of C&#35; programming and OpenGL.<br><br><p>posted by Herbit</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634699146091966834</link>
		<pubDate>Fri, 13 Apr 2012 11:50:09 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634699146091966834</guid>
		<dc:creator>Herbit</dc:creator>
	</item>
	<item>
		<title>Re: Asteroids, C#, 3D and OpenGL</title>
		<description>
			<![CDATA[Hello&#33; Where I can download OpenGL libs&#63; <p>posted by TOXA</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634702737415839493</link>
		<pubDate>Tue, 17 Apr 2012 15:35:41 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Asteroids-C-3D-and-OpenGL#c634702737415839493</guid>
		<dc:creator>TOXA</dc:creator>
	</item>
</channel>
</rss>