First BMax program
BlitzMax Forums/BlitzMax Beginners Area/First BMax program
| ||
Hello, I am new to BlitzMax and I'm having a hard time getting the simplest program to run. Can one shed any light on why this code fails? {code} CreateGraphics (1024,768,16,60,0) imagen = LoadImage("image1.jpg",0) DrawImage imagen,0,0,0 Flip WaitKey {/code} I keep getting a "call of null object method or property" (or something like that ) error. My guess is that the image is for some reason not loading. But the documentation does not specify which formats are supported. When I use Print on the "imagen" object, I get a 1, so I guess that the object is not really null. Also, the WaitKey command keeps on waiting even after I press a key. Why is this? |
| ||
You need to use SetGraphics with the returned Object from CreateGraphics Couldn't you just use the Graphics command instead as I think it does it automatically? |
| ||
imagen needs to be of type TImage. change imagen = LoadImage("image1.jpg",0) to imagen:TImage = LoadImage("image1.jpg",0) Also make sure the image is in the same directory as your program since you're not specifying a path. |
| ||
why not try out these beginner tutorials? http://www.2dgamecreators.com/tutorials/gameprogramming/basics/S1%20-%20First%20Program.html and then this http://www.blitzmax.com/Community/posts.php?topic=59509 |
| ||
Thanks everyone, I will certainly try out the tutorials. I was able to make it run using Azathoth's suggestion about the Graphics command. Apparently, there are various way to initiate a graphics display. For what purpose is still beyond me. I own Blitz3D and am just starting with BMax. Thanks everyone. |
| ||
CreateGraphics (or create in general) are functions that create an object with return for later usage. The graphics usage is mainly for canvases so you can change the "drawn" context. For regular usage, Graphics should be enough :-) |
| ||
Actually, it's not necessary to specify imagen as type:Timage. If not specified as a Timage, it will simply be treated as a handle to that image. The problem is, you then need to explicitly call Release on the image when you are done with it or it won't be cleaned up until the program ends. It's definitely wisest to just specify all images as a Timage. |
| ||
There is another reason to specify it: Using objects through Int Handles is 5 - 40 times slower than using proper reference types (like :TImage), as BM first must find the object that is assigned to the int instead of accessing it directly. |
| ||
5 to 40 times slower? arent these these ints used to index a table of pointers?, does it really make that much difference? we are all oopy here anyway.. again..im not in the know, so perhaps im totally mistaken, but i wouldnt have thought that grabbing a pointer from a table/array would be that expensive.. it may be that bmax allocates small pages for index/pointer arrays - and the number is broken into page/index.. this would make memory management perhaps a little less heavy, and the cost of dereferencing wouldnt be too high...heh..ok ill shut up ;) |
| ||
Jepp, it makes such a large difference. BM isn't optimized around this int handle stuff anymore, as Blitz3D / Blitz Plus were, it is focused on the typed usage. *the int handle stuff isn't handled by the regular memory manager ie Garbage Collector, which might be the reason it suffers that badly. In Strict / superstrict I think you can't use them anyway* The largest impact I know of so far are banks, which are seriously useless when used with int handles ... |
| ||
Good to know that about the banks. I better go check my code! :) |
| ||
arent these these ints used to index a table of pointers? It looks like it:myImage1 = CreateImage(16,16) myImage2 = CreateImage(16,16) Print myImage1 Print myImage2However since ints aren't typesafe (is you could possibly just go DrawImage 1, 0 , 0 ) I would assume that the act of determining whether "1" is an image or not, and thus can be drawn, could add significant overhead. I somehow doubt we're talking anything near an order of magnitude performance hit tho'. |