Page 1 of 1
Image not displayed
Posted: Sun Sep 05, 2004 10:55 am
by FvEldijk
Somehow I don't get this image displayed:
Code: Select all
InitKeyboard()
InitSprite()
OpenScreen(640,480,32,"")
test=LoadImage(#PB_Any,"test.bmp")
FlipBuffers()
StartDrawing(ScreenOutput())
DrawImage(test,0,0)
DrawText("This was a test")
StopDrawing()
FlipBuffers()
Repeat
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Can anyone out there tell me why?
(The image is loaded, no problem there)
Posted: Sun Sep 05, 2004 11:20 am
by GreenGiant
Here, you'd got a few things in the wrong order and stuff. Try this (I have also changed a couple of things, transparent text background, keyboardreleased rather than pressed, etc)
Code: Select all
InitKeyboard()
InitSprite()
OpenScreen(640,480,32,"")
test=LoadImage(#PB_Any,"test.bmp")
Repeat
ExamineKeyboard()
StartDrawing(ScreenOutput())
DrawImage(UseImage(test),0,0)
DrawingMode(1)
Locate(50,50)
DrawText("This was a test")
StopDrawing()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
Posted: Sun Sep 05, 2004 11:42 am
by FvEldijk
If I understand corractly it was mainly the useimage() that does the trick here, am I right?
Posted: Sun Sep 05, 2004 11:51 am
by GreenGiant
Yeah, pretty much. The changed postion of the repeat is worth noting too though. Its not strictly necessary for this, but as soon as you're actually moving/changing anything on screen you'll need to be updating the screen in a loop.
Posted: Sun Sep 05, 2004 1:00 pm
by FvEldijk
Ok... I think I understand the basics of image-drawing...
Now sprites bug me, here is the same example, now with a sprite:
Code: Select all
InitKeyboard()
InitSprite()
OpenScreen(640,480,32,"")
test=LoadSprite(#PB_Any,"test.bmp")
Repeat
ExamineKeyboard()
StartDrawing(ScreenOutput())
DisplaySprite(test,100,100)
DrawingMode(1)
Locate(50,50)
DrawText("This was a test")
StopDrawing()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
again, the sprite is not displayed... how come?
Posted: Sun Sep 05, 2004 1:14 pm
by aaron
sprites don't need to be displayed from within the startdrawing() : stopdrawing() stuff. Put the sprite command outside that and it should start working.
Posted: Sun Sep 05, 2004 1:18 pm
by FvEldijk
Ok!
Has it something to do with images being GDI stuff and sprites not? StartDrawing does a lock or something?
This purebasic is not at all easy...
Posted: Mon Sep 06, 2004 1:55 am
by aaron
I don't know all the details of why it is this way, but I'm always willing to guess.

Displaying a sprite is just a matter of copying (blitting) an image, so purebasic does it directly into the video card memory (via directx or SDL I guess). Drawing text (or some of the other commands like text or circle or whatever) is more complicated... so purebasic has to assemble an image in computer ram before dumping it to the video card memory. Using the startdrawing and stopdrawing commands tells the compiler what you are up too and makes sure that it doesn't waste time moving data back and forth for each of the drawing commands... only need to read video memory once (at the start) and write it back once (at the end).
Or something like that.

Posted: Mon Sep 06, 2004 11:33 am
by GreenGiant
I dont really know either, but I'm willing to make a (different) guess. My guess is that the sprite commands are directly taken from DirectX and work upon that system, directly drawing to a DirectX screen. And I'd guess the drawing commands are mostly taken from the api, and so require a device context to draw to. The startdrawing() command just sets which device context you're drawing to. Not sure about that, but it'd be my guess.