Author Topic: BlitzMax Sinewave  (Read 7743 times)

0 Members and 1 Guest are viewing this topic.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
BlitzMax Sinewave
« on: June 03, 2011 »
Hi Guys,
I was wondering if some one could help me out with this problem I have converting bb code to bm.
There is no doublebuffer command in bm so I must confess I don't know how to work around this
Any help would be most appreciated as I have just spent the last 2 nights working on this


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: BlitzMax Sinewave
« Reply #1 on: June 03, 2011 »
Hi,

What you need to do is define a screen with a backbuffer something like this;

Code: [Select]
SetGraphicsDriver GLMax2DDriver()
Const xres = 1024
Const yres = 768
Graphics xres,yres,32,60,GRAPHICS_BACKBUFFER

Then all drawing by default is on the back buffer, you just need to use this command in your main loop to swap the buffers;

Code: [Select]
Flip(-1)

Hopt that helps!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: BlitzMax Sinewave
« Reply #2 on: June 03, 2011 »
Thanks for the speedy reply I have done as you said but I am still stuck, Basicly I have read my png font data in to an Array using Readpixel this works ok but I just can not get my head around the Writepixel command I would like to write the data back to the backbuffer then flip it in to view. WritePixel(BACKBUFFER, draw_x, draw_y, font(font_x, y))
What would go where I have Backbuffer? Thanks for your help.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: BlitzMax Sinewave
« Reply #3 on: June 03, 2011 »
Sorry, I see.. I hadn't understood the question.

Well, I can't run the program as it can't find your font file so I'll take a look at this tomorrow :)  Maybe I'll build something that draws a scroller pixelwise like you are trying to do.

Bearing in mind that I've used Blitz Max for about 20 minutes in total so don't hold your breath.

In the meantime, maybe someone else whow uses Bmax regularly will help - there are a few people here who use it a lot.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: BlitzMax Sinewave
« Reply #4 on: June 03, 2011 »
I haven't used BlitzMax for along time. I came up with with a kind of wpf method using pixel maps. http://www.dbfinteractive.com/forum/index.php?topic=4101.msg54918#msg54918
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: BlitzMax Sinewave
« Reply #5 on: June 04, 2011 »
Thanks Shockwave for your offer and your time I will wait and see if you come up with something.
The plasma effect is brill thanks for that, I think my problem is I never paid attention in maths at school and now
I am paying for it I do know that Out of bound errors are caused by bad maths :clap:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: BlitzMax Sinewave
« Reply #6 on: June 04, 2011 »
If you could attach the font image to a post, then I'll take a look at it and see if I can figure out why its not working for you.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: BlitzMax Sinewave
« Reply #7 on: June 04, 2011 »
OK here it is, hope you have more luck than I have had :suicide: I can only think it's the pixmap setup that is wrong.
Thanks for you help.

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: BlitzMax Sinewave
« Reply #8 on: June 04, 2011 »
Writepixel is not fast and you can make a sine text effect much easier and faster by using the command that draws part of an image onto the backbuffer. I have made an example of this which you can try here:

Code: [Select]
SuperStrict

Const GRAPHICS_W:Int = 800
Const GRAPHICS_H:Int = 600
Const FONT_W:Int = 32
Const FONT_H:Int = 32

Graphics GRAPHICS_W, GRAPHICS_H

Global font:TImage = LoadAnimImage("Fonts.png",32,32,0,60) ' load image as an animimage with 60 frames each 32x32 pixels
Global cnt:Float = 0.0
Global cntUpd:Int = MilliSecs()

While Not KeyHit(KEY_ESCAPE)
Cls
sineText(0,300,"SINE TEXT TEST",100,cnt,0.5)

If MilliSecs() > cntUpd+25 Then
cnt :+ 2.0
If cnt > 359.99 Then cnt :- 360.0
End If

Flip
Wend

Function sineText(x:Int,y:Int,text:String,amp:Int,sine:Float,add:Float=0.1)
For Local i:Int = 0 To Len(text)
Local char:Int = Asc(Mid(text,i,1))
' check to see if it is a valid character and if so, then draw it
If char > 31 And char < 92 Then
' go through each vertical line of the character
For Local ii:Int = 0 Until FONT_W
DrawSubImageRect(font,x,y+Sin(sine)*amp,1,FONT_H,ii,0,1,FONT_H,0,0,char-32)
sine :+ add
x :+ 1
Next
End If
Next
End Function

If you want to find out how to do fast pixel manipulation you can try and take a look at how I did it for a software framework I posted a while back on this forum. It shows how to do the manipulation directly on the data instead of using write-/read-pixel commands.

[edit] Here is a link to the old thread about my software framework. http://www.dbfinteractive.com/forum/index.php?topic=4193.0
« Last Edit: June 04, 2011 by zawran »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17412
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: BlitzMax Sinewave
« Reply #9 on: June 04, 2011 »
K+ for you Zawran :-)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: BlitzMax Sinewave
« Reply #10 on: June 04, 2011 »
Thank you, so much if I told you that I had been trying to produce that effect on and off for a number years now
I bet you would laugh, I can't thank you enough looking at the code "what there is of it" looks so simple
I guess the more you try the worst it gets, finding this site and your help has made my day :updance:
Thanks again.

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: BlitzMax Sinewave
« Reply #11 on: June 04, 2011 »
You are very welcome. It can be done with pixel manipulation, it just does not make sense to do unless you need the pixel stuff for something else at the same time. So this is why its better to use the image drawing options already available. I have made a ton of different old school effects using both blitzplus and blitzmax, and I does not mind answering questions, so if there are anything you are struggling with and want help with then please feel free to ask on this forum and together we will try and find a solution.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: BlitzMax Sinewave
« Reply #12 on: June 07, 2011 »
Zawran made a pretty awesome library for Blitzmax some time ago.
You might look that up it, had some great raster effects it could do.
Challenge Trophies Won:

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: BlitzMax Sinewave
« Reply #13 on: June 07, 2011 »
Thanks I will try and find it.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: BlitzMax Sinewave
« Reply #14 on: June 07, 2011 »
Sorry Pixel_Outlaw I have looked for the library but with no luck, If any one can point me in the right direction to the download I would be greatfull.

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: BlitzMax Sinewave
« Reply #15 on: June 07, 2011 »
There is a link to the framework in my post further up where I also posted that example.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Re: BlitzMax Sinewave
« Reply #16 on: June 07, 2011 »
Thanks found it and ran the example code, this will help me no end  :goodpost: