<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>fastest way to plot pixels A5</title>
		<link>http://www.allegro.cc/forums/view/608104</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 15 Aug 2011 19:13:13 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m wondering how to go about increasing the speed of my program. The question is what is the fastest way to draw pixels across the entire screen in one loop? </p><p>Kazzmir told me to lock the bitmap like so, but is this correct or am I supposed to draw onto a bitmap instead?</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_lock_bitmap"><span class="a">al_lock_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_target_bitmap"><span class="a">al_get_target_bitmap</span></a><span class="k2">(</span><span class="k2">)</span>, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE<span class="k2">)</span><span class="k2">;</span>              

  <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> y <span class="k3">&lt;</span> SCREEN_HEIGHT_Y<span class="k2">;</span> y<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
  <span class="k2">{</span>
    <span class="k1">for</span><span class="k2">(</span><span class="k1">int</span> x <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> x <span class="k3">&lt;</span> SCREEN_WIDTH_X<span class="k2">;</span> x<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
    <span class="k2">{</span>
      <a href="http://www.allegro.cc/manual/al_draw_pixel"><span class="a">al_draw_pixel</span></a><span class="k2">(</span>x,y, COLOR<span class="k2">)</span><span class="k2">;</span>        
    <span class="k2">}</span>
  <span class="k2">}</span>
<a href="http://www.allegro.cc/manual/al_unlock_bitmap"><span class="a">al_unlock_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_target_bitmap"><span class="a">al_get_target_bitmap</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sun, 14 Aug 2011 20:33:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You aren&#39;t allowed to use al_draw_pixel on a locked bitmap AFAIK (maybe that has changed though.) You should use al_put_pixel. Experiment with al_put_pixel+locking and ALLEGRO_VERTEXs+al_draw_prim+ALLEGRO_POINT_LIST.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sun, 14 Aug 2011 20:35:26 +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/608104/928225#target">Trent Gamblin</a> said:</div><div class="quote"><p>ALLEGRO_VERTEXs+al_draw_prim+ALLEGRO_POINT_LIST</p></div></div><p>

I&#39;m not sure what you mean? Can you give an example?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sun, 14 Aug 2011 20:37:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sure.</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX"><span class="a">ALLEGRO_VERTEX</span></a> my_100_pixels<span class="k2">[</span><span class="n">100</span><span class="k2">]</span><span class="k2">;</span>
<span class="k1">for</span> <span class="k2">(</span><span class="k1">int</span> i <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span> i <span class="k3">&lt;</span> <span class="n">100</span><span class="k2">;</span> i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span> <span class="k2">{</span>
   <span class="c">// initialize pixels with random x, y</span>
   my_100_pixels<span class="k2">[</span>i<span class="k2">]</span>.x <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span> % SCR_W<span class="k2">;</span>
   my_100_pixels<span class="k2">[</span>i<span class="k2">]</span>.y <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_637.html" target="_blank">rand</a><span class="k2">(</span><span class="k2">)</span> % SCR_H<span class="k2">;</span>
   my_100_pixels<span class="k2">[</span>i<span class="k2">]</span>.z <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
   <span class="c">// set the pixels color</span>
   my_100_pixels<span class="k2">[</span>i<span class="k2">]</span>.color <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgb_f"><span class="a">al_map_rgb_f</span></a><span class="k2">(</span><span class="n">1</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="c">// red</span>
<span class="k2">}</span>
<a href="http://www.allegro.cc/manual/al_draw_prim"><span class="a">al_draw_prim</span></a><span class="k2">(</span>my_100_pixels, NULL, NULL, <span class="n">0</span>, <span class="n">100</span>, ALLEGRO_PRIM_POINT_LIST<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Obviously you don&#39;t have to do random pixels, you can set their x/y/color to whatever you want, but you probably want z to be 0 if you&#39;re doing 2d.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sun, 14 Aug 2011 20:52:17 +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/608104/928227#target">Trent Gamblin</a> said:</div><div class="quote"><p>Obviously you don&#39;t have to do random pixels, you can set their x/y/color to whatever you want, but you probably want z to be 0 if you&#39;re doing 2d.
</p></div></div><p>

Does this mean I can create a 3d plot. If so, how would I move the camera or rotate the world? Is it rendered using opengl or directx?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sun, 14 Aug 2011 21:42:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah, you can do 3d, but you have to do transformations yourself as Allegro only supports 2d transformations. You can still use the <span class="source-code"><a href="http://www.allegro.cc/manual/al_compose_transform"><span class="a">al_compose_transform</span></a></span>, <span class="source-code"><a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a></span>, <span class="source-code">al_set_projection_transform</span> with 3d transformations but <span class="source-code"><a href="http://www.allegro.cc/manual/al_rotate_transform"><span class="a">al_rotate_transform</span></a></span> etc are only 2d. Allegro 5 always renders with OpenGL or D3D. Default is D3D on Windows and OpenGL everywhere else but you can specify with <span class="source-code">al_set_new_display_flag<span class="k2">(</span>ALLEGRO_OPENGL<span class="k3">/</span>ALLEGRO_DIRECT3D<span class="k2">)</span></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sun, 14 Aug 2011 21:47:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Basically I would need to create my own camera with culling methods and what not? What (practical) use of 3d does allegro 5 have so far then?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sun, 14 Aug 2011 21:50:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, you don&#39;t need to create any of that. That&#39;s all built into OpenGL and D3D. Allegro is a 2D lib but it allows you to use OpenGL or D3D directly for any 3D stuff you want to do, and you can mix 2D Allegro drawing with your own 3D drawing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sun, 14 Aug 2011 21:53:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So I would use openGL methods in the allegro code?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sun, 14 Aug 2011 21:54:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;d use OpenGL calls in your own code, intermixed with Allegro calls.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sun, 14 Aug 2011 22:00:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m trying to create a class where the ALLEGRO_VERTEX is a variable size at class construction but it doesn&#39;t compile, any ideas if this is possible?</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="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro_primitives.h&gt;</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="k1">class</span> pixel_class
<span class="number">  5</span><span class="k2">{</span>
<span class="number">  6</span>  private:
<span class="number">  7</span>    
<span class="number">  8</span>    <span class="k1">int</span> SCREEN_HEIGHT_Y<span class="k2">;</span>
<span class="number">  9</span>    <span class="k1">int</span> SCREEN_WIDTH_X<span class="k2">;</span>    
<span class="number"> 10</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_VERTEX"><span class="a">ALLEGRO_VERTEX</span></a> pixels<span class="k2">[</span>SCREEN_HEIGHT_Y<span class="k3">*</span>SCREEN_WIDTH_X<span class="k2">]</span><span class="k2">;</span>
<span class="number"> 11</span>
<span class="number"> 12</span>  public:
<span class="number"> 13</span>
<span class="number"> 14</span>  pixel_class<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span><span class="k2">}</span>
<span class="number"> 15</span>  ~pixel_class<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span><span class="k2">}</span>
<span class="number"> 16</span>  pixel_class<span class="k2">(</span><span class="k1">int</span> sw, <span class="k1">int</span> sh<span class="k2">)</span>
<span class="number"> 17</span>  <span class="k2">{</span>    
<span class="number"> 18</span>    SCREEN_HEIGHT_Y <span class="k3">=</span> sh<span class="k2">;</span>
<span class="number"> 19</span>    SCREEN_WIDTH_X <span class="k3">=</span> sw<span class="k2">;</span>  
<span class="number"> 20</span>  <span class="k2">}</span>  
<span class="number"> 21</span><span class="k2">}</span><span class="k2">;</span>
</div></div><p>
C:\pixel_class.h|11|error: invalid use of non-static data member &#39;pixel_class::SCREEN_HEIGHT_Y&#39;|<br />C:\pixel_class.h|13|error: from this location|<br />C:\pixel_class.h|12|error: invalid use of non-static data member &#39;pixel_class::SCREEN_WIDTH_X&#39;|<br />C:\pixel_class.h|13|error: from this location|<br />C:\pixel_class.h|13|error: array bound is not an integer constant|<br />||=== Build finished: 5 errors, 0 warnings ===|
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Sun, 14 Aug 2011 22:12:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Make it a pointer and new/delete it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sun, 14 Aug 2011 22:14:37 +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/608104/928243#target">Trent Gamblin</a> said:</div><div class="quote"><p>You&#39;d use OpenGL calls in your own code, intermixed with Allegro calls.</p></div></div><p>
In a previous thread(I can&#39;t find it anymore), someone told me that you can&#39;t mix Allegro calls with OpenGL calls because the former mess up the OpenGL state. I tried drawing text with Allegro after rendering a scene with OpenGL and I got weird results...<br />Could you give some example code where OpenGL is mixed with allegro drawing?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (J-Gamer)</author>
		<pubDate>Sun, 14 Aug 2011 22:34:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>As long as you&#39;re aware of the state changes, you can do it. I have several 3d mini games that draw in 3d with 2d overlays drawn with Allegro. Actually, I draw some of the 3d parts with al_draw_prim too.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Sun, 14 Aug 2011 22:58:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just curious, would it be faster to use a shader than al_put_pixel?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 15 Aug 2011 08:07:21 +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/608104/928286#target">Mark Oates</a> said:</div><div class="quote"><p> Just curious, would it be faster to use a shader than al_put_pixel?</p></div></div><p>Alex the Alligator frowns on that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Mon, 15 Aug 2011 09:51:34 +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/608104/928286#target">Mark Oates</a> said:</div><div class="quote"><p>Just curious, would it be faster to use a shader than al_put_pixel?
</p></div></div><p>

I could only imagine a shader would be made up of the functions that render a pixel anyway.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Mon, 15 Aug 2011 10:07:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I guess I&#39;m just curious if a shader has some extra magic that you wouldn&#39;t otherwise get.  Point list is a cool idea, though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 15 Aug 2011 14:57:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Depends. If your data is stored in a texture, sure. But uploading 1000 pixels to a shader ever frame isn&#39;t going to be faster (and I&#39;m not even sure you can do it.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trent Gamblin)</author>
		<pubDate>Mon, 15 Aug 2011 19:13:13 +0000</pubDate>
	</item>
</rss>
