<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_draw_rotated_bitmap() giving distorted edges </title>
		<link>http://www.allegro.cc/forums/view/617459</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 26 Jun 2018 13:06:01 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was just running an animation using frames. But when I changed the rotation the edged became distorted but for rotation = 0 degrees it&#39;s crystal clear and fine. I am using #define PI 3.141592653589793f for converting the degree to radian. The data type used to store the value in radians is a float.</p><p>What would be the potential cause of this problem? <br />All the graphical results are attached to this post. For visual analysis. </p><p>float Position::getRadRotX() const<br />{<br />	return((rotX * PI) / 180);<br />}
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 01:23:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Something you can do is turn on multi-sampling.</p><p>You have to enable it before creating your display :</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_set_new_display_option"><span class="a">al_set_new_display_option</span></a><span class="k2">(</span>ALLEGRO_SAMPLE_BUFFERS , <span class="n">1</span> , ALLEGRO_SUGGEST<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_set_new_display_option"><span class="a">al_set_new_display_option</span></a><span class="k2">(</span>ALLEGRO_SAMPLES , <span class="n">4</span> , ALLEGRO_SUGGEST<span class="k2">)</span><span class="k2">;</span>

<a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</span> d <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span>...<span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_display_option"><span class="a">al_get_display_option</span></a><span class="k2">(</span>d , ALLEGRO_SAMPLE_BUFFERS<span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> <span class="n">1</span><span class="k2">)</span> <span class="k2">{</span>
   cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"Failed to enable multisampling on the display."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
<span class="k2">}</span>
cout <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">"There are "</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <a href="http://www.allegro.cc/manual/al_get_display_option"><span class="a">al_get_display_option</span></a><span class="k2">(</span>d , ALLEGRO_SAMPLES<span class="k2">)</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> <span class="s">" sample buffers in use."</span> <span class="k3">&lt;</span><span class="k3">&lt;</span> std::endl<span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 01:33:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you, Edgar Reynaldo for the replay</p><p>std::cout&lt;&lt; says:- <br />Failed to enable multisampling on the display.<br />There are 0 sample buffers in use.<br />And it&#39;s the same as before, blurred edges.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 01:40:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s curious. What platform are you on?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 01:45:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Windows 10 64bit. Visual Studio 2017<br />Intel(R) Pentium(R) CPU N3710 @ 1.60GHz 1.60 GHz <br />Intel HD Graphics 405<br />Shader version 5.0<br />Open GL version 4.4<br />Open CL version 1.2 <br />Direct X runtime version 12.0<br />         hardware supported version 11.1
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 01:51:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay, and what Allegro driver are you using? OpenGL or DX?</p><p>Show your display set up code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 01:59:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>void debug()<br />{<br />	ALLEGRO_DISPLAY *display;<br />	ALLEGRO_DISPLAY_MODE   dispData;</p><p>	al_init();<br />	al_init_primitives_addon();<br />	al_init_image_addon();<br />	al_get_display_mode(al_get_num_display_modes() - 1, &amp;dispData);</p><p>	al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);<br />	al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);<br />	al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);</p><p>	display = al_create_display(dispData.width, dispData.height);<br />	if (al_get_display_option(display, ALLEGRO_SAMPLE_BUFFERS) != 1) {<br />		std::cout &lt;&lt; &quot;Failed to enable multisampling on the display.&quot; &lt;&lt; std::endl;<br />	}<br />	std::cout &lt;&lt; &quot;There are &quot; &lt;&lt; al_get_display_option(display, ALLEGRO_SAMPLES) &lt;&lt; &quot; sample buffers in use.&quot; &lt;&lt; std::endl;</p><p>}
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 02:00:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s really weird, because I&#39;m running mostly the same setup as you, and I know I have a working multisampling example around here somewhere. Let me find it.</p><p>Run a debugging build, and see what allegro.log has to say about the display.</p><p>EDIT<br />Try the OpenGL driver and see if it enables multi sampling. Could be a DX issue.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 02:11:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Edgar Reynaldo for helping out, <br />The log file is attached above. <br />Allegro produce log&#39;s in debugging mode only or it&#39;s the same in the release mode too?. I never noticed it before <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 02:24:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>See my edit. From allegro.log it looks like none of the display formats tested support multi-sampling. They all say &quot;samples 0/0&quot; in the log.</p><p>Try the OpenGL driver.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 02:28:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t know how to switch to open GL in windows 10.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 02:44:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_set_new_display_flags"><span class="a">al_set_new_display_flags</span></a><span class="k2">(</span>ALLEGRO_OPENGL <span class="k3">|</span> ALLEGRO_FULLSCREEN<span class="k2">)</span><span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 02:48:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you, Edgar Reynaldo for your kind support. <br />It&#39;s little better, and the sampling worked .... <br />But not fluid as the 0-degree pic.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 02:53:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is probably a bug in the DX driver.</p><p>You might try to increase the samples to 8 but I think 2 or 4 will give the most optimal results.</p><p>How many samples did it end up with? What does allegro.log say?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 02:56:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I replaced the value of PI with const float PI = 104348 / 33215;<br />Now it seems better. Still some little distortions here and there.</p><p>I switched back to d3d and used the same code as &quot;const float PI = 104348 / 33215;&quot; and the result was the same as when the OpenGL was rendering with 4 buffers. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 03:06:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Are you drawing your sprite on the back buffer or another bitmap? If you&#39;re drawing it on another bitmap it won&#39;t be multi-sampled unless you enable multi-sampling on the bitmap as well.</p><div class="source-code snippet"><div class="inner"><pre>al_set_new_bitmap_samples<span class="k2">(</span><span class="n">8</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_create_bitmap"><span class="a">al_create_bitmap</span></a><span class="k2">(</span>w,h<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

