Using incbin

BlitzMax Forums/BlitzMax Beginners Area/Using incbin

AD(Posted 2006) [#1]
How do you use incbin on both images and text files? I'm really confused what you're meant to do with it.

' This code uses inc-bin to get a small red image (5x5) in size and is meant to show the image on the screen.

Import brl.ramstream

Incbin "stars.png"

Global stars=LoadImage( "incbin::stars.png" )


Graphics 800, 600

While Not KeyHit(KEY_ESCAPE)	
      ' Clear the screen...

      Cls

      ' Store mouse position in these global variables...

      mx = MouseX ()
      my = MouseY ()

	DrawImage stars, mx, my

Wend


And how do you use incbin for text files? The below example is obviousily wrong, but the document and manual does not give any instructions or sample code on how to use it.

The text file just has three names, each on a seperate line (e.g. Tom, @#!*, Harry)

Import brl.ramstream

Incbin "names.txt"

Global names=ReadFile( "incbin::names.txt" )

Graphics 800, 600

While Not KeyHit(KEY_ESCAPE)	

   ' Clear the screen...	
	Cls
	
	' Store mouse position in these global variables...
	
	mx = MouseX ()
	my = MouseY ()
	
	DrawText names, mx, my

Wend
End


Any chance someone can put up a short tutorial or explain how to use incbin?

Many thanks!


Diablo(Posted 2006) [#2]
well first of all it would help if you presented it to the front buffer instead of leaving on the back one (add a flip after you drawen everthying).

incbin is used to store files in the exe file you get when you complie thus making your exes massive.

i wouldnt use it while testing and such like only on distro.

basicaly if you incbin, once you have complied you wont need any of the resources that you incbined.


AD(Posted 2006) [#3]
Ah, I see -- I understand -- that's why its not outputting anything. Thank you very much for your help!


degac(Posted 2006) [#4]
Well at the moment I have not the Max help file under my nose, bu I think the problem is in the readfile(); this command should returns a handle to the file, then you need to read from that stream. You should read how ReadFile() works, then where the files is on disk on in Ram is not important.
Byez


AD(Posted 2006) [#5]
I'll just stick with data statements for the moment. Thanks anyway!


Diablo(Posted 2006) [#6]
oh yes and that too... didnt notic the other code.

if you want to read everything in a file you can use:


I KNOW, YOU SHOULD NOT DO IT LIKE THIS but you get the idea (its not a good idea to read a file every itteration you should read it once and then store the data in somthing (an array might be a good choice here).


FlameDuck(Posted 2006) [#7]
You're not actually loading anything from the text file.

You need to do something like this (not tested, should work):
Incbin "names.txt"

Global names=ReadFile( "incbin::names.txt" )

local name1:String = ReadLine(names)
local name2:String = ReadLine(names)
local name3:String = ReadLine(names)

CloseFile names

Graphics 800, 600

While Not KeyHit(KEY_ESCAPE)	

   ' Clear the screen...	
	Cls
	
	' Store mouse position in these global variables...
	
	mx = MouseX ()
	my = MouseY ()
	
	DrawText name1, mx, my
	DrawText name2, mx, my + 10
	DrawText name3, mx, my + 20
	Flip
Wend
End