Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Aug 17, 2019 5:51 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: glTexImage2D?
PostPosted: Thu Dec 10, 2009 12:05 am 
I'm trying to make a 2D texture image that I can pass to glTexImage2D from a Picture.
Can you show me how to get the pointer to the bytes of the picture to pass as the last parameter to glTexImage2D?


Top
  
Reply with quote  
 Post subject: Re: glTexImage2D?
PostPosted: Thu Dec 10, 2009 12:07 am 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
I know the picture has to be in a memory block with each byte being a RGB(A) value moving bottom left to top right for the direct declare call, let me look into the OpenGL. call and see if its the same.

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Last edited by Blake on Thu Dec 10, 2009 12:12 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: glTexImage2D?
PostPosted: Thu Dec 10, 2009 12:11 am 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
Yeah, it appears to be the same, here is a quick function turn the picture into a memoryblock.

Function PictureToMemBlock(Image As Picture, BytesPerPixel As Integer) As MemoryBlock

' Disabling items to speed up loops
#Pragma BackgroundTasks False

' Local properties
Dim x, y, count, image_width, image_height As Integer
Dim surface, mask As RGBSurface
Dim pixel As Color
Dim image_data As MemoryBlock

' If we received a bad picture
If Image = Nil Or Image.RGBSurface = Nil then _
Return Nil

' Storing local to speed things up
image_width = Image.Width - 1
image_height = Image.Height - 1

' Creating our Image Data memory block
image_data = NewMemoryBlock( ( ImageWidth * ImageHeight * BytesPerPixel ) + BytesPerPixel )

' Storing our RGB surface
surface = Image.RGBSurface()
mask = Image.Mask.RGBSurface()

' Setting our greyscale color(s?)
If BytesPerPixel = 1 Then

For y = image_height DownTo 0
For x = 0 To image_width

' Storing our pixel
pixel = surface.Pixel( x, y )

' Storing our color
image_data.Byte( count ) = pixel.Red

' Increasing our position in the memory block
count = count + 1
Next
Next

' Setting our RGB colors
ElseIf BytesPerPixel = 3 Then

For y = image_height DownTo 0
For x = 0 To image_width

' Storing our pixel
pixel = surface.Pixel( x, y )

' Storing our color
image_data.Byte( count ) = pixel.Red
image_data.Byte( count + 1 ) = pixel.Green
image_data.Byte( count + 2 ) = pixel.Blue

' Increasing our position in the memory block
count = count + 3
Next
Next

' Setting our RGBA Colors
Elseif BytesPerPixel = 4 Then

' Setting our colors
For y = image_height DownTo 0
For x = 0 To image_width

' Storing our pixel
pixel = surface.Pixel( x, y )

' Storing our color
image_data.Byte( count ) = pixel.Red
image_data.Byte( count + 1 ) = pixel.Green
image_data.Byte( count + 2 ) = pixel.Blue
image_data.Byte( count + 3 ) = mask.Pixel( x, y ).Value * 255

' Increasing our position in the memory block
count = count + 4
Next
Next
End If

' Everything went OK
Return image_data
End Function

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: glTexImage2D?
PostPosted: Thu Dec 10, 2009 12:23 am 
Nice!!! Thank you.

OpenGL.glTexImage2D(
OpenGL.GL_TEXTURE_2D,
0,
3,
text.width,
text.height,
0,
OpenGL.GL_RGB,
OpenGL.GL_UNSIGNED_BYTE,
PictureToMemBlock(text, 3)
)
void glTexImage2D(
GLenum target,
   GLint    level,
   GLint    internalFormat,
   GLsizei    width,
   GLsizei    height,
   GLint    border,
   GLenum    format,
   GLenum    type,
   const GLvoid *    data
);


Last edited by JustSomeGuy on Thu Dec 10, 2009 12:31 am, edited 2 times in total.

Top
  
Reply with quote  
 Post subject: Re: glTexImage2D?
PostPosted: Thu Dec 10, 2009 12:30 am 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
add _ at the end of the line if it continues onto the next line

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: glTexImage2D?
PostPosted: Thu Dec 10, 2009 12:31 am 
Sorry I just broke 1 long line into many for this posting for easier reading...


Top
  
Reply with quote  
 Post subject: Re: glTexImage2D?
PostPosted: Thu Dec 10, 2009 12:36 am 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
hmm, not sure, here is a line that I use (direct declares)

glTexImage2D( GL_TEXTURE_2D, 0, Format, ImageWidth, ImageHeight, 0, Format, Type, ImageData )


vs what you have

OpenGL.glTexImage2D( OpenGL.GL_TEXTURE_2D, 0, 3, text.width, text.height, 0, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE, PictureToMemBlock( text, 3 ) )


it should work perfectly, I'm lost on this one.

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group