As for your float problem. int/int always gives you int. You need to specify a floating point literal value as such by using .0f on the end of it. Otherwise you get integer division, which discards the remainder.</p><p>Here&#39;s multi-sampling enabled through al_set_new_bitmap_samples : </p><p>https://www.allegro.cc/files/attachment/611523</p><p>Actually, 8 samples looks the best.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 03:11:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Edgar Reynaldo, for bearing with me ... <br />I am drawing to the back buffer (not to any bitmap). I removed the entire code for sampling and I got the same result as before with the sampling enabled. It&#39;s little weird
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 03:15:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay, I&#39;m thinking that MultiSampling doesn&#39;t do anything for sprite drawing. Try this instead : Before you load your sprites, call the following code :</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_set_new_bitmap_flags"><span class="a">al_set_new_bitmap_flags</span></a><span class="k2">(</span>ALLEGRO_MIN_LINEAR <span class="k3">|</span> ALLEGRO_MIPMAP<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

ALLEGRO_MIPMAP won&#39;t do anything if the width and height of the image are not a power of two.</p><p>You can also try ALLEGRO_MAG_LINEAR, but it can make sprites blurry when enlarging them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 18 Jun 2018 03:39:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Edgar Reynaldo, <br />I think it&#39;s little better than before - just little distortion especially at the tip of the gun. For a starting, it won&#39;t be a problem. Thank you for helping out.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Mon, 18 Jun 2018 21:39:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, I&#39;m glad it&#39;s improved somewhat. Could you show a screenshot of the sprite with ALLEGRO_MIN_LINEAR enabled? Is it really any smoother?</p><p>I&#39;ve never had this problem before, but I haven&#39;t been rotating sprites much. I tried out rotation on multi-sampled primitives and enabled down scaling and ALLEGRO_MIN_LINEAR.</p><p>While it doesn&#39;t do much for full size sprites, it looks pretty good when actually scaling down.</p><p>You might try increasing the resolution of your graphics and scaling them down in your game, but whether that is worth it or not is up to you.</p><p>I will agree, there are some rather jagged edges when rotating sprites, even multi-sampled primitive sprites.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 19 Jun 2018 00:46:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Edgar Reynaldo, <br />My previous post had the pic&#39;s attached to it with these flags enabled &quot; al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MIPMAP); &quot;. But however the width and height of the png&#39;s are not a power of two, and the pic shows an unscaled version of the character. I will try to use HD images - and downscale it as per need if required.</p><p>One more thing - Should the actual bitmap have to be in the power of two or just the sub-bitmaps have to be in power of two.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Tue, 19 Jun 2018 01:44:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you want mipmaps, the source image has to be power of two in width and height (not necessarily the same though). mipmaps are really only good if you change the scale of your sprite often at runtime. That&#39;s what mipmaps are, pre-scaled versions of your image.</p><p>I will play with this some more over the next few days. Could you attach the image you&#39;re using for your player? I&#39;d like to try some things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 19 Jun 2018 12:09:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Edgar Reynaldo, <br />So the source image has to be a power of two <img src="http://www.allegro.cc/forums/smileys/cry.gif" alt=":&#39;(" />  that&#39;s bad.......<br />I took all the game assets from open game arts <a href="https://opengameart.org/content/animated-top-down-survivor-player">https://opengameart.org/content/animated-top-down-survivor-player</a><br />To test the code I uploaded - I will attach the combined animation sprite with the custom script I am using to this post.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Tue, 19 Jun 2018 13:09:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Note for the future - if you&#39;re going to attach multiple files, like a game project, it&#39;s best to put it in a .zip file so there&#39;s only one file to download. I will take a look at the assets.</p><p>You only need power of two textures if you want mipmaps. mipmaps are only good if you&#39;re planning to zoom in <s>and out</s> on your images.</p><p><b>EDIT</b><br />I made a small demo of your survivor guy being rotated and scaled with different combinations of ALLEGRO_MIN_LINEAR, ALLEGRO_MAG_LINEAR, and ALLEGRO_MIPMAP. Mipmapping didn&#39;t seem to help at all, and resulted in a faded image when scaling down. Mipmapping doesn&#39;t do anything when scaling up. Shrinking with ALLEGRO_MIN_LINEAR and growing with ALLEGRO_MAG_LINEAR really helped though, when not drawing at actual size.</p><p>Here&#39;s the demo - <a href="https://www.allegro.cc/files/attachment/611583">MinMag.zip</a>.</p><p>For some reason, mipmapping made the images fade when drawn at less than actual size.</p><p>https://www.allegro.cc/files/attachment/611584</p><p>Rotate around the center with the mouse. Mouse wheel changes zoom.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 20 Jun 2018 03:56:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you, Edgar Reynaldo, for your kind support. <br />I will look into the code. <br />Yes, next time I will take special care in zipping all the contents before attaching it.<br />Thank you once again....
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Fri, 22 Jun 2018 17:01:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Note that your sprite has antialiasing. I&#39;m not speaking of the borders (alpha on the fringe), but on the surface of the image, some pixel colors are drawn a spcific color in order to smooth the difference between pixels around it : for example a pixel can be set grey because it&#39;s between a black shape and a white shape. If such image is rotated at a similar zoom level to the original (*), the grey pixel may be preserved, and end up in a place which is not between a black and a white pixel, so it looks out of place.<br />This is a very simplified explanation (the rotozoom doesn&#39;t just juggle pixels), but the effect is real and can explain some oddities that appear at several angles but always at same position relative to sprite (ie. &quot;right elbow&quot;, &quot;corner of backpack&quot;...)</p><p>(*) Scaling UP the sprite amplifies the problem, scaling it down makes it disappear very quickly.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 22 Jun 2018 17:42:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you, Audric for the replay<br />I never noticed that changes ...... Now I know; I will try to use good quality High definition images and will scale it down when I need to draw - Hope that fix the problem for now. My project is live and if you like to take a peek into the stuff i am doing or need to edit or suggest changes feel free to do so. <br /><a href="https://github.com/ThinkalVB/NearEarth">https://github.com/ThinkalVB/NearEarth</a><br />Thank you once again for the help...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Fri, 22 Jun 2018 18:06:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For my Deluxe Pacman 2 game, I rotate the Pacman character, as the main image just faces the right.  For my setup, all I really have is:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_set_new_bitmap_flags"><span class="a">al_set_new_bitmap_flags</span></a><span class="k2">(</span>ALLEGRO_MAG_LINEAR<span class="k2">)</span><span class="k2">;</span></span></p><p>I have a bunch of code commented out that I tried in the past, but this seems to be the one I ended up using that works well using DirectX and OpenGL.</p><p>Not sure if that would help or not, been a while since I worked on this sort of problem.  And in my game the rotations are increments of 90 degrees.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Tue, 26 Jun 2018 10:52:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you Neil Roy, <br />I am trying a combination of MIP_MAP and MIN_LINEAR , I am more into zooming out, not much zooming in, but I have backed up all of your suggestions for future references if a need arise. Thank you once again for leaving your valuable comments in here.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Tue, 26 Jun 2018 11:55:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not relevant, but something you should know: the only minification filter you should ever use is some sort of mip mapping. Anything else will cause you to thrash the texture cache.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (relpatseht)</author>
		<pubDate>Tue, 26 Jun 2018 12:35:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you relpatseht, <br /><img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> Almost forgot that fact.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thinkal VB)</author>
		<pubDate>Tue, 26 Jun 2018 13:06:01 +0000</pubDate>
	</item>
</rss>
