Pixmap transparency

BlitzMax Forums/BlitzMax Programming/Pixmap transparency

Pineapple(Posted 2011) [#1]
I can't seem to get my pixmap to have a transparent background.

I have SetBlend alphablend and I tried maskblend. The pixmap format is PF_RGBA8888, and I did ClearPixels but it's not transparent.

What am I missing?


Oddball(Posted 2011) [#2]
You'd need to explain more. If you are drawing TPixmaps directly they are never drawn with transparency. For that you need to convert them to TImages first. Other than that we'd need more info, or see the offending code/image.

Last edited 2011


Pineapple(Posted 2011) [#3]
I was trying to draw pixmaps directly.

Is it very taxing to convert a pixmap to an image?

Also, how?

Not using pixmaps would be pretty costly, so I'm hoping I can keep that up. The conversion would be infrequent and the images would be small, so I don't think it'd be that bad.

Last edited 2011


Jesse(Posted 2011) [#4]
drawpixmap doesn't work with any of the filters. converting pixmaps to images is a bit slow because the pixmap has to be converted to a texture and passed to the video card for display. I have never done any speed test. I did that for a project a while back and was unable to use it for my needs. but that was because I used a pixmap that was 800x600 and was constantly modifying its content.
I think the best way to use it is to create an image, lock to modify its pixmap then display it. it won't be that much faster though as pixmaps are converted to textures before displaying them and that's exactly what happens with locked images.


Tommo(Posted 2011) [#5]

converting pixmaps to images is a bit slow because the pixmap has to be converted to a texture and passed to the video card for display


Use 2^n sized PF_RGBA8888 pixmap can save some image process time.


Jesse(Posted 2011) [#6]
yes, that will help some but not much as the main problem is in converting from one format to the other and passing it to the video card. less of a difference if the pixmaps are small.

it will not make any difference if you make the image is 35x35 or 64x64. in either case it will be processed as a 64x64 image. it will make a difference if your image is 65x65 and you change it to 64x64. as the 65x65 will be processed as 128x128 and the 64x64 will be processed as a 64x64.

Last edited 2011


Tommo(Posted 2011) [#7]
framework brl.max2d
import brl.glmax2d
import brl.d3d9max2d
import brl.standardio
strict

local driver:TMax2DDriver
driver = GLMax2DDriver()
'driver = D3D9Max2DDriver()

local stdFormat%
local nonStdFormat%

if driver = GLMax2DDriver()
	stdFormat = PF_RGBA8888
	nonStdFormat = PF_BGRA8888
	print("GL:")
else
	stdFormat = PF_BGRA8888
	nonStdFormat = PF_RGBA8888
	print("D3D:")
endif

local testCount% = 200
SetGraphicsDriver(driver)

graphics 400, 300

local p1:TPixmap = CreatePixmap(256, 256, stdFormat) '2^n
local p2:TPixmap = CreatePixmap(257, 257, stdFormat) 'non 2^n
local p3:TPixmap = CreatePixmap(256, 256, nonStdFormat) 'non stdformat

local m1%
gccollect()
m1 = millisecs()
for local i% = 0 until testCount
	driver.CreateFrameFromPixmap(p1, FILTEREDIMAGE)
next
print("2^n:~n~t" + (millisecs() - m1))

gccollect()
m1 = millisecs()
for local i% = 0 until testCount
	driver.CreateFrameFromPixmap(p2, FILTEREDIMAGE)
next
print("non 2^n:~n~t" + (millisecs() - m1))


gccollect()
m1 = millisecs()
for local i% = 0 until testCount
	driver.CreateFrameFromPixmap(p3, FILTEREDIMAGE)
next
print("non std format:~n~t" + (millisecs() - m1))


gccollect()
m1 = millisecs()
for local i% = 0 until testCount
	driver.CreateFrameFromPixmap(p1, FILTEREDIMAGE | MIPMAPPEDIMAGE)
next
print("mipmap:~n~t" + (millisecs() - m1))


Here's a little benchmark. It seems that the difference is not that small.

Last edited 2011


Jesse(Posted 2011) [#8]
that's a kind of a one sided test but none the less it proves me wrong. I would also include the other way around:


Last edited 2011


Czar Flavius(Posted 2011) [#9]
For people who are too lazy to run the code or work out what's going on, could I have the test conclusions please :)


AdamRedwoods(Posted 2011) [#10]
DrawPixmap + setblend alphablend should work directly, if the image itself has a _proper_ alpha layer.

Notes on speed:
- if the pixmaps are preset, load them into images before any main loops
- if the pixmaps must be dynamic, loading the pixmaps into one main pixmap, THEN displaying that single pixmap as an image is faster than loading many pixmaps
- creating many small pixmaps into one large pixmap, then uploading that one pixmap into an image (then using drawimageSUBrect) may be faster.
- using a faster drawpixmap() routine can sometimes work as well (search around)


drawing pixmap onto pixmap routines:
http://blitzmax.com/codearcs/codearcs.php?code=2658


Oddball(Posted 2011) [#11]
AdamRedwoods wrote:
DrawPixmap + setblend alphablend should work directly, if the image itself has a _proper_ alpha layer.
Please explain. In GLMax2D the DrawPixmap command sets the blend mode to SOLIDBLEND within the function so how can a TPixmap be drawn with alpha using DrawPixmap?


Jesse(Posted 2011) [#12]
true. there is no way to display just the pixmap as normal images with the provided functionality of BlitzMax modules.


skidracer(Posted 2011) [#13]


Also, how?





myimage=LoadImage(pixmap)

this effectively copies the pixel data to your graphics card for use with high speed hardware accelerated blending aka DrawImage.


Jesse(Posted 2011) [#14]
@skid
We all know that but that's not what this thread is about. it's a bout getting the pixmap to the screen as effectively as drawimage with all of the bells and whistles of an image which we don't think can be achieve. At lest not with the current graphics modules design.


Yan(Posted 2011) [#15]
We all know that but that's not what this thread is about. it's a bout getting the pixmap to the screen as effectively as drawimage with all of the bells and whistles of an image which we don't think can be achieve. At lest not with the current graphics modules design.
In your eyes, perhaps. However, the thread's author did ask...
Is it very taxing to convert a pixmap to an image?

Also, how?



Jesse(Posted 2011) [#16]
sorry, I guess that in the process of translating the code to Spanish I miss-interpretted the code. It would take a graciously intelligent person like you to make me understand it.
it's still a bit misleading to me.
I guess LoadImage(Pixmap) is not taxing.
and I guess LoadImage(pixmap) is not converting pixmap to images?

Last edited 2011


AdamRedwoods(Posted 2011) [#17]
Please explain. In GLMax2D the DrawPixmap command sets the blend mode to SOLIDBLEND within the function so how can a TPixmap be drawn with alpha using DrawPixmap?


You are right! I am wrong. I modified my DrawPixmap() long ago....

similar to this:
Function FastGLDrawPixmap(p:TPixmap, x:Int, y:Int)
	glDisable(GL_TEXTURE_2D)
	glpixelzoom(1, -1)
	glRasterPos2i(0, 0)
	glBitmap(0, 0, 0, 0, x, -y, Null)
	glPixelStorei(GL_UNPACK_ROW_LENGTH, p.pitch Shr 2)
	glDrawPixels(p.width, p.height, GL_RGBA, GL_UNSIGNED_BYTE, p.pixels)
End Function