<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>quixotic project blog &#187; code</title>
	<atom:link href="http://michi.ist.inspirationslos.de/lang/en/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://michi.ist.inspirationslos.de</link>
	<description></description>
	<lastBuildDate>Sat, 06 Feb 2010 10:11:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Erstes Meggy Jr Programm</title>
		<link>http://michi.ist.inspirationslos.de/lang/en/2009/04/05/erstes-meggy-jr-programm</link>
		<comments>http://michi.ist.inspirationslos.de/lang/en/2009/04/05/erstes-meggy-jr-programm#comments</comments>
		<pubDate>Sun, 05 Apr 2009 16:34:25 +0000</pubDate>
		<dc:creator>michi</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[meggy]]></category>
		<category><![CDATA[meggy jr rgb]]></category>

		<guid isPermaLink="false">http://michi.ist.inspirationslos.de/?p=114</guid>
		<description><![CDATA[
Today I finished my first Meggy Jr program. The programming with the Arduino IDE was easy as expected. I wrote a simple Color Chooser application that let&#8217;s the user explore the variety of colors available on Meggy Jr.  Meggy Jr&#8217;s &#60;em&#62;Simple Library&#60;/em&#62; only knows 16 predefined colors. It is possible though to define more colors [...]]]></description>
			<content:encoded><![CDATA[
<p>Today I finished my first Meggy Jr program. The programming with the Arduino IDE was easy as expected. I wrote a simple Color Chooser application that let&#8217;s the user explore the variety of colors available on Meggy Jr.  Meggy Jr&#8217;s &lt;em&gt;Simple Library&lt;/em&gt; only knows 16 predefined colors. It is possible though to define more colors with the Method <code>EditColor(byte color, byte r, byte g, byte b)</code> in which you simply specify the amount of red, green and blue you want in your final color. Each component takes a byte as input and therefore Meggy can display 4096 different colors, theoretically. In practice you will find that even small values for the blue component will make the resulting color blue.</p>
<p>In my last <a href="http://michi.ist.inspirationslos.de/2009/04/04/meggy-jr-rgb/" target="_self">blog entry</a> I mentioned that it is possibly to write data to the pc via a serial connection. The Color Chooser makes use of this feature and writes back the current color and its components to the pc so you can use the values in another project.</p>
<p>I made a video of the running application. The quality sucks, but you&#8217;ll get the idea:</p>
<p><object width="425" height="344" data="http://www.youtube.com/v/kGUu1PVKy5c&amp;hl=de&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/kGUu1PVKy5c&amp;hl=de&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></p>

<p>During the programming I used the Meggy Jr Programming Guide, a pretty helpful document. You can get it at the <a href="http://www.evilmadscientist.com/article.php/meggyjr" target="_blank">Evil Mad Scientist Laboratories</a>.</p>
<p>The sourcecode of this application is available as <a href="http://michi.ist.inspirationslos.de/files/2009/04/colorchooser.pde" target="_self">download</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://michi.ist.inspirationslos.de/lang/en/2009/04/05/erstes-meggy-jr-programm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roguelike Programmierung</title>
		<link>http://michi.ist.inspirationslos.de/lang/en/2007/12/04/roguelike-programmierung</link>
		<comments>http://michi.ist.inspirationslos.de/lang/en/2007/12/04/roguelike-programmierung#comments</comments>
		<pubDate>Tue, 04 Dec 2007 20:30:38 +0000</pubDate>
		<dc:creator>michi</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[roguelike]]></category>

		<guid isPermaLink="false">http://www.quixotic-project.de/blog/?p=71</guid>
		<description><![CDATA[Seit einiger Zeit nun versuche ich mich selbst daran ein kleines roguelike zu schreiben. Noch gibt es nicht viel zu sehen, deswegen keine Screenshots. Nebenbei lese ich auch die entsprechende Newsgroup rec.games.roguelike.development um einen Überblick zu erhalten und Links zu Tutorials und so weiter zu finden. Eine Seite fand ich dabei besonders gut: Ascii Dreams. [...]]]></description>
			<content:encoded><![CDATA[<p>Seit einiger Zeit nun versuche ich mich selbst daran ein kleines <a href="http://de.wikipedia.org/wiki/Rogue-like">roguelike</a> zu schreiben. Noch gibt es nicht viel zu sehen, deswegen keine Screenshots. Nebenbei lese ich auch die entsprechende Newsgroup rec.games.roguelike.development um einen Überblick zu erhalten und Links zu Tutorials und so weiter zu finden. Eine Seite fand ich dabei besonders gut: <a href="http://roguelikedeveloper.blogspot.com/">Ascii Dreams</a>. Der Autor entwickelt, soweit ich das richtig mitbekommen habe, ein altes Roguelike (Angband) weiter und dokumentiert dabei die wichtigsten Schritte und was ihm wichtig ist. Erst kürzlich hat er eine Reihe von Artikeln über die Levelgenerierung veröffentlicht, die sehr interessant waren.</p>
<p>Ich habe den ersten Schritt hinter mir und mich für eine Darstellung entschieden. Klassischerweise würde man wohl farbige Konsolenausgabe für die Grafik wählen, doch da ich mich für Java als Programmiersprache entschlossen habe fällt das flach. Java kennt keine Farbe in der Konsole und dies durch Tricks zu umgehen war mir zu aufwendig. Die zweite Möglichkeit ist eine der vielen Curses Bibliotheken zu benutzen die es so gibt. Da die meisten aber für C++ sind und ich nur eine für Java gefunden habe (<a href="http://sourceforge.net/projects/javacurses/">JCurses</a>) und mit dieser auch nicht besonders gut zurechtgekommen bin habe ich auch dies wieder verworfen. Entschieden habe ich mich dann für Alternative drei: Mit Hilfe von OpenGL zeichne ich einfach Quads auf den Bildschirm die die Ascii-Zeichen als Textur haben und habe somit auch gleich die volle Kontrolle über die Auflösung, verschiedene Zeichensätze usw.<br />
Zeichnen lasse ich dann alles über VertexArrays, wobei sich nur die Arrays für die Farbe und die Textur ändern, die Geometrie ist statisch. Gerendert wird in zwei Schritten: Zuerst wird der Hintergrund ohne Textur mit Hintergrundfarbe gerendert und danach kommt nochmal ein Durchgang mit angeschalteten Texturen. In Code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//render background</span>
<span style="color: #666666; font-style: italic;">//fill color buffer</span>
colorBuffer.<span style="color: #006633;">position</span><span style="color: #009900;">&#40;</span>0<span style="color: #009900;">&#41;</span>;
colorBuffer.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>colorArrayBackground<span style="color: #009900;">&#41;</span>;
colorBuffer.<span style="color: #006633;">flip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
GL11.<span style="color: #006633;">glDisable</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_TEXTURE_2D</span><span style="color: #009900;">&#41;</span>;
GL11.<span style="color: #006633;">glEnableClientState</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_VERTEX_ARRAY</span><span style="color: #009900;">&#41;</span>;
GL11.<span style="color: #006633;">glEnableClientState</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_COLOR_ARRAY</span><span style="color: #009900;">&#41;</span>;
GL11.<span style="color: #006633;">glVertexPointer</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, 0, vertexBuffer<span style="color: #009900;">&#41;</span>;
GL11.<span style="color: #006633;">glColorPointer</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, 0, colorBuffer<span style="color: #009900;">&#41;</span>;
&nbsp;
GL11.<span style="color: #006633;">glDrawArrays</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_TRIANGLES</span>, 0, resX <span style="color: #339933;">*</span> resY <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">//render foreground</span>
<span style="color: #666666; font-style: italic;">//fill colorbuffer</span>
colorBuffer.<span style="color: #006633;">position</span><span style="color: #009900;">&#40;</span>0<span style="color: #009900;">&#41;</span>;
colorBuffer.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>colorArrayForeground<span style="color: #009900;">&#41;</span>;
colorBuffer.<span style="color: #006633;">flip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
texCoordBuffer.<span style="color: #006633;">position</span><span style="color: #009900;">&#40;</span>0<span style="color: #009900;">&#41;</span>;
texCoordBuffer.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>texCoordArray<span style="color: #009900;">&#41;</span>;
texCoordBuffer.<span style="color: #006633;">flip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
GL11.<span style="color: #006633;">glEnable</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_TEXTURE_2D</span><span style="color: #009900;">&#41;</span>;
GL11.<span style="color: #006633;">glEnableClientState</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_TEXTURE_COORD_ARRAY</span><span style="color: #009900;">&#41;</span>;
&nbsp;
GL11.<span style="color: #006633;">glTexCoordPointer</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, 0, texCoordBuffer<span style="color: #009900;">&#41;</span>;
&nbsp;
GL11.<span style="color: #006633;">glDrawArrays</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_TRIANGLES</span>, 0, resX <span style="color: #339933;">*</span> resY <span style="color: #339933;">*</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span>;
&nbsp;
GL11.<span style="color: #006633;">glDisableClientState</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_TEXTURE_COORD_ARRAY</span><span style="color: #009900;">&#41;</span>;
GL11.<span style="color: #006633;">glDisableClientState</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_VERTEX_ARRAY</span><span style="color: #009900;">&#41;</span>;
GL11.<span style="color: #006633;">glDisableClientState</span><span style="color: #009900;">&#40;</span>GL11.<span style="color: #006633;">GL_COLOR_ARRAY</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>Die Klasse die für das Rendern zuständig ist merkt sich die Farben und Texturen der einzelnen Tiles (also die Positionen an denen ein Buchstabe oder Zeichen stehen soll), sodass nicht in jedem Durchlauf alles erneut ausgelesen werden muss.</p>
<p>Sobald man mal mehr als nur ein paar Debugausgaben sehen kann werde ich auch einen Screenshot posten.</p>
]]></content:encoded>
			<wfw:commentRss>http://michi.ist.inspirationslos.de/lang/en/2007/12/04/roguelike-programmierung/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
