Why doesn't this work?

BlitzMax Forums/BlitzMax Programming/Why doesn't this work?

Craig H. Nisbet(Posted 2007) [#1]
can anyone tell my why this doesn't work?

Graphics 800,600

Local myPic:TPixmap = LoadPixmap("spark1.png")

While Not KeyDown(KEY_ESCAPE)
	Cls()
	DrawPixmap myPic,MouseX(),MouseY()
	Flip
Wend


when I run this the screen is empty. The image is valid. I don't get it.

The only way I've been able to get this to work is to create a new pixmap and manually copy all the pixels to the new pixmap. Am I doing something wrong?


Craig H. Nisbet(Posted 2007) [#2]
Ok, that's strange.

This worked...
Graphics 800,600

Local myPic:TPixmap = LoadPixmap("spark1.png")
myPic:TPixmap = myPic.convert(PF_BGRA8888)

While Not KeyDown(KEY_ESCAPE)
	Cls()
	DrawPixmap myPic,MouseX(),MouseY()
	Flip
Wend



tonyg(Posted 2007) [#3]
Where did you get spark1.png from and what format is it in?


Vlad(Posted 2007) [#4]
@Craig H. Nisbet
Your sample works fine at my system. But I've used my own picture.
But DrawPixmap uses obsolete drawing method BitBlt. Not supports alpha, rotation, etc. Use LoadImage/DrawImage and don't miss to set blending mode SetBlend(alphablend)
Also you don't attach image (spark1.png) - all troubles can be in that image.


Craig H. Nisbet(Posted 2007) [#5]
Where did you get spark1.png from and what format is it in?

the image is from the sample/shooter/gfx folder.

Your sample works fine at my system. But I've used my own picture.
But DrawPixmap uses obsolete drawing method BitBlt. Not supports alpha, rotation, etc. Use LoadImage/DrawImage and don't miss to set blending mode SetBlend(alphablend)
Also you don't attach image (spark1.png) - all troubles can be in that image.


So...is there way to access the pixmap from the Loadimage commands?


tonyg(Posted 2007) [#6]
Using that image and your code works fine for me with 1.26 Bmax.
When you Loadimage you create a pixmap plus a texture which can be drawn to a surface using drawimage.
This means you can access the pixmap of the image (using lockimage) and change it. The next time you draw the image it will load the new texture into videomem


Craig H. Nisbet(Posted 2007) [#7]
Wow, it works for you? Must be something with my video card or Vista.


Dreamora(Posted 2007) [#8]
Newer drivers might decide to NOT convert wrong pixel formats when uploading.

This might be the reason for the create surface problem mentioned in the Blitz3D Bugboard as well ...

the "drivers do programmers work" approach costs performance, performance NVIDIA would like to use against ATI not against itself.
so at best / correct way you check the pixel format and convert it if needed.


N(Posted 2007) [#9]
So...is there way to access the pixmap from the Loadimage commands?
Call LockImage. You'll have to unlock it when you're done using the pixmap. This is not a good way to get it, however, since the image will be buffered again once you unlock it (you cannot draw the image while it's locked) and will require the image to be loaded as a dynamic image. You should consider loading the pixmap separately and storing them both alongside each other if you need the pixmap.

If you plan on modifying it and reloading the image, however, you should load it as a dynamic image. The documentation, poor as it is, details this at least at a basic level.