From: "Chad R. Meiners" <crmeiners@hotmail.com>
Subject: Re: AdaSDL and glTexImage2D
Date: Wed, 29 Jan 2003 15:15:44 -0500
Date: 2003-01-29T15:15:44-05:00 [thread overview]
Message-ID: <b19cth$c2k$1@msunews.cl.msu.edu> (raw)
In-Reply-To: 49981b.cu.ln@ID-soos.user.dfncis.de
"Stefan Soos" <stefan.soos@gmx.de> wrote in message
news:49981b.cu.ln@ID-soos.user.dfncis.de...
>
> Hello,
>
> I'm doing some programming in Ada with the thin binding to the SDL
> library. I'd like to create some textured objects, but there I run
> into some problems. My texture data is stored in an SDL surface:
>
> Image : SDL.Video.Surface_ptr;
>
> The actual data can be read from Image.Pixels. Now, I'd like to call
> glTexImage2D:
> glTexImage2D (GL_TEXTURE_2D,
> 0,
> GLint (GL_RGBA),
> GLsizei (Width), GLsizei (Height),
> 0,
> GL_RGBA,
> GL_UNSIGNED_BYTE,
> GLubyte_Array (Image.Pixels));
> but this doesn't work. How can I convert Image.Pixels (wich is
> actually defined as System.Address) to an array of GLubyte?
Well what you want to do is bit more complicated than what a simple type
conversion function can do for you automatically.
Image.Pixels is of type System.address. First System.Address doesn't have
any bounds information, but there is hope because Ada gives you a very nice
package called System.Address_To_Access_Conversions. This package is IMHO a
very cool package because it lets you transform System.Address into any type
you would like. However invoking it in this case will be a little bit
tricky since your array will need bounds information added to it. I don't
have immediate access to the GL libraries so I can't give you the exact code
to solve your problem, but I can point you to an example in the AdaSDL thick
binding where a similar conversion takes place.
In AdaSDL-Video-Drawing.adb around line 273 you will find:
declare
subtype Current_Screen is Screen_Eight(1..Array_Size);
package Convert is new System.Address_To_Access_Conversions
(Current_Screen);
begin
Eight_Bit_Draw
( On => Convert.To_Pointer (Item.Item.Pixels).all, -- The
important conversion
Colors => To_Palette_Provider (Item),
Coordinates => Coords);
end;
Here is a example of converting the Image.Pixels (in this case
Item.Item.Pixels ;) into an access to an array of size Array_Size. Notice
that we had to declare a subtype of the Screen_Eight array with a specified
range so that the compiler can reconstruct the range information.
Now I am guessing that GLubyte_Array is an array of bytes. So for your code
your solution might look like this
declare
Bytes_Per_Pixel : constant := 4; -- I believe RGBA is 32 bit color, but
if I am wrong in your case change this value
subtype Current_Buffer is
GLubyte_Array(0..(Width*Height*Bytes_Per_Pixel)-1);
package Convert is new
System.Address_To_Access_Conversions(Current_Buffer);
begin
glTexImage2D (GL_TEXTURE_2D,
0,
GLint (GL_RGBA),
GLsizei (Width), GLsizei (Height),
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
Convert.To_Pointer (Image.Pixels).all);
end;
Now remember this might need some tinkering to get it right since I don't
have the packages to test this out.
I hope this solves your problem,
Chad R. Meiners
next prev parent reply other threads:[~2003-01-29 20:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-29 10:09 AdaSDL and glTexImage2D Stefan Soos
2003-01-29 20:15 ` Chad R. Meiners [this message]
2003-01-30 9:52 ` Stefan Soos
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox