DrawImage Crash
BlitzPlus Forums/BlitzPlus Beginners Area/DrawImage Crash
| ||
First day with BlitzPlus! Also haven't figured out how to post code here (e.g. screenshot) other than copy and paste, so please forgive me. Am attempting to load and draw a background image, and then to display text on top. Text was working just fine by itself; however, the moment I introduced the Fdrawbackdrop function, the window began bombing out. Moreover, even with all the font and text code removed, the window still crashes. I have yet to get any image to draw! :( My image is saved in the same folder as the .bb file. I have also tried moving the .bb and image files into the root of the BlitzPlus folder, with no success. I have tried .jpg and .tga extensions, also with the same results. What is my day one noob mistake? I'd be eternally grateful for any help! Thank you. ; enable graphics mode -------------- ; use iphone4 resolution Graphics 640,960,32,2 SetBuffer BackBuffer() ; define backdrop Global backdrop = LoadImage("backtest01.tga") ; load fonts to a file handle variable Global defaultfont = LoadFont("Cutiepie",48) SetFont defaultfont ; game loop: hit escape to exit While Not KeyHit(1) Cls Fdrawbackdrop() Flip ; display text Text 320,780,"TEST1",True,True Text 320,830,"TEST2",True,True Wend End ; function: draw background Function Fdrawbackdrop() DrawImage(backdrop,0,0) End Function |
| ||
Pretty sure Blitzplus doesn't support .tga format, so that's your first problem. Other than that, and taking into account that you said you tried .jpg format with the same result, it might be an idea to expand upon "it crashes". I.e. what error message? |
| ||
Standard MS crash report: --- blitzcc.exe has encountered a problem and needs to close. We are sorry for the inconvenience. --- If tgas aren't supported, do I need to use pngs for alpha? |
| ||
BlitzPlus doesn't support native alpha at all, you need to use a hardware-accelerated graphics library for that, like e.g. *cough* <self-plug> bOGL-2 </self-plug>. The built-in image commands are "pure" 2D, which means old-style "pixel crunching" graphics only (basically all they can do is blit solid, aligned rectangles, occasionally with some pixels fully masked out). PNG should work for images in general though, as should JPG. Putting the image with your running source file is the right place: BlitzPlus doesn't care where things are relative to the BlitzPlus compiler itself. You can turn on Debug mode (Program -> Debug Enabled - should be ticked) to get more advanced and informative error messages that will refer back to your source instead of just crashing dumbly. You might also want to replace the actual call to Fdrawbackdrop with a Text line that prints out the current value of "backdrop": if it's 0, the image didn't load (seems obvious in this case, but always worth doing to narrow things down). Also, this sounds a lot like it could be related to this problem: http://www.blitzbasic.com/Community/post.php?topic=100631&post=1189867 Make sure you have "show file extensions" (or whatever it's called) checked in Windows, or you have a good chance of using incorrect filenames that the system is helpfully hiding from you. As an aside, when you get this working, your Text lines will no longer show as they're caught between the Flip and the next Cls: everything you want to be drawn to screen should come before the Flip. |
| ||
Nothing wrong with a bit of <self-plug> :) Thanks so much guys. I've got pngs working fine. Also, jpgs are now working too. I haven't figured out why they weren't working before; I suspect I was attempting to load one of my source jpgs which was saved in my source art folder. (Am assuming that all images must be saved in the same folder AND tier as the .bb file?) Am a little surprised that native alpha isn't supported (although no idea why I'm surprised). And this double-buffering malarky is gonna take some getting used too. Debug mode is going to be a Godsend - thank you! Really appreciate your help guys! (Suspect I'll be hanging out on the forums quite a bit for the foreseeable future...) |
| ||
Am assuming that all images must be saved in the same folder AND tier as the .bb file? Nah you can put them where you like: the main .bb file's folder is just where it defaults to looking. You can get at relative locations using the standard relative path syntax (e.g. "in the parent folder" -> "../backtest01.jpg"; "in the Media folder" -> "Media/backtest01.png"). You can also use absolute paths (bad idea, since you don't know where an end-user will put your program), and you can also change the current working directory with ChangeDir (e.g. say you have a lot of images to load in "Media": change to that, load them with simple filenames, change to ".." to restore to where you were). And of course you can use variable and dynamically-constructed strings to get to dynamically chosen locations, e.g. "LoadImage( ChooseDir() + ChooseName() + ChooseExtension() )". |