Locking + unlocking an image doesnt work
BlitzMax Forums/BlitzMax Programming/Locking + unlocking an image doesnt work
| ||
Hi all, bit difficult as I am not at home (where I have found a fix) but I have an issue, and looking around it looks like it shouldnt be broken. now, the graphics context is created as normal, the code that is failing: Global image:timage=CreateImage(maxx,maxy,1,filteredimage+dynamicimage) Local pixmap:TPixmap=LockImage(image) WritePixel(pixmap,10,10,$ffffff00) UnlockImage(image) DrawImage(image,0,0) Flip WaitKey I see nothing! I found that I have to use a command to re-insert the pixmap into the image (Again, i'm not at home and can't seem to find the function to do this.) My question is- why does the above code not work? |
| ||
Works perfectly here (once you set a graphics mode, and set maxx and maxy to non-zero values but I assume you know that). |
| ||
I see nothing! I found that I have to use a command to re-insert the pixmap into the image (Again, i'm not at home and can't seem to find the function to do this.) It works for me. are maxx & maxy defined? Btw, you dont need to handle the pixmap->image stuff as its done at next DrawImage. |
| ||
Your code doesn't work as there is no GRAPHICS command and maxx/maxy are both 0. Graphics 800,600 Global image:timage=CreateImage(256,256,1,FILTEREDIMAGE|DYNAMICIMAGE) Local pixmap:TPixmap=LockImage(image) WritePixel(pixmap,10,10,$ffffff00) UnlockImage(image) DrawImage(image,0,0) Flip WaitKeyHowever, that does only put 1 single pixel into the image. |
| ||
hmm, seems that what IS working for some, isnt working for me, on any of my machines. my actual code is: SuperStrict Global maxx:Int=128 Global maxy:Int=128 Graphics maxx,maxy Global image:timage=CreateImage(maxx,maxy,1,filteredimage+dynamicimage) Local pixmap:TPixmap=LockImage(image) WritePixel(pixmap,10,10,$ffffff00) UnlockImage(image) DrawImage(image,0,0) Flip WaitKey End So you can see I am defining graphics etc. The other app that is having this issue is using higher resolutions in case that is an issue. I got around it on the other machine by setting the images pixmap, though this caused a slowdown. So, this code *should* work, but isn't....? I don't see the single pixel that I have written. if I DrawPixmap, it works. If I drawImage, I see nothing. [edit] Works on a third machine. Wierdness!!! |
| ||
Your code works for me as is. Just to make it clearer, does this not show anything either : with/ GL driver, and with/without the loadimage from the pixmap? What version of Bmax are you using and is this something which once worked OK? The fact it is occurring on more than one of your machines is odd so what are the spec of both. SuperStrict Global maxx:Int=128 Global maxy:Int=128 ' setgraphicsdriver glmax2ddriver() Graphics maxx,maxy Global image:timage=CreateImage(maxx,maxy,1,filteredimage+dynamicimage) Local pixmap:TPixmap = LockImage(image) For Local x:Int = 0 To ImageWidth(image) - 1 For Local y:Int=0 To ImageHeight(image)-1 WritePixel(pixmap , x,y , $ffffff00) Next Next UnlockImage(image) ' image=loadimage(pixmap) DrawImage(image,0,0) Flip WaitKey End |
| ||
GL just crashes out on this machine. (intel onboard). it works in DX if I do loadimage. The machines are completely different. this ones an Optiplex GX520, Pentium 4 HT,512mb ram, intel graphics. The one at home, is a toshiba laptop, intel core duo 1.83ghz, Nvidia 7600 graphics, 1gb ram. Both are running blitzmax 1.28. I have had problems on two nvidia systems (both actually had the 7600...) and this intel. Previously I had written a planet generator that would refuse to draw the graphics on the nvidia machines but it worked fine on other peoples. The laptop uses 81.xx drivers (no choice of my own unless I want the card to fry itself) and the optiplex is bang up to date. I'll use Loadimage for now (or image.setpixmap which I think is the fix I used back at home.) Thanks for helping guys. |
| ||
Maybe a daft question, but you aren't using Framework/Import that might be leaving out something important? Happened to me in the past, and I didn't get an error. Stuff just didn't work. |
| ||
i've seen this before... when you create an image it doesn't always create an assosiated pixmap straight away. So when you try to lock it, there is no pixmap to lock. When drawing the image it will always create a pixmap before drawing. So add a "drawimage image,-maxx,-maxy" just after you create it. Global image:timage=CreateImage(maxx,maxy,1,filteredimage+dynamicimage) drawimage image,-maxx,-maxy ' draw offscreen Local pixmap:TPixmap = LockImage(image) This should fix it. |
| ||
What if you load it as a pixmap, then 'unlock' it to create a TImage? Does that solve the problem in a slightly neater way? |
| ||
Nope. But that is not needed. To create a TImage from a Pixmap you just LoadImage(TPixmap) :) And its funny that above works. Graphics context at 128x128 is a seriously bad idea and should normally lead to all kind of funny problems if you try to edit a 128x128 texture |
| ||
@dreamora, Yep, i'm aware there might have been issues with the graphics size, but the above code still fails at 640x480 etc. @GfK. yeah i've had that issue before too, not the problem here though. My planet gen actually got around the problem by grabbing a pixmap instead of creating a blank one. I really need to be at home to see exactly how i've fixed the problem on those machines. Right, I'll return when I get back home then :-) |