Image not displayed

Just starting out? Need help? Post your questions and find answers here.
FvEldijk
New User
New User
Posts: 8
Joined: Sun Sep 05, 2004 9:03 am

Image not displayed

Post 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)
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post 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)
FvEldijk
New User
New User
Posts: 8
Joined: Sun Sep 05, 2004 9:03 am

Post by FvEldijk »

If I understand corractly it was mainly the useimage() that does the trick here, am I right?
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post 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.
FvEldijk
New User
New User
Posts: 8
Joined: Sun Sep 05, 2004 9:03 am

Post 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?
aaron
Enthusiast
Enthusiast
Posts: 267
Joined: Mon Apr 19, 2004 3:04 am
Location: Canada
Contact:

Post 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.
FvEldijk
New User
New User
Posts: 8
Joined: Sun Sep 05, 2004 9:03 am

Post 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...
aaron
Enthusiast
Enthusiast
Posts: 267
Joined: Mon Apr 19, 2004 3:04 am
Location: Canada
Contact:

Post by aaron »

I don't know all the details of why it is this way, but I'm always willing to guess. :D 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. :o
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post 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.
Post Reply