comp.lang.ada
 help / color / mirror / Atom feed
* Best way to put an array-based pixmap on a screen?
@ 2017-03-26  1:01 LaeMing Ai
  2017-03-26  8:25 ` Dmitry A. Kazakov
  2017-03-26  9:35 ` Dirk Craeynest
  0 siblings, 2 replies; 10+ messages in thread
From: LaeMing Ai @ 2017-03-26  1:01 UTC (permalink / raw)


I am hoping to learn some Ada with an explicit interest in simple software 3D rendering (ie: writing the render code in Ada, NOT calling external libraries such as OpenGL). I want to set up a shim between my Ada environment and my Linux Desktop to facilitate monitoring my output, without having to mess about with the daunting (I quickly found) task of interfacing to SDL or GTK+!

All I really want to see from my code's perspective is a 2D array of 32-bit pixel values that I can manipulate from my developing Ada code, and not have to worry about the intricacies of window managers. Is it possible to get help constructing a project template providing the following:

- Function to create a non-resizable X11 window of dimensions N high by 2N wide (N is nominally valued at 512, but could be any value of 2^x above 256).

- Callback for if the above window's close box is activated, to terminate the program.

- Function to copy an array of 2N by N of 32 bit values (8:Red 8:Green 8:Blue 8:ignored) to the above window.

At this stage I am not concerned with input to the window (other than the close box terminating the application, would be nice).

Packing it all into a single source file that I can put to the side and largely ignore would be nice too!

I particularly don't want event loops, or anything else dragged in from outside the Ada environment if at all possible - the point of using Ada is to learn to do all that /in/ Ada! :-)

I have played around with some AdaGTK examples but keep getting bogged down :-( . 

Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26  1:01 Best way to put an array-based pixmap on a screen? LaeMing Ai
@ 2017-03-26  8:25 ` Dmitry A. Kazakov
  2017-03-26  9:55   ` Simon Wright
                     ` (2 more replies)
  2017-03-26  9:35 ` Dirk Craeynest
  1 sibling, 3 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2017-03-26  8:25 UTC (permalink / raw)


On 2017-03-26 03:01, LaeMing Ai wrote:
> I am hoping to learn some Ada with an explicit interest in simple
> software 3D rendering (ie: writing the render code in Ada, NOT calling
> external libraries such as OpenGL).

Usually there is no access to the display around the OS. You will have 
to use some external library this or that way.

> I particularly don't want event loops, or anything else dragged in
> from outside the Ada environment if at all possible - the point of
> using Ada is to learn to do all that /in/ Ada!

You cannot draw into the RAMDAC, for obvious reasons. You do into a 
window controlled by the window manager. The window can get exposed, 
obscured, minimized etc. That brings a lot of stuff with it, events 
included.

> I have played around with some AdaGTK examples but keep getting bogged down :-( .

That is because you looked at the wrong place. Rendering under Gtk is 
done through Cairo (or far less frequently through OpenGL). Earlier 
versions of Gtk (<3.0) used other, very limited compared to Cairo, 
means. This is the stuff you probably found. Forget it, it is no longer 
supported.

Cairo rendering is more or less simple:

    https://www.cairographics.org/tutorial

 From the Gtk side you need a widget to draw into. The best candidate is 
Gtk_Drawing_Area for which you have to provide a handler of "draw" 
event. In the handler you receive a Cairo context, where all your 
drawing goes.

As an example you can take the Gtk_Layered widget. It consists of layers 
drawn upon each other:

    http://www.dmitry-kazakov.de/ada/aicwl.htm#2

You also can derive your own layer from the Abstract_Layer and let 
Gtk_Layered draw it.

If drawing pixmaps is the only thing you need, that is even simpler:

    http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#3

You can compile an XPM image into Ada code and use that to either to 
draw into a Cairo context (see above) or as a stand-alone image widget 
Gtk_Image.

P.S. An alternative to Gtk/Cairo is Qt. There are Ada Qt bindings as 
well. People here will surely help you with that too.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26  1:01 Best way to put an array-based pixmap on a screen? LaeMing Ai
  2017-03-26  8:25 ` Dmitry A. Kazakov
@ 2017-03-26  9:35 ` Dirk Craeynest
  1 sibling, 0 replies; 10+ messages in thread
From: Dirk Craeynest @ 2017-03-26  9:35 UTC (permalink / raw)


In article <cc019e12-33d8-4e05-910e-f9fc7f42fa06@googlegroups.com>,
LaeMing Ai  <laeming@exemail.com.au> wrote:
>[...] I want to set up a shim between my Ada environment and my Linux
>Desktop to facilitate monitoring my output, without having to mess
>about with the daunting (I quickly found) task of interfacing to SDL
>or GTK+!
>
>All I really want to see from my code's perspective is a 2D array of
>32-bit pixel values that I can manipulate from my developing Ada code,
>and not have to worry about the intricacies of window managers. [...]

You might want to take a look at the code Ludovic Brenta provided for
his series of presentations in several Ada Developer Rooms at past
FOSDEM events.  He used a minimal Ada interface to the xcb-library
to do exactly that, i.e. to display a 2D array of pixel values on
the screen.

For more info, see:

Ada DevRoom @ FOSDEM 2013
Ada Tasking: Multithreading Made Easy
<https://www.cs.kuleuven.be/~dirk/ada-belgium/events/13/130203-fosdem.html#multithreading>

Ada DevRoom @ FOSDEM 2014
Ada Task Pools: Multithreading Made Easy
<https://www.cs.kuleuven.be/~dirk/ada-belgium/events/14/140201-fosdem.html#multithreading>
video registration:
<http://ftp.belnet.be/FOSDEM/2014/K4601/Saturday/Ada_Task_Pools_Multithreading_Made_Easy.webm>

Ada DevRoom @ FOSDEM 2015
Multithreading Made Easy, part 3 - Bounded Work Queues
<https://www.cs.kuleuven.be/~dirk/ada-belgium/events/15/150131-fosdem.html#multithreading>
video registration (very low sound level):
<https://ftp.heanet.ie/mirrors/fosdem-video/2015/devroom-ada/multithreading__CAM_ONLY.mp4>
source distribution (latest version):
<https://www.cs.kuleuven.be/~dirk/ada-belgium/events/15/150131-fosdem/06-ada-multithreading.tgz>

HTH

Dirk
Dirk.Craeynest@cs.kuleuven.be (for Ada-Belgium/Ada-Europe/SIGAda/WG9)

*** 22nd Intl.Conf.on Reliable Software Technologies - Ada-Europe'2017
*** June 12-16, 2017 *** Vienna, Austria *** http://www.ada-europe.org


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26  8:25 ` Dmitry A. Kazakov
@ 2017-03-26  9:55   ` Simon Wright
  2017-03-26 13:27     ` reinert
  2017-03-26 19:10   ` Lucretia
  2017-03-26 21:00   ` BartC
  2 siblings, 1 reply; 10+ messages in thread
From: Simon Wright @ 2017-03-26  9:55 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On 2017-03-26 03:01, LaeMing Ai wrote:
>> I am hoping to learn some Ada with an explicit interest in simple
>> software 3D rendering (ie: writing the render code in Ada, NOT
>> calling external libraries such as OpenGL).
>
> Usually there is no access to the display around the OS. You will have
> to use some external library this or that way.

OP talked about using X11; there are, I'm sure, Ada bindings to X11 (the
one I used back in the day was based on a DEC tool, no longer accessible
I think).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26  9:55   ` Simon Wright
@ 2017-03-26 13:27     ` reinert
  2017-03-26 16:48       ` gautier_niouzes
  0 siblings, 1 reply; 10+ messages in thread
From: reinert @ 2017-03-26 13:27 UTC (permalink / raw)


In case it could be useful, here is a simple test program using GLOBE_3D (texture). I just started to use GLOBE_3D for fast (interactive) video-like rendering (programming in Ada).

reinert
https://korsnesbiocomputing.no/


with Text_IO; use Text_IO;
with GL,  GLUT.Devices;
use  GL,  GLUT.Devices;

procedure a1 is

  package Flt_Io is new Text_IO.Float_Io   (Float);
  package Int_Io is new Text_IO.Integer_Io (Integer);
  use Flt_Io,Int_Io;

  GLUT_Problem: exception;
  use GLUT;

  texDat : array (1..64) of aliased gl.ushort; 
  texDat_Ptr : constant pointer := to_Pointer(texDat(texDat'First)'unchecked_access);

  tex    : aliased GL.uint;
  tex_Ptr : constant GL.uintPtr := tex'unchecked_access; 
 
  n,k : Integer := 1;

begin

    glut.Init;
    glut.SetOption(GLUT.ACTION_ON_WINDOW_CLOSE, GLUT.ACTION_GLUTMAINLOOP_RETURNS);
    glut.InitDisplayMode( GLUT.DOUBLE or GLUT.RGB or GLUT.DEPTH );
    glut.InitWindowSize(800,600);
    glut.InitWindowPosition(1, 1);
    if glut.CreateWindow( "Tittel A" ) = 0 then
      raise GLUT_Problem;
    end if;
    glut.Devices.Initialize;

    n := texDat'First;
    for i in 1..8 loop
        for j in 1..8 loop
            k := (if i = j then 1 else 0);
            k := (if (i + j) mod 2 = 0 then 1 else 0);
            texDat(n) := gl.ushort(k*100 + 100);
            n := n + 1;
        end loop;
    end loop;

    gl.GenTextures(1, tex_Ptr);
    gl.BindTexture(GL.TEXTURE_2D, tex);

    gl.TexParameter(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST);
    gl.TexParameter(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST);

    gl.TexImage2D(GL.TEXTURE_2D, 0, GL.LUMINANCE, 8, 8, 0, GL.LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, texDat_Ptr);

    gl.BindTexture(GL.TEXTURE_2D, 0);
    gl.MatrixMode(GL.PROJECTION);
    gl.Ortho(0.0, 800.0, 0.0, 600.0, -1.0, 1.0);
    gl.MatrixMode(GL.MODELVIEW);
    gl.ClearColor(1.0, 1.0, 1.0, 0.0); 

    gl.Clear(GL.COLOR_BUFFER_BIT);

    gl.BindTexture(GL.TEXTURE_2D, tex);
    gl.Enable(GL.TEXTURE_2D);

    gl.Color(1.0, 1.0, 1.0, 1.0);
    gl_Begin(QUADS);
      gl.TexCoord(0.0, 0.0); gl.Vertex(100, 100);
      gl.TexCoord(0.0, 1.0); gl.Vertex(100, 500);
      gl.TexCoord(1.0, 1.0); gl.Vertex(500, 500);
      gl.TexCoord(1.0, 0.0); gl.Vertex(500, 100);
    gl_End;

    gl.Disable(GL.TEXTURE_2D);
    gl.BindTexture(GL.TEXTURE_2D, 0);
    gl.Flush;
    glut.SwapBuffers;

    Delay 10.0;

end a1;

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26 13:27     ` reinert
@ 2017-03-26 16:48       ` gautier_niouzes
  0 siblings, 0 replies; 10+ messages in thread
From: gautier_niouzes @ 2017-03-26 16:48 UTC (permalink / raw)


I think the OP would like to do the 3D rendering in Ada and not letting GL or a hardware layer do it.

Here is a specimen of Ada code doing the complete 3D -> 2D projection (and also almost everything else...) :

https://sourceforge.net/projects/engine-3d/

_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26  8:25 ` Dmitry A. Kazakov
  2017-03-26  9:55   ` Simon Wright
@ 2017-03-26 19:10   ` Lucretia
  2017-03-26 19:13     ` Lucretia
  2017-03-26 21:00   ` BartC
  2 siblings, 1 reply; 10+ messages in thread
From: Lucretia @ 2017-03-26 19:10 UTC (permalink / raw)


In response to the original message (which google doesn't have for some reason)...

I don't think this is harder than working with X11 directly, it's significantly easier:

https://github.com/Lucretia/sdlada/blob/master/test/stream2.adb line 183 which would give you per pixel access on a packed record each component being 8-bits, ARGB.

I still have to change the array discriminants to start at 0 instead of 1, because that just makes things easier with these particular pixel arrays.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26 19:10   ` Lucretia
@ 2017-03-26 19:13     ` Lucretia
  0 siblings, 0 replies; 10+ messages in thread
From: Lucretia @ 2017-03-26 19:13 UTC (permalink / raw)


On Sunday, 26 March 2017 20:10:17 UTC+1, Lucretia  wrote:
> 
> I still have to change the array discriminants to start at 0 instead of 1, because that just makes things easier with these particular pixel arrays.


I forgot to mention that I intend to incorporate line iterators which will iterate over the array 1 line at a time.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26  8:25 ` Dmitry A. Kazakov
  2017-03-26  9:55   ` Simon Wright
  2017-03-26 19:10   ` Lucretia
@ 2017-03-26 21:00   ` BartC
  2017-03-26 21:48     ` Dmitry A. Kazakov
  2 siblings, 1 reply; 10+ messages in thread
From: BartC @ 2017-03-26 21:00 UTC (permalink / raw)


On 26/03/2017 09:25, Dmitry A. Kazakov wrote:
> On 2017-03-26 03:01, LaeMing Ai wrote:
>> I am hoping to learn some Ada with an explicit interest in simple
>> software 3D rendering (ie: writing the render code in Ada, NOT calling
>> external libraries such as OpenGL).

> Cairo rendering is more or less simple:
>
>    https://www.cairographics.org/tutorial

Ah! Perhaps a simpler way to get into Cairo, since I got bogged down 
last time (trying to use it via C). I click Download on your link, 
scroll to Windows, and it says I need to download GTK+ as it will have 
Cairo.

OK, GTK download page, Windows, it says I will need GLib, cairo, Pango, 
ATK, gdk-pixbuf and GTK+ developer packages.... Then it says it's best 
to install MSYS2 to download binaries (we are still trying to download a 
simple rendering package, right?).

This is obviously going to lead nowhere. Back a few pages, it suggests 
Glade, but, looking at it, it appears to have nothing to do with GTK. Or 
with Cairo (remember that?).

A very familiar pattern.

I would suggest to the OP, especially if having similar problems trying 
to install purportedly 'simple' packages, to just create an N by 2N 
array of pixels, and draw directly into it.

But to view the result, it will necessary to write it to a file in some 
recognised format (PPM is perhaps the simplest), and use some external 
utility to display. Perhaps the OS will already be able to show it.

-- 
Bartc

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Best way to put an array-based pixmap on a screen?
  2017-03-26 21:00   ` BartC
@ 2017-03-26 21:48     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry A. Kazakov @ 2017-03-26 21:48 UTC (permalink / raw)


On 2017-03-26 23:00, BartC wrote:
> On 26/03/2017 09:25, Dmitry A. Kazakov wrote:
>> On 2017-03-26 03:01, LaeMing Ai wrote:
>>> I am hoping to learn some Ada with an explicit interest in simple
>>> software 3D rendering (ie: writing the render code in Ada, NOT calling
>>> external libraries such as OpenGL).
>
>> Cairo rendering is more or less simple:
>>
>>    https://www.cairographics.org/tutorial
>
> Ah! Perhaps a simpler way to get into Cairo, since I got bogged down
> last time (trying to use it via C). I click Download on your link,
> scroll to Windows, and it says I need to download GTK+ as it will have
> Cairo.
>
> OK, GTK download page, Windows, it says I will need GLib, cairo, Pango,
> ATK, gdk-pixbuf and GTK+ developer packages.... Then it says it's best
> to install MSYS2 to download binaries (we are still trying to download a
> simple rendering package, right?).

Well, it is how Gtk is (and most other C libraries are as well).

> This is obviously going to lead nowhere. Back a few pages, it suggests
> Glade, but, looking at it, it appears to have nothing to do with GTK. Or
> with Cairo (remember that?).

In fact the advise is correct. You should install MSYS2 and then *from* 
MSYS2 you do Cairo developing packages. The package management tool 
under MSYS2 is pacman.

Alternatively you can use MinGW packages from Debian or Fedora if you 
are more comfortable with apt and dnf/yum than with MSYS2 pacman.

Even simpler would be to install GtkAda. That includes Cairo. It is 
really simple: download, execute, ready.

> A very familiar pattern.

There is a reason why we dislike C. It is not much for the language as 
for the damage it inflicts on software developers, for the "culture of C".

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-03-26 21:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-26  1:01 Best way to put an array-based pixmap on a screen? LaeMing Ai
2017-03-26  8:25 ` Dmitry A. Kazakov
2017-03-26  9:55   ` Simon Wright
2017-03-26 13:27     ` reinert
2017-03-26 16:48       ` gautier_niouzes
2017-03-26 19:10   ` Lucretia
2017-03-26 19:13     ` Lucretia
2017-03-26 21:00   ` BartC
2017-03-26 21:48     ` Dmitry A. Kazakov
2017-03-26  9:35 ` Dirk Craeynest

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox