Author Topic: Magnification . . .  (Read 7395 times)

0 Members and 1 Guest are viewing this topic.

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Magnification . . .
« on: September 27, 2006 »
Hello again - tis only me . . . DrewPee

thought I would share this code!

Comments, feedback - very much appreciated!

Regards to you all - DrewPee
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Magnification . . .
« Reply #1 on: September 27, 2006 »
Welldone dude :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Magnification . . .
« Reply #2 on: September 28, 2006 »
Looks really nice :)
Would look even better centred and without the sleep 40!!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Magnification . . .
« Reply #3 on: September 28, 2006 »
Yeah - sorry about that . . . ive never had problems with basic being so fast before - not sure how to sort that but hopefully will get there! - will work out centering too!

Thanks for the comments.

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline MrP

  • Atari ST
  • ***
  • Posts: 176
  • Karma: 18
    • View Profile
Re: Magnification . . .
« Reply #4 on: September 29, 2006 »
Very Nice.... if you need some help with slowing things down and getting a smoother refresh lemme know......

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Magnification . . .
« Reply #5 on: September 30, 2006 »
The best way to sort out the speed is to use Jim + Rbraz's ptc lib :) Guaranteed rock steady refresh rate all the time.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Magnification . . .
« Reply #6 on: October 02, 2006 »
Hello again guys

Ive done a new version with Jim's and Rbraz's new lib . . . nice - just want it full screen again now!!!

Just need to optimise it a little more - can anybody help me with a bit of timing - to make it slower?

Regards

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Magnification . . .
« Reply #7 on: October 02, 2006 »
shouldnt be a problem mate  :)

ill sort you out tomorow the problem is that now it will run at rock steady 60 fps or what ever the refresh monitor rate is on your comp but it might still be a bit fast so you could either adjust your zoom by smaller amounts each frame or clamp the fps to maybe 30 fps.

the first one you could do im sure and would probably be the best the second if you wish ill sort out for you.

<edit in fact if you change mag1 to 0.5 or something wouldnt that slow it down a bit>
« Last Edit: October 02, 2006 by ninogenio »
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Magnification . . .
« Reply #8 on: October 02, 2006 »
Ninogenio
Thanks for your input . . .
Tried changing mag1 to 0.5 and it messes it up horrendously because of the way i calculate stuff, might have another go though.
Another problem is that both of my screens here are LCD, so i guess that can mess things up as well.
As always any help is very much appreciated.

Drew

DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Magnification . . .
« Reply #9 on: October 02, 2006 »
well i just tested it and it runs pretty smoth here mate but never the less ill have a play around and post what i come up with.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Magnification . . .
« Reply #10 on: October 03, 2006 »
right ive been having fun messing around with this,

i first got all the resize code contained in a function that would alow for more than one image to be resized then i went through it to understand it fully and imho this isnt the best way to do resized images as it doesnt give very much controll as to how much the image should be zoomd each frame the way i would go about it is to have two affinely textured mapped triangles ie a quad then you could rotate and zoom the images so*

if you wish i could make an example for you also instead of having if checks for the rgb colors you could simply have the rgb colors in the array ie a raw bitmap or i could show you how to dynamically load bmps.

the only reason i ask if you would like me to do an example is that i dont want to take any of the fun out of your learning.

although in saing that though your version is quicker.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Magnification . . .
« Reply #11 on: October 03, 2006 »
I think you're going to lose Drew there Nino, he needs more time to learn to code a flatshaded triangle routine before he can do texture maps.

Why not do a routine that just zooms a pixel font like he had? :)

I can help if you want but I don't want to jump in and steal Nino's thunder so by all means post if you need me and I'll just watch the topic :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Magnification . . .
« Reply #12 on: October 03, 2006 »
sorry i was getting ahead of myself there i have done some stuff with the routine that might be usefull unfortunitly the codes on another comp so i can only post it tomorow.

would you like me to show you how to convert bmps into a raw format i.e an array that can be linked directly into the exe or maybe load them dynamically or are you happy with the way it is now?

again sorry for getting ahead of myself it was when i was going through your code last night i was getting lots of ideas so thanks mate.
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Magnification . . .
« Reply #13 on: October 04, 2006 »
@Nino

I have done some conversion from bmp > raw and raw > freebasic (so to speak) and found it very useful - in fact i was messing around with it last nite to be honest!

Im glad you have got some enjoyment and ideas from this though - that's what it is all about.

I would love to see what you are doing . . . not sure if I will understand it all but as Shockwave said - you may lose me a little - but hey! I am willing to learn!

@Shockwave

The more the merrier - we all do things differently - I was messing around with your electricity affect last nite and managed to put my logo on with it! What I originally wanted (almost!)

How do I code a flatshaded triangle routine? ;)

Cheers you guys!

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Magnification . . .
« Reply #14 on: October 04, 2006 »
here where ive got so far its not that great just yet but ill speed it up later and hopefully get float amounts running through the resize sub then wee can add shockwaves delta timing and get it running really smooth.

note: youll notice it now dynamically loads bmps well what ive done is nick the bmp load file out the the nehe examples thet come with freebasic and ive modifed it because before it was ubytes only ie rgb one byte each and it was upside down so i added an integer_buffer and ord the rgb values together and flipped the image so in your main code its much easyer to blit the image to screen.

