Other pixmap questions, etc

BlitzMax Forums/BlitzMax Programming/Other pixmap questions, etc

Russell(Posted 2010) [#1]
DrawPixmap() does not take the current origin into account? (DrawPixmap source code reveals that the x and y origins are not added to the drawing position, unlike DrawImage() and the other drawing commands). This has caused me many hours of headscratching/headbanging to locate the source of my blank images!

So, if you're using DrawPixmap() and SetOrigin() together, be sure to add the x offset and y offset used in SetOrigin to the x and y for DrawPixmap().

GrabPixmap() (and other commands such as MouseX()/MouseY()) also use the actual absolute screen coordinates.

The Alpha channel: Even if I establish a 32 bit dislpay mode and a create pixmaps with an alpha channel, no matter what values I write into the "upper" byte of the pixel value in a pixmap it has no affect on the actual pixmap: No transparency is seen in any of the pixels.

Graphics 1920,1080,32
SetColor(255,255,0)
DrawRect(0,0,100,100)
SetColor(255,0,0)
DrawText("Hello",0,0)

Local pix:TPixmap = GrabPixmap(0,0,100,100)
DrawPixmap(pix,0,0)
For Local y:Int = 0 Until pix.height
	For Local x:Int = 0 Until pix.width
		WritePixel(pix,x,y,(128 Shl 24) | (ReadPixel(pix,x,y) & $FFFFFF))
	Next
Next

DrawPixmap(pix,0,50)
Flip
WaitKey()

Am I doing something wrong here?

Russell


Brucey(Posted 2010) [#2]
From what I understand, DrawPixmap just copies the raw rgb data to the graphics card for drawing.
With some cards/drivers it is *highly* inefficient - so much so, that pushing it into a TImage every frame is in fact faster!

I tend to avoid DrawPixmap() like the plague...


jkrankie(Posted 2010) [#3]
Yeah, pixmaps are sloooooooow.

Cheers
Charlie


Jesse(Posted 2010) [#4]
you can convert it to an image before drawing it, which will also solve your problem of the origin:
image = loadimage(pixmap)
drawimage image,x,y

Really you should start with an image access its pixmap then draw the image:
local image:Timage = createImage(640,480)
local pixmap = lockImage(image)

'modify pixmap then just draw the image no loadImage necessary.

DrawImage image,x,y



[edit]

be aware that drawing pixmaps in windows 7 and vista is not friendly at all..


Russell(Posted 2010) [#5]
Then what's so great about pixmaps? Why even have them? They seem to have virtually no advantages whatsoever over TImages...

And what about the alpha channel?

Russell


Jesse(Posted 2010) [#6]
Actually pixmap are good for modifying pixels of a Timage. I believe there might be a compatibility issue with direct 9x. pixmap's was designed for dx7 and I doubt Mark has even taken a look at it sense then but you might want to find out from the man himself.


Russell(Posted 2010) [#7]
That's ok: I've converted everything to TImages and all is well in the world. :)

Russell


Brucey(Posted 2010) [#8]
Then what's so great about pixmaps? Why even have them? They seem to have virtually no advantages whatsoever over TImages...

A TImage *contains* a TPixmap. The TPixmap is the actual pixel data stored in RAM. The TImage is a reference to that data on the graphics card.


ImaginaryHuman(Posted 2010) [#9]
This is actually because of the fact that the GPU can only really access the content of *video ram*, not main memory. And because of the way the API's are set up ie OpenGL and DirectX, in their simpler forms, it's generally not possible to just store a bitmap in video ram and access its pixels. OpenGL pretty much `requires` some concept of a pixmap in main memory, even if it's just a block of allocated memory containing pixel data. You have to somehow get that data from a file on disk into main memory before you can upload it to the video ram for the GPU to access. Also you need main memory bitmaps for all the image file loading and saving routines. And like other said you must have them if you want to use the CPU to modify individual pixels in a way that's compatible with the graphics API. A TImage is a separate copy of the pixel data in video ram while a TPixmap is a separate copy of the pixel data in main memory. Also for efficiency reason's it's better to have two copies of the image this way because you can then, for example, use the TImage to draw an image while you use a TPixmap to do per-pixel collision detection.