Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 13, 2019 4:26 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 6:53 am 
Offline

Joined: Thu Apr 02, 2009 11:34 am
Posts: 15
Location: Earth
Hi all,

I have the fllowing code:
Sub GCSprite.Constructor()
location = GCMakePoint(50, 50)
size = GCMakeSize(32,32)

texture = new OpenGLTexture()
//hard coded for testing purposes
dim image As picture = getFolderItem("Data").child("Sprites").child("Player").child("Falling.png").openAsPicture()

firstFrame = New Picture(32,32,32)

dim ffg as Graphics = firstFrame.graphics
dim ffmg as Graphics = firstFrame.mask.graphics

ffg.drawpicture image, 0, 0, 32, 32, 0, 0, size.width, size.height
ffmg.drawpicture image.mask, 0, 0, 32, 32, 0, 0, size.width, size.height

firstFrame.transparent = 1
call texture.LoadAsPicture(firstFrame)
End Sub


and im using the OpenGLTexture class from <insert name here>

and using the LoadAsPicture method as seen here:

Function LoadAsPicture(Image As Picture) As Boolean
' Disabling items to speed up loops
#IF ACCESS_DISABLE_OPTIONS
#Pragma BackgroundTasks False
#Pragma BoundsChecking False
#Pragma NilObjectChecking False
#Pragma StackOverflowChecking False
#ENDIF

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

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

' Setting Dimentions
ImageWidth = Image.Width
ImageHeight = Image.Height

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

' Storing local to speed things up
image_width = ImageWidth - 1
image_height = ImageHeight - 1

' Storing our RGB surface
surface = Image.RGBSurface()
mask = Image.Mask.RGBSurface()//i added this myself for debugging

' Setting our greyscale color(s?)
If BytesPerPixel = 1 Then
//code not needed as i never load a 1 pixel per byte image
//code is also removed for brevity.
' Setting our RGB colors
ElseIf BytesPerPixel = 3 Then
//im loading a picture with an alpha mask so this code is also irrelevant
' Setting our RGBA Colors
Elseif BytesPerPixel = 4 Then
Format = opengl.GL_RGBA
Dim value as Integer
' Setting our colors
For y = image_height DownTo 0
For x = 0 To image_width

' Storing our pixel
pixel = surface.Pixel( x, y )
mpixel = mask.Pixel( x, y )
' Storing our color
ImageData.Byte( count ) = pixel.Red
ImageData.Byte( count + 1 ) = pixel.Green
ImageData.Byte( count + 2 ) = pixel.Blue
'Value = mpixel.value * 255
'If Value <> 255 then break
ImageData.Byte( count + 3 ) = mpixel.value * 255

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

' Everything went OK
Return True
End Function



with that code i get the following image (bottom left part of the image is the one im talking about):
Image

now I'm curious to know why that is? in the debugger the image and mask seems to get copied just
fine from the source image...

also if it's relevant, if I load the image with GL_RGB and ignore the mask, I get the image fine, but no
mask... which is not what I'm going for...

any insights would be greatly appreciated thanks in advance and regards.

P.S.
Some of the code is hard coded values (such as the image to load for testing purposes)

_________________
Eric Hoaglin
GryphonClaw Software
Come Join the REALbasic IRC Channel on Freenode


Last edited by ss2cire on Sun Jan 31, 2010 6:17 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 11:16 am 
Offline

Joined: Fri Sep 30, 2005 11:19 am
Posts: 275
Try inverting the mask.

_________________
"If you look carefully at my lips, you'll realize that I'm actually saying something else."
Brainswitch Machina - REALStudio/REALbasic
RBScriptExtender - give RBScript power to work with any class


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 1:42 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
Do you have GL_BLEND enabled?

_________________
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: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 4:50 pm 
Offline

Joined: Thu Apr 02, 2009 11:34 am
Posts: 15
Location: Earth
Yeah, I've tried doing:

Sub Draw()
OpenGL.glPushMatrix()
OpenGL.glTranslatef(location.x, location.y, 0)

OpenGL.glEnable( OpenGL.GL_TEXTURE_2D )
OpenGL.glEnable(OpenGL.GL_ALPHA_TEST)
OpenGL.glEnable(OpenGL.GL_BLEND)
Texture.BindTexture()

OpenGL.glColor3f(1.0, 1.0, 1.0)
OpenGL.glBegin( OpenGL.GL_QUADS )
OpenGL.glTexCoord2f( 0.0, 0.0 )
OpenGL.glVertex2i( 0, 0 ) ' Bottom Left
OpenGL.glTexCoord2f( 0.0, 1.0 )
OpenGL.glVertex2i( 0, size.height ) ' Top left
OpenGL.glTexCoord2f( 1.0, 1.0 )
OpenGL.glVertex2i( size.width, size.height ) ' Top Right
OpenGL.glTexCoord2f( 1.0, 0.0 )
OpenGL.glVertex2i( size.width, 0 ) ' Bottom Right
OpenGL.glEnd()

OpenGL.glPopMatrix()
End Sub


but the result is exactly the same... Unless I'm missing something?

_________________
Eric Hoaglin
GryphonClaw Software
Come Join the REALbasic IRC Channel on Freenode


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 5:02 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
Try adding OpenGL.glBlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA)

_________________
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: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 5:09 pm 
Offline

Joined: Thu Apr 02, 2009 11:34 am
Posts: 15
Location: Earth
Blake wrote:
Try adding OpenGL.glBlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA)

That would be to my Open even of the OpenGLSurface or to my sprite draw code?

_________________
Eric Hoaglin
GryphonClaw Software
Come Join the REALbasic IRC Channel on Freenode


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 5:54 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
I would put it in the open event.

_________________
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: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 6:16 pm 
Offline

Joined: Thu Apr 02, 2009 11:34 am
Posts: 15
Location: Earth
Ok, I did that, and I have the same result :(

_________________
Eric Hoaglin
GryphonClaw Software
Come Join the REALbasic IRC Channel on Freenode


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 7:18 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
wait...with the OpenGLSurface you have to make sure you have 32 color/depth bits instead of the default 24.

_________________
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: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 8:43 pm 
Offline

Joined: Thu Apr 02, 2009 11:34 am
Posts: 15
Location: Earth
Ok... I changed both ColorBits and DepthBits to 32 and I still get the same result :(

_________________
Eric Hoaglin
GryphonClaw Software
Come Join the REALbasic IRC Channel on Freenode


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 8:47 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
hmm... I've never used GL_ALPHA_TEST so maybe don't enable it and see what happens?

_________________
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: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 8:49 pm 
Offline

Joined: Thu Apr 02, 2009 11:34 am
Posts: 15
Location: Earth
Ok this is weird... I set the values to 32 (Color and Depth) and I get the same results and then I even set them each to 0 and still get the same results.

I just commented out ALPHA_TEST and same results...

_________________
Eric Hoaglin
GryphonClaw Software
Come Join the REALbasic IRC Channel on Freenode


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 9:01 pm 
Offline

Joined: Thu Apr 02, 2009 11:34 am
Posts: 15
Location: Earth
I could post the project for you to take a look at if you don't mind, would the work?

_________________
Eric Hoaglin
GryphonClaw Software
Come Join the REALbasic IRC Channel on Freenode


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 9:13 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
yea ill take a look

_________________
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: OpenGL and Texture Transparency
PostPosted: Sun Jan 31, 2010 9:25 pm 
Offline

Joined: Thu Apr 02, 2009 11:34 am
Posts: 15
Location: Earth
OK, here's the project and everything I have so far:
OpenGL Project (44.4k)

_________________
Eric Hoaglin
GryphonClaw Software
Come Join the REALbasic IRC Channel on Freenode


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

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