<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — fortran-sdl2 package]]></title>
		<link>http://forums.approximatrix.com/viewtopic.php?id=968</link>
		<atom:link href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=968&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in fortran-sdl2 package.]]></description>
		<lastBuildDate>Tue, 07 Jan 2025 14:07:03 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4409#p4409</link>
			<description><![CDATA[<p>Thanks, the software is working now.<br />I only need to solve the problem that the figure is shown upside down and mirror imaged.</p>]]></description>
			<author><![CDATA[null@example.com (csitters)]]></author>
			<pubDate>Tue, 07 Jan 2025 14:07:03 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4409#p4409</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4408#p4408</link>
			<description><![CDATA[<p>The <a href="https://packages.simplyfortran.com/package/90.html">version in the SF Package Manager</a> has been updated to correct the issue.&nbsp; Hopefully your code works now.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Tue, 07 Jan 2025 13:13:54 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4408#p4408</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4407#p4407</link>
			<description><![CDATA[<div class="quotebox"><cite>csitters wrote:</cite><blockquote><p>Can it be that bitmap is a &quot;sdl_surface pointer&quot; and sdl_save_bmp requires a &quot;sdl_surface&quot;??</p></blockquote></div><p>No, the runtime library is reporting that <em>bitmap</em> is not associated, meaning the initial call to <em>SDL_Create_RGB_Surface_From</em> failed, returning a null (or, in Fortran, unassociated) pointer.</p><p>No, the actual problem here is that the fortran-sdl2 library contains a bug.&nbsp; The Fortran binding for this function is incorrect.&nbsp; If you look at the <a href="https://github.com/interkosmos/fortran-sdl2/blob/2e08994a2fe0ac165109701fdbfde902e8c77b69/src/sdl2/sdl2_surface.f90#L72">GitHub version of the Fortran interface</a>, you&#039;ll notice that they&#039;ve bound the C function not to <em>SDL_CreateRGBSurfaceFrom</em>, but, rather, <em>SDL_CreateRGBSurface</em>.&nbsp; It appears to be a copypasta error.</p><p>I&#039;ve already <a href="https://github.com/interkosmos/fortran-sdl2/pull/22">submitted a pull request</a> to correct the issue.&nbsp; In the meantime, I&#039;ll try to build a new version of the package to fix this.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Tue, 07 Jan 2025 13:01:47 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4407#p4407</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4406#p4406</link>
			<description><![CDATA[<p>I adapted the code, it looks as follows:</p><p>subroutine save_image2()</p><p>use opengl_glu<br />use opengl_glut<br />use common_window<br />use, intrinsic :: iso_fortran_env, only: i1 =&gt; int8, i8 =&gt; int64, r8 =&gt; real64,&amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stderr =&gt; error_unit, stdout =&gt; output_unit<br />use :: sdl2<br />use :: sdl2_image<br />use :: SDL2_mixer<br />use :: SDL2_ttf<br />&nbsp; &nbsp;<br />implicit none<br />integer(kind=GLbyte), dimension(:), pointer::image<br />type(sdl_surface),pointer :: bitmap<br />integer :: idepth,ipitch,mm<br />allocate(image(iwidth*iheight*4))&nbsp; ! assumes 4 bytes (RGB + alpha per pixel)</p><p>call glReadPixels(0,0,iwidth,iheight,GL_RGBA,GL_UNSIGNED_BYTE,c_loc(image))<br />idepth=32<br />ipitch=4*iwidth<br />!ipitch=0<br />bitmap =&gt; SDL_Create_RGB_Surface_From(c_loc(image),iwidth,iheight,idepth,&amp;<br />&nbsp; &nbsp;ipitch, int(z&#039;000000ff&#039;,kind=i8),int(z&#039;0000ff00&#039;,kind=i8),&amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int(z&#039;00ff0000&#039;,kind=i8),int(z&#039;ff000000&#039;,kind=i8))<br />&nbsp; &nbsp; &nbsp; &nbsp;<br />mm=sdl_save_bmp(bitmap,&quot;test.bmp&quot;)</p><p>endsubroutine save_image2</p><br /><p>However I still get the same error:<br />At line 27 of file .\save_image2.f90<br />Fortran runtime error: Pointer actual argument &#039;bitmap&#039; is not associated<br />Error termination.</p><p>Can it be that bitmap is a &quot;sdl_surface pointer&quot; and sdl_save_bmp requires a &quot;sdl_surface&quot;??</p><p>If I fill out ipitch=0 the code runs, but the saved file is empty</p>]]></description>
			<author><![CDATA[null@example.com (csitters)]]></author>
			<pubDate>Tue, 07 Jan 2025 11:04:18 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4406#p4406</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4405#p4405</link>
			<description><![CDATA[<p>The runtime error is stating that the variable <em>bitmap</em> is not associated, meaning that the call to <a href="https://wiki.libsdl.org/SDL2/SDL_CreateRGBSurfaceFrom">SDL_Create_RGB_Surface_From</a> has failed and returned a null pointer.&nbsp; </p><p>One issue I can see is that pulling the pixels from OpenGL, you&#039;ve requested the format as <em>GL_RGB</em>, which will not include an alpha channel.&nbsp; Your SDL call, though, assumes an alpha channel is present, hence the 4 bytes per pixel.&nbsp; You probably want to use <em>GL_RGBA</em> on the call to <em>glReadPixels</em>.&nbsp; </p><p>Additionally, your call to <em>glReadPixels</em> is using a problematic pointer for image data.&nbsp; The function definition is actually expecting a <em>type(c_ptr)</em> that points to a region of memory that can store the image.&nbsp; What you really should have here instead is a Fortran pointer to allocated memory.&nbsp; </p><p>The declaration should be simply:</p><div class="codebox"><pre><code>integer(kind=GLbyte), dimension(:), pointer::image</code></pre></div><p>Next, before using it for anything, you need to allocate it to the image size:</p><div class="codebox"><pre><code>allocate(image(iwidth*iheight*4))  ! assumes 4 bytes (RGB + alpha per pixel)</code></pre></div><p>Finally, on your OpenGL call, you need to provide the C location of the array:</p><div class="codebox"><pre><code>call glReadPixels(0,0,iwidth,iheight,GL_RGBA,GL_UNSIGNED_BYTE,C_LOC(image))</code></pre></div><p>Likewise, on the call to SDL:</p><div class="codebox"><pre><code>bitmap =&gt; SDL_Create_RGB_Surface_From(C_LOC(image),iwidth,iheight,idepth,ipitch,&amp;
         int(z&#039;000000ff&#039;,kind=i8),int(z&#039;0000ff00&#039;,kind=i8),&amp;
         int(z&#039;00ff0000&#039;,kind=i8),int(z&#039;ff000000&#039;,kind=i8))</code></pre></div><p>I haven&#039;t run the code, though.&nbsp; Perhaps that will improve things.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Mon, 06 Jan 2025 12:32:09 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4405#p4405</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4404#p4404</link>
			<description><![CDATA[<p>As you probably are aware I am new to opengl and sld2<br />I managed to compile the software without errors.<br />when I run the programme it creates a bmp file, but it is empty.<br />I tried several things, but am not able to solve the problem.<br />I try to save a window of 750x500 pixels (iwidth x iheight) containing an 2D image of a FEM boundary with basepoints and numbering. </p><p>the routine that should do the job reads:</p><p>subroutine save_image2()</p><p>use opengl_glu<br />use opengl_glut<br />use common_window<br />use, intrinsic :: iso_fortran_env, only: i1 =&gt; int8, i8 =&gt; int64, r8 =&gt; real64,&amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stderr =&gt; error_unit, stdout =&gt; output_unit<br />use :: sdl2<br />use :: sdl2_image<br />use :: SDL2_mixer<br />use :: SDL2_ttf<br />&nbsp; &nbsp;<br />implicit none<br />type(c_ptr),dimension(0:iwidth*iheight*3) :: image<br />type(sdl_surface),pointer :: bitmap<br />integer :: idepth,ipitch,mm</p><p>call glReadPixels(0,0,iwidth,iheight,GL_RGB,GL_UNSIGNED_BYTE,image)<br />idepth=32<br />ipitch=4*iwidth<br />!ipitch=0<br />bitmap =&gt; SDL_Create_RGB_Surface_From(image,iwidth,iheight,idepth,ipitch,&amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int(z&#039;000000ff&#039;,kind=i8),int(z&#039;0000ff00&#039;,kind=i8),&amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int(z&#039;00ff0000&#039;,kind=i8),int(z&#039;ff000000&#039;,kind=i8))<br />mm=sdl_save_bmp(bitmap,&quot;test.bmp&quot;)</p><p>endsubroutine save_image2</p><br /><p>If I fill out ipitch = 0, I get the empty bmp file<br />if I fill out ipitch = 4*iwidth I get an error (see below)</p><p>At line 28 of file .\save_image2.f90<br />Fortran runtime error: Pointer actual argument &#039;bitmap&#039; is not associated<br />Error termination. </p><p>The window sizes iwidth and iheight are obtained via the common block &quot;common_window&quot;</p><p>I hope I provided enough information</p>]]></description>
			<author><![CDATA[null@example.com (csitters)]]></author>
			<pubDate>Sun, 05 Jan 2025 13:23:46 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4404#p4404</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4403#p4403</link>
			<description><![CDATA[<p>What exactly do you currently have in the <em>Linker</em> box of <em>Compiler Flags</em> in <em>Project Options</em>?&nbsp; Having just &quot;-lfortran-sdl2&quot; is not sufficient.&nbsp; What I had meant was that the previous library had been using the flag &quot;-lSDL_fortran&quot; I believe.&nbsp; But you actually need the complete flag set to link the actual SDL libraries:</p><div class="codebox"><pre><code>-lfortran-sdl2 -lSDK2.dll -lSDL2_image.dll -lSDL2_mixer.dll -lSDL2_ttf.dll</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Thu, 02 Jan 2025 18:52:21 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4403#p4403</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4402#p4402</link>
			<description><![CDATA[<p>dear Jeff,<br />Happy New year!<br />I seem to have the correct function calls: &quot;sdl_create_rgb_surface_from&quot; and &quot;sdl_save_bmp&quot;.<br />The library flag reads &quot;lfortran-sdl2&quot;.<br />However I still get undefined references. I hope you can help. A part of the *build status* looks like this:</p><p>==============================================================================<br />Generating Makefile... Okay<br />==============================================================================<br />Processing default resource<br />Generating atb_ex.dll.exe<br />C:/Users/csitt/AppData/Local/sfpm/64/lib\libfortran-sdl2.a(sdl2.o): In function `__sdl2_MOD_sdl_log_warn&#039;:<br />- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <br />C:\Users\jeffr\Workspace\packages\fortran_sdl2\fortran-sdl2/src/sdl2.f90:587: undefined reference to `SDL_LogWarn&#039;<br />C:/Users/csitt/AppData/Local/sfpm/64/lib\libfortran-sdl2.a(sdl2.o): In function `__sdl2_MOD_sdl_log_verbose&#039;:<br />- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <br />C:\Users\jeffr\Workspace\packages\fortran_sdl2\fortran-sdl2/src/sdl2.f90:578: undefined reference to `SDL_LogVerbose&#039;<br />C:/Users/csitt/AppData/Local/sfpm/64/lib\libfortran-sdl2.a(sdl2.o): In function `__sdl2_MOD_sdl_log_info&#039;:<br />- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <br />C:\Users\jeffr\Workspace\packages\fortran_sdl2\fortran-sdl2/src/sdl2.f90:569: undefined reference to `SDL_LogInfo&#039;<br />C:/Users/csitt/AppData/Local/sfpm/64/lib\libfortran-sdl2.a(sdl2.o): In function `__sdl2_MOD_sdl_log_error&#039;:<br />- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <br />C:\Users\jeffr\Workspace\packages\fortran_sdl2\fortran-sdl2/src/sdl2.f90:560: undefined reference to `SDL_LogError&#039;<br />C:/Users/csitt/AppData/Local/sfpm/64/lib\libfortran-sdl2.a(sdl2.o): In function `__sdl2_MOD_sdl_log_debug&#039;:</p>]]></description>
			<author><![CDATA[null@example.com (csitters)]]></author>
			<pubDate>Thu, 02 Jan 2025 18:14:27 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4402#p4402</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4401#p4401</link>
			<description><![CDATA[<p>thanks let me try.<br />Anyway strange call first time I see it like this.<br />I will let you know if it works.</p>]]></description>
			<author><![CDATA[null@example.com (csitters)]]></author>
			<pubDate>Mon, 30 Dec 2024 18:02:44 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4401#p4401</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4400#p4400</link>
			<description><![CDATA[<p><a href="https://github.com/interkosmos/fortran-sdl2/blob/2e08994a2fe0ac165109701fdbfde902e8c77b69/src/sdl2.f90#L243"><em>sdl_create_rgb_surface_from</em> does seem to be bound</a>.&nbsp; Are you using the correct function call?</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Mon, 30 Dec 2024 12:28:19 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4400#p4400</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4399#p4399</link>
			<description><![CDATA[<p>The ambiguous problem ha been solved. I had to disable the module &quot;open_gl&quot; (package F03GL), because it conflicted with the module &quot;sdl2&quot; (thanks to the remark of jeff).&nbsp; <br />However my problem still persists. The function SDL_CreateRGBSurfaceFrom remains not recognised. From readme.md (visual studio) the function still seems not to be bound (see line 326).</p><p>What I actually want is to save an opengl image to a file as a bitmap, jpg or another format. Perhaps somebody has a solution??</p>]]></description>
			<author><![CDATA[null@example.com (csitters)]]></author>
			<pubDate>Mon, 30 Dec 2024 12:10:33 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4399#p4399</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4398#p4398</link>
			<description><![CDATA[<p>Interesting, I didn&#039;t see this issue.&nbsp; Did you also reinstall:</p><p> - Simple DirectMedia Layer<br /> - SDL2_image<br /> - SDL2_mixer<br /> - SDL2_ttf</p><p>I&#039;m not sure it would upgrade those automatically.&nbsp; </p><p>You say you&#039;ve &quot;uninstalled and reinstalled opengl,&quot; but I&#039;m not sure I understand what package you&#039;re talking about.&nbsp; <em>glclearcolor</em> is available in the <em>sdl2</em> module, and it doesn&#039;t require any other imports.&nbsp; I&#039;m not sure if you&#039;re calling it directly or not.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Sat, 28 Dec 2024 19:48:08 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4398#p4398</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4397#p4397</link>
			<description><![CDATA[<p>I reinstalled fortran-sdl2.<br />I changed the library flag. in the file: sfpm&gt;templates&gt;readme_sdl.txt&gt;flags.txt<br />I cannot test if it works, because I have another compilation error, namely: ambiguous references:<br />for example:<br />Error: Name &#039;glclearcolor&#039; at (1) is an ambiguous reference to &#039;glclearcolor&#039; from module &#039;opengl_gl&#039;</p><p>I do not know how to solve this.<br />I uninstalled and reinstalled opengl, but it does not help.</p>]]></description>
			<author><![CDATA[null@example.com (csitters)]]></author>
			<pubDate>Sat, 28 Dec 2024 13:39:54 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4397#p4397</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4396#p4396</link>
			<description><![CDATA[<p>I&#039;ve updated <a href="https://packages.simplyfortran.com/package/90.html">fortran-sdl2 to the lastest repo version</a>, and it seems to be working fine.&nbsp; It is using the latest SDL2 packages as well.&nbsp; </p><p>One word of warning: the Fortran library name has changed, which could cause an existing project&#039;s linking step to fail.&nbsp; The library flag is now:</p><div class="codebox"><pre><code>-lfortran-sdl2</code></pre></div><p>Let me know if there&#039;s any problem!</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Fri, 27 Dec 2024 14:29:53 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4396#p4396</guid>
		</item>
		<item>
			<title><![CDATA[Re: fortran-sdl2 package]]></title>
			<link>http://forums.approximatrix.com/viewtopic.php?pid=4395#p4395</link>
			<description><![CDATA[<p>thanks Jeff</p>]]></description>
			<author><![CDATA[null@example.com (csitters)]]></author>
			<pubDate>Mon, 23 Dec 2024 17:32:45 +0000</pubDate>
			<guid>http://forums.approximatrix.com/viewtopic.php?pid=4395#p4395</guid>
		</item>
	</channel>
</rss>
