It is currently Mon Dec 11, 2017 5:08 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 3:05 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 25, 2013 5:38 am
Posts: 189
Location: Australia
Is it possible to resize an image to another existing one, or to the screen? I have looked at ResizeImage() and it does not do what I want. The reason I want to do this is to simulate a lower resolution in my game engine. ResizeImage() could do it if I create a new image each frame which is obviously not a good idea.

Edit: sorry my bad again I hope you don't mind my beginner questions :oops:

You can do this with DrawImage() by setting the width and height.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 4:53 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3425
Location: Utah, USA
If using a screen do it with sprites and controling the zoom.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 5:28 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 25, 2013 5:38 am
Posts: 189
Location: Australia
I did it with DrawImage() but it takes huge amounts of CPU. EDIT: I will post up an example soon

EDIT: Please have a look at my example. Is there a faster way to do the resize? It's consuming a LOT of CPU to do this. Surely there is a faster way?

Code:
EnableExplicit

Define.i Event, Quit

Quit = 0

InitSprite()
InitKeyboard()

CreateImage(0, 320, 240, 32)

OpenWindow(0, 0, 0, 640, 480, "Test Environment", #PB_Window_SystemMenu | #PB_Window_Maximize | #PB_Window_MaximizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), #False, 0 , 0, #PB_Screen_WaitSynchronization)

Repeat
  ; Draw the circle to the temp image buffer
  StartDrawing(ImageOutput(0))
  Box(0, 0, 320, 240, 8723235)
  Circle(160, 120, 50, #Yellow)
  StopDrawing()
 
  ; Copy the temp image buffer to the screen resizing it
  StartDrawing(ScreenOutput())

  DrawImage(ImageID(0), 0, 0, WindowWidth(0), WindowHeight(0))
  ; **********************************************************
  ; Why does this take so much CPU especially when maximised?
  ; **********************************************************
  StopDrawing()
 
  FlipBuffers()
  ExamineKeyboard() 
 
  If KeyboardReleased(#PB_Key_Escape) : Quit = 1 : EndIf
 
  Repeat
    Event = WindowEvent()
    If Event = #PB_Event_CloseWindow : Quit = 1 : EndIf
  Until Event = 0

Until Quit


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 6:36 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 25, 2013 5:38 am
Posts: 189
Location: Australia
Is there a way to access the images and screen memory manually with ASM? I think I would need to rewrite this function to be faster.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 8:34 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 202
Location: Côtes d'Azur, France
Like it was said before, use zoomsprite and sprite.

Each time you can avoid using stardrawing()/stopdrawing() in your main loop, it's better.
You should use it as few as possible.(once per loop is alright, no more)
Sprites are the fastest.

Code:
EnableExplicit

Define.i Event, Quit

Quit = 0

InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 640, 480, "Test Environment", #PB_Window_SystemMenu | #PB_Window_Maximize | #PB_Window_MaximizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), #False, 0 , 0, #PB_Screen_WaitSynchronization)
;create new sprite 0
CreateSprite(0,320,240)
;draw inside sprite 0 one time only
  StartDrawing(SpriteOutput(0))
  Box(0, 0, 320, 240, 8723235)
  Circle(160, 120, 50, #Yellow)
  StopDrawing()
Repeat
;zoom sprite
ZoomSprite(0,ScreenWidth(),ScreenHeight())
;display sprite
DisplaySprite(0,0,0)

 
  FlipBuffers()
  ExamineKeyboard() 
 
  If KeyboardReleased(#PB_Key_Escape) : Quit = 1 : EndIf
 
  Repeat
    Event = WindowEvent()
    If Event = #PB_Event_CloseWindow : Quit = 1 : EndIf
  Until Event = 0

Until Quit

_________________
There are 2 methods to program bugless.
But only the third works fine.


Last edited by Fig on Tue Jan 10, 2017 8:50 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 8:38 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 25, 2013 5:38 am
Posts: 189
Location: Australia
Thank you Fig I should have tried myself. I looked at Sprite and thought it was wrong to Zoom a sprite 60 times a second but I guess that's what it's designed for? I guess the image functions are not designed for this task. Thanks again. EDIT: Thank you also Demivec :oops:


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 8:43 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 202
Location: Côtes d'Azur, France
Yes it's been designed for.
You can display thousandS of sprites without any problem.

_________________
There are 2 methods to program bugless.
But only the third works fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 11:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 25, 2013 5:38 am
Posts: 189
Location: Australia
That's good I assume a good game needs many sprites displayed. I have another problem now, I can't get the sprite to be transparent. When I try this code all I get is a black screen. Shouldn't it clear the sprite with a transparent box? Shouldn't there be a blue and a yellow circle?

Code:
EnableExplicit

Define.i Event, Quit, Sprite

Quit = 0

InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 640, 480, "Test Environment", #PB_Window_SystemMenu | #PB_Window_Maximize | #PB_Window_MaximizeGadget)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), #False, 0 , 0, #PB_Screen_WaitSynchronization)
;create new sprite
Sprite = 257
CreateSprite(Sprite, 320, 240, #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(Sprite))

Box(0, 0, 320, 240, RGBA(0,0,0,0))
Circle(100, 120, 10, #Blue)
StopDrawing()


StopDrawing()
Repeat
  StartDrawing(ScreenOutput())
  Circle(160, 120, 50, #Yellow)
  StopDrawing()
  ;zoom sprite
  ZoomSprite(Sprite,ScreenWidth(),ScreenHeight())
  ;display sprite
  DisplayTransparentSprite(Sprite,0,0)
  FlipBuffers()
  ExamineKeyboard() 
 
  If KeyboardReleased(#PB_Key_Escape) : Quit = 1 : EndIf
 
  Repeat
    Event = WindowEvent()
    If Event = #PB_Event_CloseWindow : Quit = 1 : EndIf
  Until Event = 0
 
Until Quit


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Tue Jan 10, 2017 11:56 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 25, 2013 5:38 am
Posts: 189
Location: Australia
I figured it out, I needed to specify the correct amount of alpha

EDIT: It doesn't do what I wanted it for anyway, you can't output a sprite to a sprite.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Wed Jan 11, 2017 9:23 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 202
Location: Côtes d'Azur, France
I don't know what you really want, but i am sure you can do something else than puting a sprite in an other sprite to achieve your goal.
Think out of the box ^^

_________________
There are 2 methods to program bugless.
But only the third works fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: Resize one image to another existing one (or screen)
PostPosted: Thu Jan 12, 2017 2:11 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Nov 25, 2013 5:38 am
Posts: 189
Location: Australia
Yup, I was thinking wrong :) You can do it just zooming sprites. And if I REALLY want to zoom standard drawing routines then I can draw to a sprite, zoom it then paste it in. Plus if I REALLY want to apply filters then I can access the video buffer directly. But I don't need to. I was just stuck in some wrong thinking. All sorted now, I needed to learn at some point.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye