New topic: OpenGL and Texture Transparency
<http://forums.realsoftware.com/viewtopic.php?t=32269> Page 1 of 1 [ 1 post ] Previous topic | Next topic Author Message ss2cire Post subject: OpenGL and Texture TransparencyPosted: Sun Jan 31, 2010 6:53 am Joined: Thu Apr 02, 2009 11:34 am Posts: 3 Location: Earth Hi all, I have the fllowing code: 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: Code: 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): 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. Eric Hoaglin GryphonClaw Software GryphonClaw Software P.S. Some of the code is hard coded values (such as the image to load for testing purposes) Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 1 post ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
