<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>OpenGL: EXT_framebuffer_object</title>
		<link>http://www.allegro.cc/forums/view/588424</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 09 Nov 2006 03:00:12 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi, I&#39;m trying to use the EXT_framebuffer_object extension to render a 1600x1600 OpenGL image to hard disk. But up to now, my code only saves black bitmaps.<br />Can somebody tell me what&#39;s wrong with my code?</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>&#160;</td></tr><tr><td class="number">2</td><td><span class="k1">void</span> render_to_hd<span class="k2">(</span><span class="k2">)</span></td></tr><tr><td class="number">3</td><td><span class="k2">{</span></td></tr><tr><td class="number">4</td><td>   GLuint fb, texture, depth_rb<span class="k2">;</span></td></tr><tr><td class="number">5</td><td>   <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>allegro_gl_is_extension_supported<span class="k2">(</span><span class="s">"GL_EXT_framebuffer_object"</span><span class="k2">)</span><span class="k2">)</span><a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"framebuffers not supported"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>&#160;</td></tr><tr><td class="number">7</td><td>   glGenFramebuffersEXT<span class="k2">(</span><span class="n">1</span>,<span class="k3">&amp;</span>fb<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>   glBindFramebufferEXT<span class="k2">(</span>GL_FRAMEBUFFER_EXT, fb<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>   glGenRenderbuffersEXT<span class="k2">(</span><span class="n">1</span>,<span class="k3">&amp;</span>depth_rb<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>   glBindRenderbufferEXT<span class="k2">(</span>GL_RENDERBUFFER_EXT, depth_rb<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>   glGenTextures<span class="k2">(</span><span class="n">1</span>, <span class="k3">&amp;</span>texture<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>   glRenderbufferStorageEXT<span class="k2">(</span>GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT32, <span class="n">1600</span>, <span class="n">1600</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>   glFramebufferRenderbufferEXT<span class="k2">(</span>GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>   glFramebufferTexture2DEXT<span class="k2">(</span>GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>&#160;</td></tr><tr><td class="number">16</td><td>  glTexImage2D<span class="k2">(</span>GL_TEXTURE_2D, <span class="n">0</span>, GL_RGBA8, <span class="n">1600</span>, <span class="n">1600</span>, <span class="n">0</span>, GL_RGBA, GL_UNSIGNED_BYTE, NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>        glBindTexture <span class="k2">(</span>GL_TEXTURE_2D, texture<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td> </td></tr><tr><td class="number">19</td><td>  glTexEnvi<span class="k2">(</span>GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>  glTexParameteri<span class="k2">(</span>GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>  glTexParameteri<span class="k2">(</span>GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">22</td><td>&#160;</td></tr><tr><td class="number">23</td><td>   glDrawBuffer<span class="k2">(</span>GL_FALSE<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">24</td><td>  glReadBuffer<span class="k2">(</span>GL_FALSE<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td>&#160;</td></tr><tr><td class="number">26</td><td>    GLenum status<span class="k3">=</span>glCheckFramebufferStatusEXT<span class="k2">(</span>GL_FRAMEBUFFER_EXT<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">27</td><td>    <span class="k1">if</span><span class="k2">(</span>status<span class="k3">=</span><span class="k3">=</span>GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT<span class="k2">)</span> <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"error"</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td>&#160;</td></tr><tr><td class="number">29</td><td>   glViewport<span class="k2">(</span><span class="n">0</span>,  <span class="n">0</span>, <span class="n">1600</span>, <span class="n">1600</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//113</span></td></tr><tr><td class="number">30</td><td>&#160;</td></tr><tr><td class="number">31</td><td>    draw<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>  <span class="c">//draws everything as if it was for normal buffers</span></td></tr><tr><td class="number">32</td><td>&#160;</td></tr><tr><td class="number">33</td><td>   <span class="k1">unsigned</span> <span class="k1">char</span> buff<span class="k2">[</span><span class="n">4</span><span class="k3">*</span><span class="n">1600</span><span class="k3">*</span><span class="n">1600</span><span class="k2">]</span><span class="k2">;</span></td></tr><tr><td class="number">34</td><td>   <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>bmp<span class="k3">=</span><a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span><span class="n">1600</span>,<span class="n">1600</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">35</td><td>   glGetTexImage<span class="k2">(</span> GL_TEXTURE_2D, <span class="n">0</span>, GL_RGB, GL_UNSIGNED_BYTE, buff<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">36</td><td>   <span class="k1">int</span> y<span class="k2">;</span></td></tr><tr><td class="number">37</td><td>   <span class="k1">for</span><span class="k2">(</span>y<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>y<span class="k3">&lt;</span><span class="n">1600</span><span class="k2">;</span>y<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span></td></tr><tr><td class="number">38</td><td>   <a href="http://www.delorie.com/djgpp/doc/libc/libc_566.html" target="_blank">memcpy</a><span class="k2">(</span>bmp_up-&gt;line<span class="k2">[</span>y<span class="k2">]</span>,buff<span class="k3">+</span><span class="n">4</span><span class="k3">*</span><span class="n">1600</span><span class="k3">*</span><span class="k2">(</span><span class="n">1600</span><span class="k3">-</span><span class="n">1</span><span class="k3">-</span>y<span class="k2">)</span>,<span class="n">4</span><span class="k3">*</span><span class="n">1600</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">39</td><td>   <a href="http://www.allegro.cc/manual/save_bitmap" target="_blank"><span class="a">save_bitmap</span></a><span class="k2">(</span><span class="s">"bitmap.bmp"</span>,bmp,NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">40</td><td>&#160;</td></tr><tr><td class="number">41</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>
