Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: DrewPee on December 06, 2007
-
Hello
Been working on this for a couple of hours . . .
#include once "tinyptc_ext.bi"
#include once "crt.bi"
Const xres=600
Const yres=480
Declare Sub lin(Byval X1 as Integer, Byval Y1 as Integer, Byval X2 as Integer, Byval Y2 as Integer, Byval LR as Integer, Byval LG as Integer, Byval LB as Integer)
Dim Shared as UInteger Buffer(XRES*YRES)
Dim shared as String key
Dim Shared as Integer a,b,c,d,b1,e,f,lop,rr,gg,bb,rn
#define PP(x,y,argb) buffer(y*XRES+x)=argb
c=299:d=479:a=199:b=199:b1=1
rr=255:gg=0:bb=0
ptc_setdialog(1,"Do You Want Full Screen? ",0,0)
if ( ptc_open ( "Laser Test by Drew", xres, yres) = 0 ) then
end -1
end if
while key<>chr$(27)
key = inkey$()
lin(c,d,b,a,255,255,255)
for lop=0 to 63
rn=int(rnd(1)*10)
e=(int(rnd(1)*-14))+(int(rnd(1)*14))
f=1+(int(rnd(1)*-14))+(int(rnd(1)*14))
if rn<5 then rr=255:gg=0:bb=0
if rn>5 then rr=255:gg=255:bb=0
pp(b+e,(a+(f)),rgb(rr,gg,bb))
next lop
ptc_update@Buffer(0)
erase buffer
b=b+b1
if b>=499 then a=a+4
if b>=499 then b1=-1
if b<99 then a=a+4
if b<99 then b1=1
if a>299 then a=199
Wend
'LINE Drawing Routine by Shockwave (Thanks Dude!)
SUB LIN(BYVAL X1 AS INTEGER , BYVAL Y1 AS INTEGER , BYVAL X2 AS INTEGER , BYVAL Y2 AS INTEGER , BYVAL LR AS INTEGER, BYVAL LG AS INTEGER, BYVAL LB AS INTEGER)
DIM xdistance AS DOUBLE
DIM ydistance AS DOUBLE
DIM TC AS INTEGER
DIM i AS INTEGER
DIM h2 AS INTEGER
DIM StartX AS DOUBLE
DIM StartY AS DOUBLE
DIM XRatio AS DOUBLE
DIM YRatio AS DOUBLE
TC = RGB ( LR,LG,LB )
xdistance = X2 - X1
ydistance = Y2 - Y1
h2 = sqr( xdistance * xdistance + ydistance * ydistance )
StartX = X1
StartY = Y1
XRatio = xdistance * ( 1.0 / h2 )
YRatio = ydistance * ( 1.0 / h2 )
for i = 0 to h2
IF STARTX>0 AND STARTX<XRES AND STARTY>0 AND STARTY<YRES THEN
BUFFER ( INT(StartX) + (INT(StartY) * XRES ) ) = TC
END IF
StartX = StartX + XRatio
StartY = StartY + YRatio
next i
END SUB
when i go to fullscreen it just quits out . . . anybody any ideas?
windowed mode works fine!
Thanks - Drew
-
600x480 isn't a standard fullscreen resolution. Try 640x480.
Jim
-
doh! of course, never noticed that . . . sad! thanks Jim!!!
-
Cool lazer :)
Lets see it drawing some stuff!
-
Shockwave,
Yeah that is the idea, does anybody remember the electronic arts logo on the amiga, a laser went around the edge of a box then the peice fell out to reveal their logo! wow! loved that idea as well! I think it was on Turrican?!?!?!? Im not sure tho?
Im hoping to etch a logo or text as the laser hits the screen or something like that - not sure if i can do it yet tho? I will try and show you guys the results!!
Cheers
Drew
-
Yeah, I remember that on Turrican.
I came up with a laser effect with lines in opengl by making them slightly transparent, if you're going to be drawing it in front of anything on the screen that might be an idea.
-
This actually sounds like a nice idea for competition : laser intro
-
Yep. It would be a good one.
-
Guys, do you mean to say Ive come up with a good idea . . . sod me!!! that don't happen very often!!!!! lol!
I have no idea how to make mine transparent and I also have no idea about OpenGL . . . thats me fekked then!
Cheers guys
Drew
-
Don't worry too much about the opengl side of things in this case but to make it transparent use some sort of blending, additive might be best for this where you simply add the colour value of the laser light to the pixel colour value and clamp it to the max value (must be done for each colour component r,g,b) but you might have to alter the line drawing function so there's no overdraw of pixels, that would be done by making either Xratio or Yratio (whichever has the largest magnitude) equal to + or - 1 and calculating the other to suit that size of step.
-
Stonemonkey . . . can that be done using tinyptc then? I understand what you mean as I use photoshop and use the blending modes on that. Not sure if I would be able to implement what you are talking about as I am using Shockwaves line drawing routine anyway (which I now understand!).
Drew
-
Yep, can be done with tinyptc, you have to read the colour value first from the pixel you're about to write to then separate the rgb values, add or blend the colour values you want to write with those (clamping if using additive blending) then combining the rgb values back together and writing to the pixel.
I've posted some alpha blending code somewhere before but you might have to alter the line drawing code or you might be able to get away with using a low blending value with the overdraw giving a cumulative effect.
EDIT:
this uses the alpha part (bits 24-31) of the source colour for blending
http://dbfinteractive.com/index.php?topic=307.msg3840#msg3840
-
Thanks stonemonkey - I will have a go at this now . . . cheers dude!
Drew