hope this helps a bit and im having some fun too.
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Magnification . . .
« Reply #15 on: October 04, 2006 »
Nino,
thanks man - this is what i wanted mine to do - just wasnt sure how to do it easily . . . fantastic!

Drew

Have some Karma +
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Magnification . . .
« Reply #16 on: October 04, 2006 »
cheers drew for the karma,

glad you like someof the changes i wasnt sure if i had changed to much, like i say ill have this running much better later as i have a few ideas.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Magnification . . .
« Reply #17 on: October 05, 2006 »
here wee go ive managed to do a bit of voodo on it and get floats running through the resizer wich then let me add shockwaves delta timing hopefully this will be running much smoother now enjoy ;)

Code: [Select]
'Another masterpiece (lol) by Drew
'If it's any use - please use
'If not, sorry for wasting your time
'I really enjoyed coding this one though
'Regards and appreciation to everybody
'on the DBF Interactive forums!!!!

'Now using the new 'ptc lib' by Jim and Rbraz - thanks guys
'edited by nino to use shockwaves delta timing

option explicit

#include once "tinyptc.bi"
#include once "crt.bi"
#include once "bmpload.bi"

const xres = 640
const yres = 480
const scr_size = xres*yres


dim shared drew_graphic as BITMAP_RGBImageRec ptr
 
dim as single size=1 , amount=0.7

ptc_open( "Magnification by Drew v2", XRES, YRES )

dim shared buffer(xres*yres) as integer

declare sub clear_screen()
declare sub resize_image( image as BITMAP_RGBImageRec ptr , byval x_pos as single , byval y_pos as single , byval resize as single)
declare sub loadimage(byval graphic_location as string , image as BITMAP_RGBImageRec ptr )
declare sub free_image( image as BITMAP_RGBImageRec ptr )
declare sub delta()
declare sub flip_screen()
dim shared as double m ,oldtime,newtime
dim shared ticks as integer

#define backbuffer(x,y,argb) buffer(y*XRES+x)=argb

loadimage( "drew.bmp" , drew_graphic )

while inkey$ = ""
     
      resize_image( drew_graphic , 640/2 , 480/2 , size)

      flip_screen()
     
      size += amount / newtime
      if size >= 10 then amount =- amount
      if size <= 1 then amount =- amount
      clear_screen()
wend

free_image( drew_graphic )



sub clear_screen() 
    memset( @buffer(0) , 0 , scr_size*sizeof(integer) )
end sub



sub flip_screen()
   
    ptc_update @buffer(0)
    ticks += 1
    delta()
   
end sub



sub delta()
   
    dim lpt as integer
    dim tst as string
    dim as double bb
    bb=timer
    if  bb-oldtime >=.2 then
        oldtime=timer
        newtime = ticks               
        newtime=newtime+1
        ticks=0
    end if
   
end sub



sub resize_image( image as BITMAP_RGBImageRec ptr , byval x_pos as single , byval y_pos as single , byval resize as single )
   
    dim as single graphic_pos , resized_y , resized_x , fraction_y , fraction_x , dn , md , graphic_array
   
    graphic_pos = 0
    graphic_array = 0
    for resized_y=0 to (image->sizeY-1)*resize step resize
                for resized_x=0 to (image->sizeX-1)*resize step resize
                   
                           
                            for fraction_y=0 to resize
                                         for fraction_x=0 to resize
                                                      dn=y_pos+(resized_y+fraction_y)-(image->sizeY/2*resize)
                                                      md=x_pos+(resized_x+fraction_x)-(image->sizeX/2*resize)
                                                      if md<xres-1 and dn<yres-1 and md>1 and dn>1 then
                                                                  if image->integer_buffer[graphic_array] then backbuffer(int(md),int(dn),image->integer_buffer[graphic_array])
                                                      endif
                                         next fraction_x
                            next fraction_y
                            graphic_array += 1
                            graphic_pos += 1
                next resized_x
                if graphic_pos=image->sizeX-1 then graphic_array += 1
                graphic_pos = 0
    next resized_y
   
end sub



sub loadimage(byval graphic_location as string , image as BITMAP_RGBImageRec ptr )
   
    image = loadbmp(graphic_location)
       
end sub


sub free_image( image as BITMAP_RGBImageRec ptr )
   
    if image then                       
             if image->byte_buffer then                 
                    deallocate(image->byte_buffer)           
             end if
             if image->integer_buffer then                 
                    deallocate(image->integer_buffer)           
             end if
             deallocate(image)                     
    end if
   
end sub
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Magnification . . .
« Reply #18 on: October 05, 2006 »
Thanks again Nino!
It is now looking very good - im going to be using it in a forthcoming demo (okay?)
Hope i can do it justice in my new demo - coming soon (i hope!)
Regards
Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: Magnification . . .
« Reply #19 on: October 05, 2006 »
yeah im sure youll do it justice.

it is stll your code mate so no credit needs to go my way and i must say its a diffrent and faster way of doing resizes than i first thought of so  :cheers:
Challenge Trophies Won: