comp.lang.ada
 help / color / mirror / Atom feed
* OpenGL Texture mapping
@ 2004-12-16 18:45 Alfredo Macias
  2004-12-16 20:15 ` tmoran
  2004-12-16 21:33 ` Martin Krischik
  0 siblings, 2 replies; 5+ messages in thread
From: Alfredo Macias @ 2004-12-16 18:45 UTC (permalink / raw)


Hi all,
I'm working on an Ada project that renders 3D graphics.
While I'm using openGl with no problems for 3D graphics, I'm trying to
implement texutre mapping.  I'm getting the code for texture mapping from a
working CPP project.  However, I'm having trouble getting the translated
code to compile in Ada.  Here is the code:
--------------------------------------
type Unsigned_Char_Type is new Interfaces.C.Unsigned_Char;
type Pix_Color_Type   is array (1 .. 3) of aliased Unsigned_Char_Type;
type Data_Buffer_Type is array (Positive range <>) of aliased
Pix_Color_Type;

Width : Integer := 256;
Height: Integer := 256;
Data :  Data_Buffer_Type;

------------------------------------
      Gl.GlTexImage2D(
              Gl.Gl_TEXTURE_2D,
              Gl.Glsizei(0),
                Gl.Pixelformatenm'(Gl.Gl_Rgb),
                Gl.Glsizei(Width),
                Gl.Glsizei(Height),
              Gl.Glsizei(0),
                Gl.Pixelformatenm'(Gl.Gl_Rgb),
                Gl.Pixeldatatypeenm'(Gl.Gl_Unsigned_Byte),
                Gl.Glpointer
                      (Gl_Pointer_Conversions.To_Pointer
                             (Data(1)(1)'Address)));
-----------------------------------------------------
This is the nasty message I recevie from the compiler; which tells me close
to nothing.
(A also tried without type casting, but got the same message)

1/2: COMP    graphics.platforms.renderers(body) rsd/adalib

  2498:       Gl.GlTexImage2D(
              ---------------- ...
  2509:                              (Data(1)(1)'Address)));
                                     ----------------------
>>> SEMANTIC: Unresolvable expression <8.3, 8.6:28> <RM83 8.3, 8.7:3>

Any ideas why this code is not compiling?
Any help would be greatly appreciated.






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

* Re: OpenGL Texture mapping
  2004-12-16 18:45 OpenGL Texture mapping Alfredo Macias
@ 2004-12-16 20:15 ` tmoran
  2004-12-16 21:33 ` Martin Krischik
  1 sibling, 0 replies; 5+ messages in thread
From: tmoran @ 2004-12-16 20:15 UTC (permalink / raw)


>Here is the code:
>...
>type Data_Buffer_Type is array (Positive range <>) ...
>Data :  Data_Buffer_Type;
  Surely not.



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

* Re: OpenGL Texture mapping
  2004-12-16 18:45 OpenGL Texture mapping Alfredo Macias
  2004-12-16 20:15 ` tmoran
@ 2004-12-16 21:33 ` Martin Krischik
  2004-12-17  1:09   ` Alfredo Macias
  1 sibling, 1 reply; 5+ messages in thread
From: Martin Krischik @ 2004-12-16 21:33 UTC (permalink / raw)


Alfredo Macias wrote:

> type Data_Buffer_Type is array (Positive range <>) of aliased
> Data :  Data_Buffer_Type;

An indefinite type without contraint and without initialisation? That does
not work. Read here to find out why:

http://en.wikibooks.org/wiki/Programming:Ada:Subtypes#indefinite_subtype

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

* Re: OpenGL Texture mapping
  2004-12-16 21:33 ` Martin Krischik
@ 2004-12-17  1:09   ` Alfredo Macias
  2004-12-17  8:32     ` Martin Krischik
  0 siblings, 1 reply; 5+ messages in thread
From: Alfredo Macias @ 2004-12-17  1:09 UTC (permalink / raw)


Sorry for the confusion, I only included what I thought was the most
relevant code, but that is just a part of it.

Data :  Data_Buffer_Type; is actually an incoming parameter to this
procedure where I'm trying to do the texture mapping.
Which means that Data was originally instantiated by the caller and
initialized to values read from a bitmap file, so by the time Data is
received by my texture mapping procedure, Data actually contains 256*256
bytes with the bitmap data.  (I have output its contents as text and
manually verified it for correctness right before my call to
Gl.GlTexImage2D).

So other than that, does anything else look incorrect?
Thank you


"Martin Krischik" <martin@krischik.com> wrote in message
news:1243716.dEx2WVfu6a@linux1.krischik.com...
> Alfredo Macias wrote:
>
> > type Data_Buffer_Type is array (Positive range <>) of aliased
> > Data :  Data_Buffer_Type;
>
> An indefinite type without contraint and without initialisation? That does
> not work. Read here to find out why:
>
> http://en.wikibooks.org/wiki/Programming:Ada:Subtypes#indefinite_subtype
>
> With Regards
>
> Martin
>
> -- 
> mailto://krischik@users.sourceforge.net
> http://www.ada.krischik.com





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

* Re: OpenGL Texture mapping
  2004-12-17  1:09   ` Alfredo Macias
@ 2004-12-17  8:32     ` Martin Krischik
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Krischik @ 2004-12-17  8:32 UTC (permalink / raw)


Alfredo Macias wrote:

> Sorry for the confusion, I only included what I thought was the most
> relevant code, but that is just a part of it.
> 
> Data :  Data_Buffer_Type; is actually an incoming parameter to this
> procedure where I'm trying to do the texture mapping.
> Which means that Data was originally instantiated by the caller and
> initialized to values read from a bitmap file, so by the time Data is
> received by my texture mapping procedure, Data actually contains 256*256
> bytes with the bitmap data.  (I have output its contents as text and
> manually verified it for correctness right before my call to
> Gl.GlTexImage2D).
> 
> So other than that, does anything else look incorrect?

No! But tell you the truth: before I would post a statement like this to
c.l.a I would break it up - one function call at a time - and store all
intermediate result in temporary variables.

declare:

X0 : .... renames Data(1)(1);
X1 : System.Address := X0'Address; 
X2 : .... := Gl_Pointer_Conversions.To_Pointer (X1)
X3 : .... := Gl.Glpointerᅵᅵ(X2)

begin
ᅵᅵᅵᅵᅵᅵGl.GlTexImage2D(
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵGl.Gl_TEXTURE_2D,
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵGl.Glsizei(0),
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵGl.Pixelformatenm'(Gl.Gl_Rgb),
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵGl.Glsizei(Width),
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵGl.Glsizei(Height),
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵGl.Glsizei(0),
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵGl.Pixelformatenm'(Gl.Gl_Rgb),
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵGl.Pixeldatatypeenm'(Gl.Gl_Unsigned_Byte),
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ.... => X3);
end

That way you get a more meaningfull errror message. Also better if you ever
need to use the debugger. And no difference in perfomace once the optimizer
found out that each variable is only used once. The GNAT optimizer will
actually tell you that all variables are "constant".

BTW: you should name the parameters when there are more then three - I you
need to read your code in half a year you'll be gratefull for it ;-) .

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

end of thread, other threads:[~2004-12-17  8:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-16 18:45 OpenGL Texture mapping Alfredo Macias
2004-12-16 20:15 ` tmoran
2004-12-16 21:33 ` Martin Krischik
2004-12-17  1:09   ` Alfredo Macias
2004-12-17  8:32     ` Martin Krischik

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