<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Mode 7 graphics in Allegro 5...</title>
		<link>http://www.allegro.cc/forums/view/616036</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 09 Feb 2016 07:34:09 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hy guys. I really want to learn a certain extra technique with allegro 5, and that technique is Mode 7 graphics. In case you don&#39;t know what that is, think the graphics in super Mario kart or F-Zero for the Super Nintendo. I did find an article on this, but it is for allegro 4:&#39;(. The reason I want to learn this is because I want to play around with it for practice and some time I would want to make a kart racer. Is there any way I can be given an example on how to code these graphics, but just for allegro 5, or any other learning resources?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (PCwizard200)</author>
		<pubDate>Sat, 06 Feb 2016 08:12:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Mode 7 is a special hardware only mode for the SNES. Technically, it cannot be done without an SNES.</p><p>However, mathematically, the &quot;look&quot; can be replicated and Allegro 5 or any other library works the same way. It&#39;s just a coordinate transformation. The question then is, what kind of transformation are you looking for? </p><p>If it&#39;s simply Mario Kart, you&#39;re just using a single texture at an angle and using bill board sprites for the cars will probably work. <a href="http://i.stack.imgur.com/8Nd0o.gif">Billboard</a> sprites are just polygons that always point toward the screen. Older games (and many modern) used them for trees to speed things up.</p><p>So you&#39;ve got the &quot;track&quot; which is a single textured polygon (technically two triangles forming a square) that&#39;s rotated and a polygon for each car. And depending on the angle between the car and the camera, you &quot;turn&quot; the car by selecting a different angle picture. Much like Wolfenstein 3-D or Doom.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Sat, 06 Feb 2016 08:43:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>One other thing to keep in mind when mimicking Mode 7 with a modern graphics API is that SNES games like Super Mario Kart and F-Zero set artificial boundaries for the rendering of the 3D floor of the track because of the angle it was being rendered at. You&#39;ll notice when playing either of those games things at the very edge of the horizon seem to come up relatively quickly, as though more stuff should be visible beyond the horizon, and that&#39;s because more stuff SHOULD be. The rendering is cut off early so that a horizon can be drawn at all! <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>The reason this is important is because if you actually used the right angle so that the horizon would really be where you intended it to be, everything on the floor would look squished because of the angle and track elements would be almost impossible to make out unless you were right on top of them. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Sun, 07 Feb 2016 00:38:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey again PCWizard200. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>I&#39;m guessing you&#39;re referencing <a href="http://www.helixsoft.nl/articles/circle/sincos.htm">Amarillion&#39;s legendary article on sin/cos</a> where he also describes how to achieve Mode 7?</p><p>I&#39;m looking at the <span class="source-code">mode_7<span class="k2">(</span><span class="k2">)</span></span> function in that tutorial and it looks like the only difference between Allegro 4 and Allegro 5 is this part:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>        <span class="c">// calculate the starting position</span>
<span class="number">  2</span>        space_x <span class="k3">=</span> cx <span class="k3">+</span> fmul <span class="k2">(</span>distance, fcos<span class="k2">(</span>angle<span class="k2">)</span><span class="k2">)</span> <span class="k3">-</span> bmp-&gt;w<span class="k3">/</span><span class="n">2</span> <span class="k3">*</span> line_dx<span class="k2">;</span>
<span class="number">  3</span>        space_y <span class="k3">=</span> cy <span class="k3">+</span> fmul <span class="k2">(</span>distance, fsin<span class="k2">(</span>angle<span class="k2">)</span><span class="k2">)</span> <span class="k3">-</span> bmp-&gt;w<span class="k3">/</span><span class="n">2</span> <span class="k3">*</span> line_dy<span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span>        <span class="c">// go through all points in this screen line</span>
<span class="number">  6</span>        <span class="k1">for</span> <span class="k2">(</span>screen_x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> screen_x <span class="k3">&lt;</span> bmp-&gt;w<span class="k2">;</span> screen_x<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number">  7</span>        <span class="k2">{</span>
<span class="number">  8</span>            <span class="c">// get a pixel from the tile and put it on the screen</span>
<span class="number">  9</span>            <a href="http://www.allegro.cc/manual/putpixel"><span class="a">putpixel</span></a> <span class="k2">(</span>bmp, screen_x, screen_y,
<span class="number"> 10</span>                <a href="http://www.allegro.cc/manual/getpixel"><span class="a">getpixel</span></a> <span class="k2">(</span>tile,
<span class="number"> 11</span>                    <a href="http://www.allegro.cc/manual/fixtoi"><span class="a">fixtoi</span></a> <span class="k2">(</span>space_x<span class="k2">)</span> <span class="k3">&amp;</span> mask_x,
<span class="number"> 12</span>                    <a href="http://www.allegro.cc/manual/fixtoi"><span class="a">fixtoi</span></a> <span class="k2">(</span>space_y<span class="k2">)</span> <span class="k3">&amp;</span> mask_y<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>            <span class="c">// advance to the next position in space</span>
<span class="number"> 14</span>            space_x <span class="k3">+</span><span class="k3">=</span> line_dx<span class="k2">;</span>
<span class="number"> 15</span>            space_y <span class="k3">+</span><span class="k3">=</span> line_dy<span class="k2">;</span>
<span class="number"> 16</span>        <span class="k2">}</span>
</div></div><p>

Even though I haven&#39;t tested this code, updating it to Allegro 5 would look like this:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>        <span class="c">// calculate the starting position</span>
<span class="number">  2</span>        space_x <span class="k3">=</span> cx <span class="k3">+</span> fmul <span class="k2">(</span>distance, fcos<span class="k2">(</span>angle<span class="k2">)</span><span class="k2">)</span> <span class="k3">-</span> <a href="http://www.allegro.cc/manual/al_get_bitmap_width"><span class="a">al_get_bitmap_width</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k3">/</span><span class="n">2</span> <span class="k3">*</span> line_dx<span class="k2">;</span>
<span class="number">  3</span>        space_y <span class="k3">=</span> cy <span class="k3">+</span> fmul <span class="k2">(</span>distance, fsin<span class="k2">(</span>angle<span class="k2">)</span><span class="k2">)</span> <span class="k3">-</span> <a href="http://www.allegro.cc/manual/al_get_bitmap_width"><span class="a">al_get_bitmap_width</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k3">/</span><span class="n">2</span> <span class="k3">*</span> line_dy<span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span>        <span class="c">// set our drawing target</span>
<span class="number">  6</span>        <a href="http://www.allegro.cc/manual/ALLEGRO_STATE"><span class="a">ALLEGRO_STATE</span></a> previous_state<span class="k2">;</span>
<span class="number">  7</span>        <a href="http://www.allegro.cc/manual/al_store_state"><span class="a">al_store_state</span></a><span class="k2">(</span><span class="k3">&amp;</span>previous_state, ALLEGRO_STATE_TARGET_BITMAP<span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span>        <a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>        <span class="c">// lock our bitmaps for faster pixel access</span>
<span class="number"> 11</span>        <a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a><span class="k2">(</span>tile, ALLEGRO_LOCK_READONLY, ALLEGRO_PIXEL_FORMAT_ANY<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>        <a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a><span class="k2">(</span>bmp, ALLEGRO_LOCK_WRITEONLY, ALLEGRO_PIXEL_FORMAT_ANY<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>        <span class="c">// go through all points in this screen line</span>
<span class="number"> 15</span>        <span class="k1">for</span> <span class="k2">(</span>screen_x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> screen_x <span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/al_get_bitmap_width"><span class="a">al_get_bitmap_width</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span> screen_x<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
<span class="number"> 16</span>        <span class="k2">{</span>
<span class="number"> 17</span>            <span class="c">// get a pixel from the tile and put it on the screen</span>
<span class="number"> 18</span>            <a href="http://www.allegro.cc/manual/al_put_pixel"><span class="a">al_put_pixel</span></a> <span class="k2">(</span>screen_x, screen_y,
<span class="number"> 19</span>                <a href="http://www.allegro.cc/manual/al_get_pixel"><span class="a">al_get_pixel</span></a> <span class="k2">(</span>tile,
<span class="number"> 20</span>                    <a href="http://www.allegro.cc/manual/fixtoi"><span class="a">fixtoi</span></a> <span class="k2">(</span>space_x<span class="k2">)</span> <span class="k3">&amp;</span> mask_x,
<span class="number"> 21</span>                    <a href="http://www.allegro.cc/manual/fixtoi"><span class="a">fixtoi</span></a> <span class="k2">(</span>space_y<span class="k2">)</span> <span class="k3">&amp;</span> mask_y<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>            <span class="c">// advance to the next position in space</span>
<span class="number"> 23</span>            space_x <span class="k3">+</span><span class="k3">=</span> line_dx<span class="k2">;</span>
<span class="number"> 24</span>            space_y <span class="k3">+</span><span class="k3">=</span> line_dy<span class="k2">;</span>
<span class="number"> 25</span>        <span class="k2">}</span>
<span class="number"> 26</span>
<span class="number"> 27</span>        <span class="c">// unlock our bitmaps</span>
<span class="number"> 28</span>        <a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a><span class="k2">(</span>tile<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 29</span>        <a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a><span class="k2">(</span>bmp<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>
<span class="number"> 31</span>        <span class="c">// restore our previous drawing target</span>
<span class="number"> 32</span>        <a href="http://www.allegro.cc/manual/al_restore_state"><span class="a">al_restore_state</span></a><span class="k2">(</span><span class="k3">&amp;</span>previous_state<span class="k2">)</span><span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 07 Feb 2016 01:14:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey everyone. Sorry for the late reply, for some reason I did not get an email that said you guys reply to my post. I guess this it is because this forum works in a different manner? Well, anyway I want to start with a simple f-zero type racing game, or mario kart style, then I will want to build up on that by making a prototype on a starfox type mode7, just without the polygons. (Meaning, that It would have a track like a f-zero game, but the player sprite would be able to move up and down and such, and shoot enemys coming at you, think the speeder stages from Super Star Wars). However full games will be for a later time, right now I just want to start by playing around with this technique, to get a better understanding of it, kinda like making graphic demos, along with making simple 2D games for practice. So thanks for your input on mode 7 graphics for me to visualize it Chris Katko and Kris Asick. Mark Oats I am happy to also play around with your sample code, ya never know, I might build upon it[:. Anyway, Im off to code! (:
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (PCwizard200)</author>
		<pubDate>Sun, 07 Feb 2016 20:44:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you want to be emailed on reply, you have to click the &quot;Subscribe&quot; button at the bottom of the thread.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 07 Feb 2016 21:44:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just to clear something up: Star Fox does NOT use Mode 7 graphics for anything. Virtually all rendering in Star Fox is done by the SuperFX chip on the cart as it was designed specifically for manipulating and rendering polygons. Mode 7 on its own is incapable of rendering polygons as it&#39;s just a transformation engine. You can witness this yourself in Super Mario Kart in that the sprites which show up on the track as you&#39;re racing do not smoothly scale and instead have different sprites for different distances from the camera. Same with F-Zero or any other such game using this sort of perspective transformation.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kris Asick)</author>
		<pubDate>Mon, 08 Feb 2016 01:51:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes Kris Asick, I meant that I would want to eventually create a StarFox game just without the polygons, and entirely in mode 7 graphics. But that will be for another project.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (PCwizard200)</author>
		<pubDate>Mon, 08 Feb 2016 01:57:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/616036/1019745#target">PCwizard200</a> said:</div><div class="quote"><p>
starfox type mode7, just without the polygons. (Meaning, that It would have a track like a f-zero game, but the player sprite would be able to move up and down and such, and shoot enemys coming at you, think the speeder stages from Super Star Wars)
</p></div></div><p>
This game actually existed: <a href="https://en.wikipedia.org/wiki/HyperZone">HyperZone</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Tue, 09 Feb 2016 07:34:09 +0000</pubDate>
	</item>
</rss>
