Noob: (Or Just Dumb) Questions
BlitzMax Forums/BlitzMax Beginners Area/Noob: (Or Just Dumb) Questions
| ||
Set of questions 1) Global AnInt:Int (Or any basic type, Float etc) ..Does This actualy make space for an Int, or just a pointer to an Int 2) Global Atype:Type (Or any user type) ..Again does this actually make space for the Type, or just a pointer to the type? 3) AnInt = ADifferentInt ..Does this copy the value of ADifferentInt to AnInt. Or does AnInt just point to ADifferentInt? ..How would I do the reverse ? 4) AType = AnOtherOfTheSameType ..Does this copy the values of Types fields, or does Atype simply now point to AnOtherOfTheSameType 5) Function AFunction(A1:int,A2:type) Called By Afunction (Aint:Int,Atype:Type) ..A1 is Aint, or is a copy of Aint. ..A2 is Atype, is a copy of Atype or is a pointer to Atype 6) Global in Functions ..A Global in a Function is Static, yes? So it must exist outside of the Function, yes? So how do I access it? (I Think I read This in the Docs but cannot find it again) 7) What is the real difference between Image and Pixmap ..If I lock A Image, have I made a whole new PixMap? ..If all I want to do is paste to the back buffer which is better Image or Pixmap. (I want Mask) 8) Can someone tell me or point me to a link, on how to make an “Include” file into an “Import” file. (This might be easy to do, I wouldn’t know) 9) TImage.Load and Load Image (for example) Why is This? ..I understand the need to have the Functions for ppl who havent got the hang of OOP, but surly apart from when the object needs to be passed they should take the same parameters MyImage.Load( Ur1:Object,Flags,mr,mg,mb)Maybe Im missing something, all it would need would be Flags = -1, mr=NULL,etc then if mr is NULL use the Global Mask that Ive had to set? |
| ||
As far as I am aware, all Type variables are simply pointers to the data and not the data itself When you assign a type variable to a new type, you dont copy what was in that other type you simply change where the variable is pointing Thats all I can really help you with |
| ||
Set of questions It will make space for an Int and set it's value to 0.1) Global AnInt:Int (Or any basic type, Float etc) ..Does This actualy make space for an Int, or just a pointer to an Int 2) Global Atype:Type (Or any user type) ..Again does this actually make space for the Type, or just a pointer to the type? 3) AnInt = ADifferentInt ..Does this copy the value of ADifferentInt to AnInt. Or does AnInt just point to ADifferentInt? ..How would I do the reverse ? 4) AType = AnOtherOfTheSameType ..Does this copy the values of Types fields, or does Atype simply now point to AnOtherOfTheSameType 5) Function AFunction(A1:int,A2:type) Called By Afunction (Aint:Int,Atype:Type) ..A1 is Aint, or is a copy of Aint. ..A2 is Atype, is a copy of Atype or is a pointer to Atype 6) Global in Functions ..A Global in a Function is Static, yes? So it must exist outside of the Function, yes? So how do I access it? (I Think I read This in the Docs but cannot find it again) 7) What is the real difference between Image and Pixmap ..If I lock A Image, have I made a whole new PixMap? ..If all I want to do is paste to the back buffer which is better Image or Pixmap. (I want Mask) 8) Can someone tell me or point me to a link, on how to make an “Include” file into an “Import” file. (This might be easy to do, I wouldn’t know) 9) TImage.Load and Load Image (for example) Why is This? ..I understand the need to have the Functions for ppl who havent got the hang of OOP, but surly apart from when the object needs to be passed they should take the same parameters MyImage.Load( Ur1:Object,Flags,mr,mg,mb) Maybe Im missing something, all it would need would be Flags = -1, mr=NULL,etc then if mr is NULL use the Global Mask that Ive had to set? |
| ||
import vs include: include compiles the included file each time you hit F5 import assumes the included (imported) file is compiled already and just uses the compiled version of it immediately.. saves project compiling time! If you change something in your imported file, you need to compile that file again, if not, your main project will import the previous compiled version again.. just in case you wonder why no changes ever happen.. ^_^ |
| ||
7) Drawing to backbuffer is faster with TImage (up to 10 times), TPixmap is for manipulating the data in the image. And yes, lock an image creates a new pixmap. To make an image out of it again, just loadimage that pixmap. 8) There is nothing you have to change beside putting STrict / superstrict on top. The rest is the same. But you have to keep in mind that include will share globals, while import won't (the imported file only knows of globals etc it defined within itself or included / imported on its own) |
| ||
I believe that the pixmap will be copied back to the image when you unlock it. At least I've never had to loadimage the pixmap to see the changes. According to the Docs, LockImage will allow you to write to the image directly. Just to test, I tried entering this program. I definately do not need to LoadImage the pixmap to see the changes. |
| ||
Makes sense, so in that case forget the last part. Haven't used it that much lately as I haven't had any need for per Pixel operations on images. |
| ||
UnlockImage() is actually just an empty function as i understand it from looking at the code: TImage contains an array of TPixmaps and an array of TImageFrames - when an image is loaded, both arrays are populated when you lock an image, you're returned a pointer to the relevant pixmap and that frame is made null when the image needs to return a frame, if that frame is null it's copied from the pixmap - so "unlocking" is done automatically i assume the commands are only called lock/unlock for the sake of looking like blitz2d/3d |
| ||
From question 5: When passing an int to a function it creates a copy. How would one pass a pointer instead? (To create a function that returns more than 1 value) example: Local Row:Int = 1 Local Col:Int = 1 CalculateRowAndCol Row, Col Print Row Print Col Function CalculateRowAndCol (Row:Int, Col:Int) Row = 10 Col = 10 End Function I would like this to Print 10 10 and not 1 1 |
| ||
Declare it with VAR which will make sure that it references to the original variable within the function, not a copy of it. Function CalculateRowAndCol(row:int var, col:int var) |
| ||
Function CalculateRowAndCol (Row:Int Var, Col:Int Var) |
| ||
Thanks to both of you for the quick answer |
| ||
@Everyone, thanks for either the anwsers or clarification of the questions. However, I still dont get lock. If an image is in the video ram, and a pixmap is in cpu ram, and I lock an Image, and therefore make it a pixmap. Is the pixmap now in the Video ram? If it is, wouldnt drawPixmap on a locked image be faster than Drawing a "Normal" Pixmap? |
| ||
Pixmaps would be always in CPU RAM, weather from a locked image or otherwise, I think thats the point of them |
| ||
@Mordax, Thats what I had thought as well, but from the above answers to Lock/Unlock, If they are just moving pointers arround, then how can an image be in video ram, then locked, and not still be in the same ram? |
| ||
If you lock an image, the image remains in VRAM but a Pixmap will be generated in System RAM that holds a pixeldata array with the color information of the Image. When you unlock it, the previously existing image color data will be replaced by the ones of the pixmap. Its not possible to modify pixel data on VRAM *at least with the low end specs that BM has as minimum. If you would force a higher OpenGL version then it wouldn't be a problem as DX has such support without the need of extensions as OpenGL* |
| ||
When you unlock it, the previously existing image color data will be replaced by the ones of the pixmap. Are you sure? What information can you provide to show this happens? As mentioned before Unlockimage function doesn't do anything. |
| ||
As dan_upright said, The image is copied to a pixmap and the corisponding frame in the image is made null when you lock the image.. When you try to DrawImage, the engine sees that it is null and copies the pixmap back to the image and video RAM, making UNlock completely unnecissary. At least that seems to be the case. At any rate, at some point the pixmap is copied back to video RAM because you can see the results immediately when you use DrawImage. |
| ||
Yep, I agree. If you take the UnlockImage out of the code you posted earlier you get the same results. Unlockimage function does nothing. Anyway, Dreamora, what do you mean by... When you unlock it, the previously existing image color data will be replaced by the ones of the pixmap. and where did you get this information? |
| ||
So to sum, A) The Image is in Video Ram B) When Locked, a copy of that frame is moved to CPU Ram, and a pointer to that "New" pixmap is returned. C) The New Pixmap can be "Messed" with as normal, D) Then whenever a call to draw the original Image is gotten, the Pixmap is copied back into the Image, and the Pixmap Nulled E) UnLock does nothing, but is there so we dont panic and think we have all our images still locked. Questions/Clarification. What happens at point D) if I have just made the pixmap pointer point to a totally different Pixmap, (Different size, different RGB BGR etc) Point A, so if video Ram is full no more images? Or slower CPU ram images Point E, thats a joke isnt it? |
| ||
@tonyg: I believe he got that idea from me. I assumed the pixmap was copied back to VRAM when unlocked since I did not need to LoadImage the pixmap back to an image, but since Unlock does nothing, I was obviously mistaken. @H&K: I'd assume UnlockImage was placed there in case if a graphics driver in the future requires additional code to "Unlock" the image. So for that reason, it'd probably be a good idea to use it anyway so that you won't break your programs when SetGraphicsDriver HolodeckMax2DDriver() is finally developed. |
| ||
I say that on UnLock as I assume that it will become its use somewhen so having it in now, even if "pointless" can only result in something positive :-) *who knows perhaps we get real surface access as with Blitz3D / BlitzPlus at some point where the unlock might make a real difference* |
| ||
seems kinda messy... i would have thought that unlock would have forced an upload, in the much the same wasy as drawimage does.. allowing the user to control the upload time more cleanly. for example i may load some animimage, process some frames, and then upload the changes - before the game starts.. having to draw the images before this will happen seems slightly ugly..i wont want the stall to happen during gameplay.. still it doesnt really matter, i could create a util to output a new image, and simply load that into the game to achieve the same result..i jst wouldnt have expected the system to work as it does.. ..bmax seems to have lots of interesting features, and plenty of weirdness ;) :p |
| ||
@Defoc8, if you want to modify images before the game begins, you can always load them as pixmaps at the start, then LoadAnimImage the pixmap. |
| ||
when I remember correctly, you can enforce the "image from pixmap" step manually and not risking that a draw command will create weird behavior. |
| ||
hmm and how can that be forced manually then, any ideas? |
| ||
image.Frame(frame) should do the trick. |
| ||
weird but thanks. |