edit: Of course that&#39;s pseudo code, Allegro and OpenGL are initiated correctly.<br />edit2:updated the code
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fred Alert)</author>
		<pubDate>Tue, 07 Nov 2006 16:19:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>allegro_init();<br />allegro_gl_init();<br />set_color_depth( your_color_depth );<br />set_gfx_mode( GFX_OPENGL );</p><p>I am just trying to help, not sure this will solve the problem, but both allegro and allegrogl must be initialized before any use of their functions
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Tue, 07 Nov 2006 16:22:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code">glFramebufferTexture1DEXT</span><br /><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> I think you mean<br /><span class="source-code">glFramebufferTexture2DEXT</span><br />As well, your renderbuffer storage should be <tt>GL_DEPTH??_EXT</tt> since you&#39;re using it for the depth buffer (where ?? is the bit depth you want for the buffer) and not the color buffer. Also, you really shouldn&#39;t put such a large static array on the stack like that. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Tue, 07 Nov 2006 23:38:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Kitty Cat: <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />Thanks for the hints, I changed it, but my saved bitmap remains black:(</p><p>My copiler can&#39;t find GL_DEPTH32_EXT...</p><p>Unfortunately the array has to be that large. But I think that&#39;s not the problem - I tried to render a 100x100 texture this way, but the problem keeps to be the same.</p><p>I built in glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT), and this delivers the error enum GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT. <br />But I don&#39;t understand it...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fred Alert)</author>
		<pubDate>Wed, 08 Nov 2006 01:14:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>GL_DEPTH I&#39;d imagine is invalid, thus the render buffer is incomplete, which causes the framebuffer to be incomplete. Checking my info, it appears it&#39;s <tt>GL_DEPTH_COMPONENT??</tt>, where ?? is 16, 24, or 32.</p><p>Pre-emptively, if you&#39;re going to want a stencil buffer, you&#39;ll need to create a packed depth-stencil renderbuffer instead, using GL_DEPTH_STENCIL_EXT or GL_DEPTH24_STENCIL8_EXT (I&#39;d imagine both are the same), then bind that to both the depth and stencil framebuffer attachments. Last I tried, a stand-alone stencil buffer wouldn&#39;t work.</p><p>As for the array, it&#39;d be better to make it a dynamic array. Make <span class="source-code"><span class="k1">char</span> <span class="k3">*</span>image_buf<span class="k2">;</span></span> global, allocate it once at program start, then deallocate it before closing. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 08 Nov 2006 02:11:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Kitty Cat, thanks, that killed the error message! But the Problem still remains...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fred Alert)</author>
		<pubDate>Wed, 08 Nov 2006 02:56:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Does the code work if you draw to the screen (don&#39;t forget to flip for that)?</p><p>EDIT:<br />Oh. And you may need to switch to a power-of-2 texture size.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 08 Nov 2006 06:12:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">KittyCat said:</div><div class="quote"><p>

EDIT:<br />Oh. And you may need to switch to a power-of-2 texture size.
</p></div></div><p>

That would depend if Fred Alert has a card which supports non-power-of-two texture dimensions. The support should be automatic, according to that extension spec. Though I second KittyCat. Try render to the screen first.</p><p>EDIT: I&#39;m having right now the same problem as Fred Alert. Renders on screen of textures that have been updated through FBOs are appearing black. I&#39;m tired tonight, so I&#39;ll continue debugging tomorrow <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />.</p><p>Attachment contains a screenshot of my program showing all textures in black, with a test quad above them all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ciro Duran)</author>
		<pubDate>Wed, 08 Nov 2006 07:54:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Rendering to screen works. What about allegro_gl_flip()? It surely has to be left out when rendering to texture!<br />What do you mean by power-of-two textures? 2-dimensional? <br />I don&#39;t understand the term &quot;power of...&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fred Alert)</author>
		<pubDate>Wed, 08 Nov 2006 16:11:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Texture with dimension that are power of two values.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Wed, 08 Nov 2006 16:13:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img class="math" src="http://www.allegro.cc/images/tex/3/1/318271e3f1e99bbebcf8b4dcd73b4868-96.png" alt="&lt;math&gt;x = {2^a}&lt;/math&gt;" /><br />x is a power of two because<br /><img class="math" src="http://www.allegro.cc/images/tex/d/d/dd7db88722de837ba3ac55d3e654be1c-96.png" alt="&lt;math&gt;log_2{x}=a&lt;/math&gt;" /></p><p>Try with image sizes like 512, 1024, 2048... i think there is a limit though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Milan Mimica)</author>
		<pubDate>Wed, 08 Nov 2006 19:39:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /> I got the point. 2^n. <br />I tried but it made no difference <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fred Alert)</author>
		<pubDate>Wed, 08 Nov 2006 19:54:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Did you remove
</p><div class="source-code snippet"><div class="inner"><pre>glDrawBuffer<span class="k2">(</span>GL_FALSE<span class="k2">)</span><span class="k2">;</span>
glReadBuffer<span class="k2">(</span>GL_FALSE<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
? That might be causing problems.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 09 Nov 2006 03:00:12 +0000</pubDate>
	</item>
</rss>
