Dark Bit Factory & Gravity
GENERAL => Challenges & Competitions => Topic started by: Shockwave on May 30, 2006
-
Here's the next one.
See who can make the best gravitational metaballs effect in any language :)
-
This is not mine it is from the Blitz forum by AngleDaniel. It's for BMax and I thought it was neat.
http://www.blitzbasic.com/Community/posts.php?topic=45716
'Blobby objects with BlitzMax using Max2D only
'Some special numbers
Local ballsize:Int=512
Local ballsizehalf:Int=ballsize/2
'Set up the display
Graphics 800,600,0
Cls
'Work out what the dividers needs to be
Local balldivider:Float
If ballsize=128 Then balldivider=64 '8x8
If ballsize=256 Then balldivider=256 '16x16
If ballsize=512 Then balldivider=1024 '32x32
Local lineardivider:Float
If ballsize=128 Then lineardivider=0.5
If ballsize=256 Then lineardivider=1
If ballsize=512 Then lineardivider=2
'Render the gradient image
For Local r:Float=1 To ballsize-1 Step 0.5
Local level:Float=r
level:*level
level=level/balldivider
SetColor level,level,level 'For blobby gradient shape
'SetColor r/lineardivider,r/lineardivider,r/lineardivider 'For linear gradients
DrawOval r/2,r/2,ballsize-r,ballsize-r
Next
'Turn it into an image
AutoMidHandle True
Local img:TImage=CreateImage(ballsize,ballsize,1,FILTEREDIMAGE)
GrabImage(img,0,0,0)
'Set the drawing mode
SetBlend LIGHTBLEND
'Keep drawing the image until you press Escape
Repeat
Cls
DrawImage img,400,300
DrawImage img,MouseX(),MouseY()
Flip
Until KeyHit(KEY_ESCAPE)
-
The tutorial should be a help for anyone who wants to have a go at this.
I'll most probably start mine tonight.
-
Here's a tute I made with regrds to this effect. :*)
http://petesqbsite.com/sections/express/issue1/index.html#blobs
-
Kewl :)
I'll read that first before I code mine ;)
-
Here is first attempt based on the tutorial from Relsoft: http://zac-interactive.dk/temp/blob_objects.zip
-
Cool :) Nice one Zawran.
-
Nice one Zawran!
O0
-
Here's my attempt based on a blitz source that I converted from an old C source that I got somewhere off the net a few years ago, cant credit the original coder as I dont know who it was but I can say that this FB version is much, much faster than the blitz version at this res ;)
-
Nice one Jon, I remember that someone on the BR forum had converted that one also years ago. Can't remember who posted it back then though, but it looked very much like it, some French code I think. Its better than my attempt because this one actually have the blobs sorta melt together where mine just adds the colorvalues of the blobs together. Great look blobs, and good speed it seems as well.
[edit] I couldn't find that post on the BR forum so its most likely your blitz conversion that I have seen way back, hehe. My memory is failing me it seems. Still its a really cool looking effect.
-
Ahh, that's the stuff Jon!
Nicely converted, FB really is so cool for doing this kind of stuff.
-
@Zawran, yes i probably sent you the blitz code to try in B+ at some point as that was faster at pixel drawing. The blitz version runs about the same speed as this at 320*240 but about 1/4 at 640*480.
@Shockwave, Yep FB and TinyPTC make this sort of pixel pushing great fun and it's sparked my interest in coding again which hasn't happened in a while ;D
-
Here's my first attempt.
I started to read Relsoft's tutorial and while it made perfect sense I wanted to do my own version so this code is different. It's probably slower than his version, I've yet to optimise it but it gives the classic metaballs pattern.
Exe attached for those without Freebasic.
'
' Lame Metablobs by Shockwave ^ DBF
' All Original code (so what?!?)
'
'------------------------------------------------------------------------------
'-------------------------------------
' Includes.
'-------------------------------------
'#define ptc_win
#Include Once "tinyptc.bi"
option dynamic
'-------------------------------------------------------------------------
' Open 800 X 600 Screen.
'-------------------------------------------------------------------------
If( ptc_open( "METABLOBS", 640, 480 ) = 0 ) Then
End -1
End If
'--------------------------------------------------------------------------
' Define Storage;
'--------------------------------------------------------------------------
defint a-z
Dim Shared As Integer Buffer( 640 * 480 )
Dim Shared As Integer Buffer2( 640 * 480 )
'---------------
'-Debug Stuff; -
'---------------
dim shared oldtime,newtime as double
dim shared TST as string
dim shared ticks as integer
ticks=0
'-----------------------------------------------------------------
' Read In Our Font;
'-----------------------------------------------------------------
dim shared FONT (81 * 59) as integer
FOR LP=1 TO (81*59)
READ FONT(LP)
NEXT
'
' Storage for our metablob graphic;
'
dim shared blob (200 , 200) as integer
dim as double angle,bangle
'
' Generate blob here!
radius=99
for z=1 to 99
bangle=360
clv=z
if clv>255 then clv=255
for a=1 to 360
x1=(100+(radius*sin(angle*3.1415926535897932/180)))
y1=(100+(radius*cos(angle*3.1415926535897932/180)))
x2=(100+(radius*sin(bangle*3.1415926535897932/180)))
angle=angle+.5
bangle=bangle-.5
for l=x2 to x1
blob(l,y1)=clv
next
next
radius=radius-1
next
'
' Colour palette
'
dim shared cols (500) as integer
rclv=0
gclv=0
bclv=0
for a=1 to 500
cols(a)=rgb(rclv,gclv,bclv)
if a<155 then
rclv=rclv+6
gclv=gclv+4
bclv=bclv+2
if rclv>255 then rclv=255
if gclv>255 then gclv=255
if bclv>255 then bclv=255
else
rclv=rclv-3
gclv=gclv-5
bclv=bclv-5
if rclv<0 then rclv=0
if gclv<0 then gclv=0
if bclv<0 then bclv=0
end if
next
'--------------------------------------------------------------------------
' Define Subs;
'--------------------------------------------------------------------------
declare sub DBFWPF(BYVAL BX AS INTEGER, BYVAL BY AS INTEGER , BYVAL CH AS INTEGER )
declare sub DBFTEXT(BYVAL BX AS INTEGER , BYVAL BY AS INTEGER , BYVAL CH AS INTEGER , BYVAL CLR AS INTEGER)
declare sub dblob(BYVAL MVOX AS INTEGER , BYVAL MVOY AS INTEGER)
declare SUB Millisecs()
declare sub copybuffer()
dim shared as integer gadd,gadd2,gadd3
oldtime=timer
DO
gadd=gadd+1
gadd2=gadd2-1
gadd3=gadd3+2
dblob(220+250*sin(gadd3/77),140+39*cos(gadd2/33))
dblob(220+150*sin(gadd2/39),140+299*cos(gadd/33))
dblob(220+250*sin(gadd/33),140+199*cos(gadd3/39))
dblob(220+125*sin(gadd/37),140+19*cos(gadd3/33))
dblob(220+250*sin(gadd3/39),140+29*cos(gadd2/33))
dblob(220+50*sin(gadd2/33),140+249*cos(gadd/29))
copybuffer()
millisecs()
Ptc_Update @Buffer(0)
ticks=ticks+1
LOOP UNTIL INKEY$<>""
sub copybuffer()
for a=1 to 640*480
buffer(a)=cols(buffer2(a))
buffer2(a)=buffer2(a) *.80
next
end sub
sub dblob(BYVAL MVOX AS INTEGER , BYVAL MVOY AS INTEGER)
for x=1 to 200
for y=1 to 200
BX=MVOX+X
BY=MVOY+Y
IF (BX>0) AND (BX<639) AND (BY>0) AND (BY<479) and (blob(x,y)>0) THEN
BUFFER2 (((MVOY+Y)*640)+(MVOX+X))=BUFFER2 (((MVOY+Y)*640)+(MVOX+X))+(blob(x,y))
if BUFFER2 (((MVOY+Y)*640)+(MVOX+X))>500 then BUFFER2 (((MVOY+Y)*640)+(MVOX+X))=500
END IF
next
next
end sub
SUB Millisecs()
t=timer
if t-oldtime >=1 then
newtime = ticks
ticks=0
oldtime=timer
end if
TST = str( (newtime) )
TST = "FPS "+TST
for LP=1 to len(tst)
CH=(ASC(MID(TST,LP,1)))-31
DBFTEXT((LP*10),1,CH,&hFFFFFF)
NEXT
end sub
'-------------------------------------------------------------------------
'Sub To Draw A Letter AnyWhere On The Screen (With Clipping);
'-------------------------------------------------------------------------
sub DBFTEXT(BYVAL BX AS INTEGER , BYVAL BY AS INTEGER , BYVAL CH AS INTEGER , BYVAL CLR AS INTEGER)
dim blx,bly as integer
'---------------------------------
'Calculate Offset In Font Data;---
'---------------------------------
bm=(ch*81)-81
FOR BLY=0 TO 8
FOR BLX=1 TO 9
'--------
'Clip;---
'--------
IF (BX+BLX>0) AND (BX+BLX<639) AND (BY+BLY>0) AND (BY+BLY<479) THEN
'----------------------------------------------------
'Draw Pixel In Buffer If Onscreen And If Binary 1 ---
'----------------------------------------------------
MM= FONT(((BLY*9)+BLX)+BM)
IF MM >0 THEN BUFFER (((BY+BLY)*640)+BX+BLX)=CLR
END IF
NEXT
NEXT
END SUB
SUB DBFWPF (BYVAL BX AS INTEGER , BYVAL BY AS INTEGER , BYVAL CH AS INTEGER)
IF (BX>0) AND (BX<639) AND (BY>0) AND (BY<479) THEN
BUFFER ((BY*640)+BX)=CH
END IF
END SUB
'==============================================================================
' Binary Font By Shockwave / DBF; (59 Chars)
'==============================================================================
'space
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
'!
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
'"
data 0,1,1,0,1,1,0,0,0
data 0,1,1,0,1,1,0,0,0
data 0,1,1,0,1,1,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
'#
data 0,0,0,0,0,0,0,0,0
data 0,1,1,0,0,0,1,1,0
data 1,1,1,1,1,1,1,1,1
data 0,1,1,0,0,0,1,1,0
data 0,1,1,0,0,0,1,1,0
data 0,1,1,0,0,0,1,1,0
data 1,1,1,1,1,1,1,1,1
data 0,1,1,0,0,0,1,1,0
data 0,0,0,0,0,0,0,0,0
'£
data 0,0,1,1,1,1,0,0,0
data 0,1,1,1,1,1,0,0,0
data 0,1,1,0,0,0,0,0,0
data 0,1,1,0,0,0,0,0,0
data 0,1,1,1,1,0,0,0,0
data 0,1,1,0,0,0,0,0,0
data 0,1,1,0,0,0,0,0,0
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,0
'%
data 0,0,0,0,0,0,0,0,0
data 0,1,1,0,0,0,0,0,0
data 0,1,1,0,0,0,1,0,0
data 0,0,0,0,0,1,0,0,0
data 0,0,0,0,1,0,0,0,0
data 0,0,0,1,0,0,0,0,0
data 0,0,1,0,0,0,1,1,0
data 0,0,0,0,0,0,1,1,0
data 0,0,0,0,0,0,0,0,0
'&
data 0,0,0,1,1,1,0,0,0
data 0,0,1,1,1,1,1,0,0
data 0,0,1,1,0,1,1,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,1,1,0,1,1,0,0
data 0,1,1,0,0,1,1,1,1
data 0,1,1,1,0,0,1,1,0
data 0,0,1,1,1,1,1,0,0
data 0,0,0,0,1,1,0,0,0
''
data 0,1,1,0,0,0,0,0,0
data 0,1,1,0,0,0,0,0,0
data 0,1,1,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
'(
data 0,0,0,0,0,1,1,1,0
data 0,0,0,0,1,1,1,1,0
data 0,0,0,0,1,1,0,0,0
data 0,0,0,0,1,1,0,0,0
data 0,0,0,0,1,1,1,0,0
data 0,0,0,0,1,1,1,0,0
data 0,0,0,0,1,1,1,0,0
data 0,0,0,0,1,1,1,1,0
data 0,0,0,0,0,1,1,1,0
')
data 0,1,1,1,0,0,0,0,0
data 0,1,1,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,1,1,1,0,0,0,0
data 0,0,1,1,1,0,0,0,0
data 0,0,1,1,1,0,0,0,0
data 0,1,1,1,1,0,0,0,0
data 0,1,1,1,0,0,0,0,0
'*
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,0,0,0,0
data 0,0,1,0,1,0,1,0,0
data 0,0,0,1,1,1,0,0,0
data 0,1,1,1,1,1,1,1,0
data 0,0,0,1,1,1,0,0,0
data 0,0,1,0,1,0,1,0,0
data 0,0,0,0,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0
'+
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,0,0,0,0
data 0,0,0,0,1,0,0,0,0
data 0,0,1,1,1,1,1,0,0
data 0,0,0,0,1,1,0,0,0
data 0,0,0,0,1,1,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
''
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,0,1,0,0,0,0
'-
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,1,1,1,1,1,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
'.
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
'/
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,1,0
data 0,0,0,0,0,0,1,1,0
data 0,0,0,0,0,1,1,0,0
data 0,0,0,0,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,1,1,1,0,0,0,0
data 0,1,1,1,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
'0
data 0,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,1,1,1
data 1,1,0,0,0,1,0,1,1
data 1,1,0,0,1,0,0,1,1
data 1,1,0,1,1,0,0,1,1
data 1,1,1,1,0,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,0
'1
data 0,0,0,1,1,0,0,0,0
data 0,0,1,1,1,0,0,0,0
data 0,0,1,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,1,1,1,1,1,1,0,0
data 0,1,1,1,1,1,1,0,0
'2
data 0,0,1,1,1,1,1,1,0
data 0,0,1,1,1,1,1,1,1
data 0,0,0,0,0,0,0,1,1
data 0,0,0,0,0,0,0,1,1
data 0,1,1,1,1,1,1,1,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
'3
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,0
data 0,0,0,0,0,0,0,1,1
data 0,0,0,0,0,0,0,1,1
data 0,0,0,0,1,1,1,1,0
data 0,0,0,0,0,0,1,1,1
data 0,0,0,0,0,0,1,1,1
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,0
'4
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,1,1,0,0,0
data 1,1,0,0,1,1,0,0,0
data 1,1,1,1,1,1,1,1,1
data 0,0,0,0,0,1,1,1,0
data 0,0,0,0,0,1,1,1,0
data 0,0,0,0,0,1,1,1,0
data 0,0,0,0,0,1,1,1,0
'5
data 0,1,1,1,1,1,1,0,0
data 0,1,1,1,1,1,1,0,0
data 0,1,1,0,0,0,0,0,0
data 0,1,1,0,0,0,0,0,0
data 0,1,1,1,1,1,1,1,0
data 0,0,0,0,0,0,1,1,1
data 0,0,0,0,0,0,1,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,0
'6
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,1,1,1,1,1,1,0
data 1,1,0,0,0,0,1,1,1
data 1,1,0,0,0,0,1,1,1
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,0
'7
data 0,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,1
data 0,0,0,0,0,0,0,1,1
data 0,0,0,0,0,0,0,1,1
data 0,0,0,0,1,1,1,1,1
data 0,0,0,0,0,0,1,1,1
data 0,0,0,0,0,1,1,1,0
data 0,0,0,0,0,1,1,1,0
data 0,0,0,0,0,1,1,1,0
'8
data 0,0,1,1,1,1,1,0,0
data 0,1,1,1,1,1,1,1,0
data 0,1,1,0,0,0,1,1,0
data 0,1,1,0,0,0,1,1,0
data 0,0,1,1,1,1,1,0,0
data 1,1,1,0,0,0,1,1,1
data 1,1,0,0,0,0,1,1,1
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,0
'9
data 0,0,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,1
data 0,1,1,0,0,0,0,1,1
data 0,1,1,0,0,0,0,1,1
data 0,0,1,1,1,1,1,1,1
data 0,0,0,0,0,0,1,1,1
data 0,0,0,0,0,0,1,1,1
data 0,0,0,0,0,0,1,1,1
data 0,0,0,0,0,0,1,1,1
':
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
';
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,0,1,0,0,0,0
'<
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,1,1,0,0
data 0,0,0,0,1,1,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,1,1,1,0,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,0,1,1,1,0,0
data 0,0,0,0,0,1,1,0,0
data 0,0,0,0,0,0,0,0,0
'=
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,1,1,1,1,1,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,1,1,1,1,1,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
'>
data 0,0,0,0,0,0,0,0,0
data 0,0,1,1,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,0,1,1,0,0,0
data 0,0,0,0,1,1,1,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,1,1,1,0,0,0,0
data 0,1,1,1,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0
'?
data 0,0,1,1,1,1,1,0,0
data 0,1,1,1,1,1,1,1,0
data 0,1,1,0,0,0,1,1,0
data 0,0,0,0,0,0,1,1,0
data 0,0,0,1,1,1,1,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,0,0,0,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
'@
data 0,0,0,0,0,0,0,0,0
data 0,0,1,1,1,1,1,0,0
data 0,1,0,0,0,0,0,0,0
data 0,1,0,0,1,1,1,0,0
data 0,1,0,1,0,0,0,1,0
data 0,1,0,1,1,1,0,1,0
data 0,1,0,0,0,0,0,1,0
data 0,0,1,1,1,1,1,0,0
data 0,0,0,0,0,0,0,0,0
'a
data 0,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,0
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
'b
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,0
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,0
'c
data 0,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,1
'd
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,0
'e
data 0,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,1,1,1,1,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,1
'f
data 0,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,1,1,1,1,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
'g
data 0,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,1,1,1,1
data 1,1,0,0,0,0,1,1,1
data 1,1,0,0,0,0,1,1,1
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,0
'h
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
'i
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
'j
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,0
data 0,0,0,0,0,0,0,1,1
data 0,0,0,0,0,0,0,1,1
data 0,0,0,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,0
'k
data 1,1,0,0,0,0,1,1,0
data 1,1,0,0,0,0,1,1,0
data 1,1,0,0,0,0,1,1,0
data 1,1,0,0,0,0,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
'l
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,1
'm
data 0,1,1,1,0,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,1,0,0,1,1
data 1,1,0,0,1,0,0,1,1
data 1,1,0,0,1,0,0,1,1
data 1,1,1,0,1,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
'n
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
'o
data 0,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,0
'p
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
'q
data 0,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,1,0,1,1
data 1,1,1,0,0,0,1,1,1
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,0
'r
data 1,1,1,1,1,1,1,1,0
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,0
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
's
data 0,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,0,0,0,0,0,0,0
data 1,1,0,0,0,0,0,0,0
data 0,1,1,1,1,1,1,1,0
data 0,0,0,0,0,0,1,1,1
data 0,0,0,0,0,0,1,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,0
't
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,0,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
data 0,0,0,1,1,1,0,0,0
'u
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,0
'v
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,1,0,0,1,1,1
data 0,1,1,1,1,1,1,1,0
data 0,0,1,1,1,1,1,0,0
'w
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,1,0,1,0,0,1,1
data 1,1,1,0,1,0,0,1,1
data 1,1,1,0,1,0,0,1,1
data 1,1,1,1,1,1,1,1,1
data 0,1,1,1,0,1,1,1,0
'x
data 0,1,1,0,0,0,1,1,0
data 0,1,1,0,0,0,1,1,0
data 0,1,1,0,0,0,1,1,0
data 0,1,1,0,0,0,1,1,0
data 0,1,1,1,1,1,1,1,0
data 1,1,1,1,0,0,1,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
data 1,1,1,0,0,0,0,1,1
'y
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 1,1,0,0,0,0,0,1,1
data 0,1,1,1,1,1,1,1,1
data 0,0,0,0,0,0,1,1,1
data 0,0,0,0,0,0,1,1,1
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,0
'z
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
data 0,0,0,0,0,0,0,1,1
data 0,0,0,0,0,0,1,1,1
data 0,1,1,1,1,1,1,1,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,0,0,0,0,0,0
data 1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1
-
Nice one Shockwave and pretty good speed here, 88fps. Not actually checked the fps of mine, might add that in ;)
-
Cheers Jon, the speed is a bit slow at the moment but I'll optimise it when I get a chance to tweak it. I have a few ideas for this effect :)
-
hey hey, i'm still around yo! :)
here's some balls for yall, in the entoxicoded colortheme :)
-
Nice stuff dudes, welldone ;D
-
Here's my attempt based on a blitz source that I converted from an old C source that I got somewhere off the net a few years ago, cant credit the original coder as I dont know who it was but I can say that this FB version is much, much faster than the blitz version at this res Wink
I don't have the code anymore but I think the BB code was Blunder's coded as a screensaver and yeah it's much, much faster.
-
Nice Marching cubes FB Fusion, need to try it on my home PC as could just about see them and the one im currently on is very low spec. Looks ace.
And welldone to all, nice light bobs.
-
Nice Marching cubes FB Fusion
that wasnt a FB_Fusion prod..
-
My appologies dude, Nice Marching Cubes Xteraco.
-
@shockwave: tight metaballs man, just amazing :D
-
I don't have the code anymore but I think the BB code was Blunder's coded as a screensaver and yeah it's much, much faster.
I didn't covert someone elses BB code I converted my own, but my BB code was a conversion of a C version I downloaded of the net. I have a load of old C/ASM based dos effects code kicking around in my backup archives on cd's. I converted a few that I could follow over to blitz but alot of them used ASM and I couldnt work out what some of it did ???
-
Hey Xteraco! Nice one :)
That's the best one yet as far as I'm concerned!
-
I've done a few optimisations on mine and improved the movements, I've attached it as an exe as the code is essentially the same. :D
-
Nice one, looks really cool in that color scheme.
I made some changes to mine, now has 2 different size blobs and twice as many, mind the fps took a big drop but it's still faster than the original code under blitz LOL
-
Yep, they are better in red Jon. Nice one.
-
mb.exe (http://www.reachone.com/wham/demo/mb.exe)
:cheers:
-
Nice logo Bill :)
-
oops wrong link ??? :whack:
-
Here's my attempt, a crap one :)
-
Cool one RBRAZ! :cheers:
-
Wham, that one was really authentic :) nice to see one done in Blitz.
Rbraz, nice and fast, cool stuff :)
-
Not my code BTW - I believe this is Bluder's code - just wanted to see some blitz code here ::) Its 100x bigger 50x slower and 500% lamer than anything else here :||
-
Blitz isnt that bad apart from the bloated exe size, you can get a decent turn of speed from it if you try real hard. Here's some more blitz metaballs, originally coded by paranoid pete but this version is compiled by me in b3d with fps counter added.
MetaballPP.rar (http://zac-interactive.dk/jon_demos/metaballsPP.rar)
-
Yep speedy alright and the MB I posted could have been sped up too - too bad the compiler sux so bad >:( I used 2d compiler and upx to get it to the dl size ;D 3d compiler was over a meg ughhhhhhhhhhhhhhh as one person said " It seems to compile everything in the known universe!" :P
-
In the version coded by Paranoid Pete, because of the movement pattern and the small size of the balls it makes the render a lot quicker.
It's hard to say how optimised it really is.
If we go by the speed output by Jons textured voroni tunnel posted in the tunnel challenge thread then the speed of Paranoid Pete's metaballs isn't all that great.
Jons tunnel rendered the whole screen with perspective correct textures at 640 X 480 and what looks like mip mapping at 108 fps on my system in that tunnel demo, Paranoid Pete's metablobs is rendering about the equivalent of a 300*200 area each frame and that is running at 126 fps here (I presume the same timer is being used), both compiled with the same version of BB3D too.
I've done a few experiments, even using lockedpixels and I still can't render full screen 640 X 480 at even half the speed of the tunnel.
As far as the Blitz exe sizes goes, it's a shame that Blitz users don't have much control over what goes into the exe. It's a damn shame but good results can be gotten from that language.
-
The code by PP is drawing every pixel of a 640*480 frame but it uses 16bit mode which I think is were some of the speed in that one comes from and it uses locked pixels via the user decls thingy but of course at 16bit there's half the data to move as compared to 32bit. My stuff is always at 32bit in blitz and I am not sure why my tunnel is so fast, it never use to be more than in the 60's. Still the exe size in the old blitz's is really the biggest drawback. at least bmax is more optimized in that sense, you only include what modules you want so exe's are much more realisticly sized.
-
Yep, I tried the tests in 16, 24 and 32 bit mode. 32 bit mode was slightly faster.
Anyway, as far as the Metaballs are concerned, all cool stuff so far! I've even developed something really strange to release as an advert intro for the messageboard using a very highly modified metaball technique.
It's so strange in fact I don't even know if I like it but it's very different to what you'd be expecting :)
Just waiting for Roly to do a tune for me.
-
Yep all nice metaball effects and some different approachs :)
Doesnt matter what language is used in my book as long as it works and you enjoyed coding it :||
-
I was supposed to post a 3d metaball using the marching cubes algo but someone beat me to it. I have another approach I haven't tried though. I think this should be very fast as the calcs are done exclusively by the GPU. :*)
That is if I finish this terrain splatting demo for our kart game. :*)
-
Love to see your spin on the Marching Cubes algo dude too matey.
-
Nope I got it to work. :*)
All the raster work done by the GPU for this demo so keep the ballz coming!
BTW, do you see random "red" artifacts on the screen? Or is it just my card acting up again?
'2d metaballs in OpenGL(with 3d translation)
'relsoft 2006
'Richard Eric M. Lope BSN RN
'http://rel.betterwebber.com
Option Explicit
'$Static
'$INCLUDE: "\gl\gl.bi"
'$INCLUDE: "\gl\glu.bi"
'$INCLUDE: "\gl\glfw.bi"
'$INCLUDE: "\gl\glext.bi"
const SCR_WIDTH = 640 'Width of the screen
const SCR_HEIGHT = 480 'height of the screen
const BITSPP = 32 '32 bits per pixel format
const PI = 3.141593
const TWOPI = (2 * PI)
const BLOB_WID = 256
const BLOB_HEI = 256
const MAX_BLOBS = 128
Type DisplayType
W As Uinteger
H As Uinteger
R_BITS As Uinteger
G_BITS As Uinteger
B_BITS As Uinteger
A_BITS As Uinteger
D_BITS As Uinteger
S_BITS As Uinteger
MODE As Uinteger
GlVer As Zstring Ptr
As Single FOVy, Aspect, zNear, zFar
End Type
type vector3d
as single x
as single y
as single z
end type
type color_type
as single r
as single g
as single b
as single a
end type
Declare Sub Init_GL_Window( Display As DisplayType )
declare SUB Init_GL_SCREEN()
declare sub vector_normalize (v as vector3d)
declare sub glEnable2D()
declare sub glDisable2D()
declare function init_blob_texture(byval wid as integer, byval hei as integer) as GLuint
declare sub draw_blob(byval x as single, byval y as single, byval z as single,_
byval r as single, byval g as single, byval b as single,_
byval a as single)
Dim Display As DisplayType
Init_GL_Window Display
Init_GL_SCREEN()
dim as GLuint blob_id
blob_id =init_blob_texture(BLOB_WID, BLOB_HEI)
glEnable(GL_TEXTURE_2D)
dim time_start as single
dim blob_col(MAX_BLOBS) as color_type
dim as single demo_time
dim i as integer
dim as single bx, by, bz
for i=0 to MAX_BLOBS
blob_col(i).r= 1 * (i and 15)
blob_col(i).g= 1 * (i and 3)
blob_col(i).b= 1 * (i and 7)
next i
glBindTexture(GL_TEXTURE_2D, blob_id)
glDisable (GL_DEPTH_TEST)
glEnable (GL_BLEND)
glBlendFunc (GL_ONE,GL_ONE)
Do
demo_time = glfwGetTime() '* 0.01208
GlClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
GlMatrixMode GL_MODELVIEW
GlLoadIdentity
gltranslatef (0.0, 0.0, -15.0)
for i = 0 to MAX_BLOBS
bx = sin(demo_time / 74 * 0.8 * i) * 5
by = cos(demo_time / 43 * 0.9 * i) * 3
bz = sin(demo_time / 53 * 0.9 * i) * 8
draw_blob(bx, by, bz, blob_col(i).r, blob_col(i).g, blob_col(i).b, 1.0)
next i
do
loop until glfwGetTime() - time_start >= (1/60)
time_start = glfwGetTime()
GlfwSwapBuffers
Loop Until glfwGetKey( GLFW_KEY_ESC )
GlDeleteTextures 1, @blob_id
GlfwTerminate()
end
sub draw_blob(byval x as single, byval y as single, byval z as single,_
byval r as single, byval g as single, byval b as single,_
byval a as single)
glPushMatrix
gltranslatef (x, y, z)
glColor4f (r, g, b, a)
glBegin GL_QUADS
glTexCoord2f (0.0, 0.0)
glVertex3f (-1.0, -1.0, 0.0)
glTexCoord2f (1.0, 0.0)
glVertex3f (1.0, -1.0, 0.0)
glTexCoord2f (1.0, 1.0)
glVertex3f (1.0, 1.0, 0.0)
glTexCoord2f (0.0, 1.0)
glVertex3f (-1.0, 1.0, 0.0)
glEnd
glPopMatrix
end sub
sub glEnable2D()
dim vPort(3) as integer
glGetIntegerv(GL_VIEWPORT, @vPort(0))
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(0, vPort(2), 0, vPort(3), -1, 1)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
end sub
sub glDisable2D()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
end sub
function init_blob_texture(byval wid as integer, byval hei as integer) as GLuint
dim as GLuint txtnumber
dim as unsigned integer ptr texture_data
dim as integer bcol, x, y
dim as single dist, strength
dim as integer wid_d2, hei_d2
texture_data = callocate((wid * hei)* 1 ,Len(unsigned Integer))
wid_d2 = wid\2
hei_d2 = hei\2
strength = wid * 2
for y = 0 to hei - 1
for x = 0 to wid - 1
dist = sqr((wid_d2-x) ^ 2 + (hei_d2-y) ^ 2)
if (wid_d2-x) = 0 and (hei_d2-y) = 0 then
bcol = 255
else
bcol = (Strength / (dist^1.4)) * 255
bcol = bcol - 255
end if
if bcol < 0 then bcol = 0
if bcol > 255 then bcol = 255
texture_data[x + y*wid] = bcol shl 16 or bcol shl 8 or bcol
next x
next y
glGenTextures(1, @txtnumber)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, txtnumber)
glTexImage2D(GL_TEXTURE_2D, 0, 4, wid, hei, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glDisable(GL_TEXTURE_2D)
deallocate (texture_data)
texture_data = 0
return txtnumber
end function
Sub Init_GL_Window( Display As DisplayType )
Display.W = SCR_WIDTH
Display.H = SCR_HEIGHT
Display.R_BITS= 8
Display.G_BITS= 8
Display.B_BITS= 8
Display.A_BITS= 8
Display.D_BITS= BITSPP
Display.S_BITS= 8
Display.MODE = GLFW_WINDOW
Display.MODE = GLFW_FULLSCREEN
If glfwInit() Then
'Successful!
Else
Print "Failed to initialize GLFW!"
Sleep 1000
End
End If
If glfwOpenWindow( _
Display.W , _
Display.H , _
Display.R_BITS, _
Display.G_BITS, _
Display.B_BITS, _
Display.A_BITS, _
Display.D_BITS, _
Display.S_BITS, _
Display.MODE ) _
Then
GlfwSwapInterval 1
Display.GlVer = glGetString(GL_VERSION)
Else
GlfwTerminate()
End
End If
End Sub
SUB Init_GL_SCREEN()
'screen information
dim w as integer, h as integer
'OpenGL params for gluerspective
dim FOVy as double 'Field of view angle in Y
dim Aspect as double 'Aspect of screen
dim znear as double 'z-near clip distance
dim zfar as double 'z-far clip distance
'using screen info w and h as params
glViewport 0, 0, SCR_WIDTH,SCR_HEIGHT
'Set current Mode to projection(ie: 3d)
glMatrixMode GL_PROJECTION
'Load identity matrix to projection matrix
glLoadIdentity
'Set gluPerspective params
FOVy = 80/2 '45 deg fovy
Aspect = SCR_WIDTH / SCR_HEIGHT 'aspect = x/y
znear = 1 'Near clip
zfar = 200 'far clip
'use glu Perspective to set our 3d frustum dimension up
gluPerspective FOVy, aspect, znear, zfar
'Modelview mode
'ie. Matrix that does things to anything we draw
'as in lines, points, tris, etc.
glMatrixMode GL_MODELVIEW
'load identity(clean) matrix to modelview
glLoadIdentity
glShadeModel GL_SMOOTH 'set shading to smooth(try GL_FLAT)
glClearColor 0.0, 0.0, 0.0, 1.0 'set Clear color to BLACK
glClearDepth 1.0 'Set Depth buffer to 1(z-Buffer)
glEnable GL_DEPTH_TEST 'Enable Depth Testing so that our z-buffer works
'compare each incoming pixel z value with the z value present in the depth buffer
'LEQUAL means than pixel is drawn if the incoming z value is less than
'or equal to the stored z value
glDepthFunc GL_LEQUAL
'have one or more material parameters track the current color
'Material is your 3d model
glEnable GL_COLOR_MATERIAL
'Enable Texturing
'glEnable GL_TEXTURE_2D
'Set blending parameters
glBlendFunc GL_SRC_ALPHA, GL_ONE
'Tell openGL that we want the best possible perspective transform
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
'Enable Backface culling
'GlEnable GL_CULL_FACE
glPolygonMode(GL_FRONT, GL_FILL)
'lighting
dim as glFloat mat_ambient(0 to 3) = { 0.5, 0.5, 1.0, 0.15 }
dim as glFloat mat_specular(0 to 3) = { 1.0, 1.0, 1.0, 0.15 }
dim as glFloat mat_shininess = 10.0
dim as glFloat light_position(0 to 3)= { -7.0, 8.0, -6.0, 1.0 }
dim as glFloat light_ambient(0 to 3)= { 0.5, 0.5, 0.5, 1.0 }
dim as glFloat mat_twister(0 to 3) = { 0.75, 0.75, 0.0, 1.0 }
dim as GLfloat fBrightLight(0 to 3) = { 1.0, 1.0, 1.0, 1.0 }
glMaterialfv(GL_FRONT, GL_AMBIENT, @mat_ambient(0))
glMaterialfv(GL_FRONT, GL_SPECULAR, @mat_specular(0))
glMaterialfv(GL_FRONT, GL_SHININESS, @mat_shininess)
glMaterialfv(GL_FRONT, GL_DIFFUSE,@mat_twister(0))
glMaterialfv(GL_FRONT, GL_SPECULAR, @fBrightLight(0))
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR)
glLightfv(GL_LIGHT0,GL_AMBIENT, @light_ambient(0))
glLightfv(GL_LIGHT0,GL_DIFFUSE, @light_ambient(0))
glLightfv(GL_LIGHT0, GL_POSITION, @light_position(0))
'glEnable(GL_LIGHTING)
'glEnable(GL_LIGHT0)
END SUB
sub vector_normalize (v as vector3d)
'makes v a unit vector
dim mag as single
mag = 1/sqr(v.x * v.x + v.y * v.y + v.z * v.z)
if mag <> 0 then
v.x = v.x * mag
v.y = v.y * mag
v.z = v.z * mag
else
v.x = 0
v.y = 0
v.z = 1
end if
end sub :||
-
That's so smooth! It sort of reminded me of unlimited bobs effect on the Amiga at first, that was until the screen started filling up.
That looks really smart Rel (as usual!) O0
-
Can we get a linky to and exe?
-
Here you are Zparticle, this is Relsofts Opengl linecube in exe format.
[edit, oops. metaballs now added too! Download the second attachment for both files]
-
Thanks@Shock.
Ditched the stupid z displacement for a much better lissa movement. Now with more colors
RGBlobs
'2d metaballs in OpenGL(with 3d translation)
'relsoft 2006
'Richard Eric M. Lope BSN RN
'http://rel.betterwebber.com
Option Explicit
'$Static
'$INCLUDE: "\gl\gl.bi"
'$INCLUDE: "\gl\glu.bi"
'$INCLUDE: "\gl\glfw.bi"
'$INCLUDE: "\gl\glext.bi"
const SCR_WIDTH = 640 'Width of the screen
const SCR_HEIGHT = 480 'height of the screen
const BITSPP = 32 '32 bits per pixel format
const PI = 3.141593
const TWOPI = (2 * PI)
const BLOB_WID = 256
const BLOB_HEI = 256
const MAX_BLOBS = 128
Type DisplayType
W As Uinteger
H As Uinteger
R_BITS As Uinteger
G_BITS As Uinteger
B_BITS As Uinteger
A_BITS As Uinteger
D_BITS As Uinteger
S_BITS As Uinteger
MODE As Uinteger
GlVer As Zstring Ptr
As Single FOVy, Aspect, zNear, zFar
End Type
type vector3d
as single x
as single y
as single z
end type
type color_type
as single r
as single g
as single b
as single a
end type
Declare Sub Init_GL_Window( Display As DisplayType )
declare SUB Init_GL_SCREEN()
declare sub vector_normalize (v as vector3d)
declare sub glEnable2D()
declare sub glDisable2D()
declare function init_blob_texture(byval wid as integer, byval hei as integer) as GLuint
declare sub draw_blob(byval x as single, byval y as single, byval z as single,_
byval r as single, byval g as single, byval b as single,_
byval a as single)
Dim Display As DisplayType
Init_GL_Window Display
Init_GL_SCREEN()
dim as GLuint blob_id
blob_id =init_blob_texture(BLOB_WID, BLOB_HEI)
glEnable(GL_TEXTURE_2D)
dim time_start as single
dim blob_col(MAX_BLOBS) as color_type
dim as single demo_time
dim i as integer
dim as single bx, by, bz
for i=0 to MAX_BLOBS
blob_col(i).r= rnd '1 * (i and 5)
blob_col(i).g= rnd '1 * (i and 2)
blob_col(i).b= rnd '1 * (i and 6)
next i
glBindTexture(GL_TEXTURE_2D, blob_id)
glDisable (GL_DEPTH_TEST)
glEnable (GL_BLEND)
glBlendFunc (GL_ONE,GL_ONE)
Do
demo_time = glfwGetTime() '* 0.01208
GlClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
GlMatrixMode GL_MODELVIEW
GlLoadIdentity
gltranslatef (0.0, 0.0, -15.0)
for i = 0 to MAX_BLOBS
bx = sin(demo_time / 74 * 0.8 * i) * 6
by = cos(demo_time / 43 * 0.9 * i) * 4
draw_blob(bx, by, 0, blob_col(i).r, blob_col(i).g, blob_col(i).b, 1.0)
next i
do
loop until glfwGetTime() - time_start >= (1/60)
time_start = glfwGetTime()
GlfwSwapBuffers
Loop Until glfwGetKey( GLFW_KEY_ESC )
GlDeleteTextures 1, @blob_id
GlfwTerminate()
end
sub draw_blob(byval x as single, byval y as single, byval z as single,_
byval r as single, byval g as single, byval b as single,_
byval a as single)
glPushMatrix
gltranslatef (x, y, z)
glColor4f (r, g, b, a)
glBegin GL_QUADS
glTexCoord2f (0.0, 0.0)
glVertex3f (-1.0, -1.0, 0.0)
glTexCoord2f (1.0, 0.0)
glVertex3f (1.0, -1.0, 0.0)
glTexCoord2f (1.0, 1.0)
glVertex3f (1.0, 1.0, 0.0)
glTexCoord2f (0.0, 1.0)
glVertex3f (-1.0, 1.0, 0.0)
glEnd
glPopMatrix
end sub
sub glEnable2D()
dim vPort(3) as integer
glGetIntegerv(GL_VIEWPORT, @vPort(0))
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(0, vPort(2), 0, vPort(3), -1, 1)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
end sub
sub glDisable2D()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
end sub
function init_blob_texture(byval wid as integer, byval hei as integer) as GLuint
dim as GLuint txtnumber
dim as unsigned integer ptr texture_data
dim as integer bcol, x, y
dim as single dist, strength
dim as integer wid_d2, hei_d2
texture_data = callocate((wid * hei)* 1 ,Len(unsigned Integer))
wid_d2 = wid\2
hei_d2 = hei\2
strength = wid \ 2
for y = 0 to hei - 1
for x = 0 to wid - 1
dist = sqr((wid_d2-x) ^ 2 + (hei_d2-y) ^ 2)
if (wid_d2-x) = 0 and (hei_d2-y) = 0 then
bcol = 255
else
bcol = (Strength / (dist)) * 255
bcol = bcol - 255
end if
if bcol < 0 then bcol = 0
if bcol > 255 then bcol = 255
texture_data[x + y*wid] = bcol shl 16 or bcol shl 8 or bcol
next x
next y
glGenTextures(1, @txtnumber)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, txtnumber)
glTexImage2D(GL_TEXTURE_2D, 0, 4, wid, hei, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture_data)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glDisable(GL_TEXTURE_2D)
deallocate (texture_data)
texture_data = 0
return txtnumber
end function
Sub Init_GL_Window( Display As DisplayType )
Display.W = SCR_WIDTH
Display.H = SCR_HEIGHT
Display.R_BITS= 8
Display.G_BITS= 8
Display.B_BITS= 8
Display.A_BITS= 8
Display.D_BITS= BITSPP
Display.S_BITS= 8
Display.MODE = GLFW_WINDOW
Display.MODE = GLFW_FULLSCREEN
If glfwInit() Then
'Successful!
Else
Print "Failed to initialize GLFW!"
Sleep 1000
End
End If
If glfwOpenWindow( _
Display.W , _
Display.H , _
Display.R_BITS, _
Display.G_BITS, _
Display.B_BITS, _
Display.A_BITS, _
Display.D_BITS, _
Display.S_BITS, _
Display.MODE ) _
Then
GlfwSwapInterval 1
Display.GlVer = glGetString(GL_VERSION)
Else
GlfwTerminate()
End
End If
End Sub
SUB Init_GL_SCREEN()
'screen information
dim w as integer, h as integer
'OpenGL params for gluerspective
dim FOVy as double 'Field of view angle in Y
dim Aspect as double 'Aspect of screen
dim znear as double 'z-near clip distance
dim zfar as double 'z-far clip distance
'using screen info w and h as params
glViewport 0, 0, SCR_WIDTH,SCR_HEIGHT
'Set current Mode to projection(ie: 3d)
glMatrixMode GL_PROJECTION
'Load identity matrix to projection matrix
glLoadIdentity
'Set gluPerspective params
FOVy = 80/2 '45 deg fovy
Aspect = SCR_WIDTH / SCR_HEIGHT 'aspect = x/y
znear = 1 'Near clip
zfar = 200 'far clip
'use glu Perspective to set our 3d frustum dimension up
gluPerspective FOVy, aspect, znear, zfar
'Modelview mode
'ie. Matrix that does things to anything we draw
'as in lines, points, tris, etc.
glMatrixMode GL_MODELVIEW
'load identity(clean) matrix to modelview
glLoadIdentity
glShadeModel GL_SMOOTH 'set shading to smooth(try GL_FLAT)
glClearColor 0.0, 0.0, 0.0, 1.0 'set Clear color to BLACK
glClearDepth 1.0 'Set Depth buffer to 1(z-Buffer)
glEnable GL_DEPTH_TEST 'Enable Depth Testing so that our z-buffer works
'compare each incoming pixel z value with the z value present in the depth buffer
'LEQUAL means than pixel is drawn if the incoming z value is less than
'or equal to the stored z value
glDepthFunc GL_LEQUAL
'have one or more material parameters track the current color
'Material is your 3d model
glEnable GL_COLOR_MATERIAL
'Enable Texturing
'glEnable GL_TEXTURE_2D
'Set blending parameters
glBlendFunc GL_SRC_ALPHA, GL_ONE
'Tell openGL that we want the best possible perspective transform
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
'Enable Backface culling
'GlEnable GL_CULL_FACE
glPolygonMode(GL_FRONT, GL_FILL)
'lighting
dim as glFloat mat_ambient(0 to 3) = { 0.5, 0.5, 1.0, 0.15 }
dim as glFloat mat_specular(0 to 3) = { 1.0, 1.0, 1.0, 0.15 }
dim as glFloat mat_shininess = 10.0
dim as glFloat light_position(0 to 3)= { -7.0, 8.0, -6.0, 1.0 }
dim as glFloat light_ambient(0 to 3)= { 0.5, 0.5, 0.5, 1.0 }
dim as glFloat mat_twister(0 to 3) = { 0.75, 0.75, 0.0, 1.0 }
dim as GLfloat fBrightLight(0 to 3) = { 1.0, 1.0, 1.0, 1.0 }
glMaterialfv(GL_FRONT, GL_AMBIENT, @mat_ambient(0))
glMaterialfv(GL_FRONT, GL_SPECULAR, @mat_specular(0))
glMaterialfv(GL_FRONT, GL_SHININESS, @mat_shininess)
glMaterialfv(GL_FRONT, GL_DIFFUSE,@mat_twister(0))
glMaterialfv(GL_FRONT, GL_SPECULAR, @fBrightLight(0))
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR)
glLightfv(GL_LIGHT0,GL_AMBIENT, @light_ambient(0))
glLightfv(GL_LIGHT0,GL_DIFFUSE, @light_ambient(0))
glLightfv(GL_LIGHT0, GL_POSITION, @light_position(0))
'glEnable(GL_LIGHTING)
'glEnable(GL_LIGHT0)
END SUB
sub vector_normalize (v as vector3d)
'makes v a unit vector
dim mag as single
mag = 1/sqr(v.x * v.x + v.y * v.y + v.z * v.z)
if mag <> 0 then
v.x = v.x * mag
v.y = v.y * mag
v.z = v.z * mag
else
v.x = 0
v.y = 0
v.z = 1
end if
end sub
-
Heh,. I was coding these stuff years ago in my quickbasic demo deedlines sax. I didn't have any better inspiration than these moving and zooming 2d star blobs ;P
C code, not particualry optimized, reused stuff, source included with some functions not used in this demo forgotten there (This code was from another project ;).
p.s. I haven't checked the other entries but I'll do soon..
-
Rel, those metaballs are beautiful! It's the movement pattern that you've used that makes it so pretty I think.
Optimus, actually I was watching Deedsax and I liked the metaballs with the plasma inside so much that I had another idea for them which is similar, Hopefully it'll be hitting your screen soon :) Probably I'll release it over at Pouet too. Great starfield blobs by the way.
I wonder how they'd look in a 3D mental hangover style starfield.
-
@shockwave: Thanks for the exes. :)
-
Yey,. my initial idea was to do a 3d starfield with the blobs instead of 2d stars, but it was morning and I had to study later so I left the idea for another time ;)
I am curious to see your blob idea. Another idea I had with the effect inside blobs, was blobs inside blobs inside blobs, zooming into blobs were new blobs appearing and all repeating patterns endlessly like in fractals. I think someone did a similar effect looking like this in a C64 demo (a Smash Design demo I can't remember), but I think it wasn't exactly that but some color cycling or something else maybe on the blobs to make that illusion..
-
I've attached a shot of the effect I'm working on. It's all done now, save for the music.
I wanted to see what the blobs would look like if they were alpha blended over a texture with a transparrent window in the centre, the window in the middle bit came from watching your stuff Optimus.. I just loved the idea of containing an effect inside metaballs.
Anyway, the intro will be out soon :)
Infinately zooming blobs sound much cooler than what I've done!
-
Pretty nice looking shot there Shockwave and I like the look of that fps :)
I have seen a similiar kinf of idea done in 3d were another scene formed the texture over the metaballs, cant remember the demo name as I am crap at that sort of thing ;D
-
Nice Screenie Shock!!! You Optimus, I have also a zooming plasma somewhere here n my HD. It zooms by actually zooming the lightmap depending on the scale factor. Not as good looking as your's though when I scale it really big. :*(
Anhyways here are two old metaballs I made in QB. Exe in the attatchent and source here. :*) The sonic blob should run on a 233 mhz machine at full speed.
http://rel.betterwebber.com/junk.php?id=17
-
Wow! Quite impressive screenshot. Yey, a 3d scene inside blobs is a must! I can't wait to see that demo of yours!
Rel: Zooming plasmas sounds interesting. I once tried to do one with no success (but it was several years ago), now I know I can try another one also some other ideas I have, I just have more experience to make it work. There was the last effect in "Into The Fight demo" with transparent plasmas (I called them line plasmas), now I am thinking if you were zooming into similar patterns of these plasma with changing colors and new ones arrised, entlessly. Like the zooming squares effect on C64 with several layers, a trip through new squares, that would rock with transparent plasmas, gotta try this!
-
zooming blobs. Not zoomung plasma. Dunno why I wrote plama there. But a zooming plasma wouldn't be hard to make since I laready made a mode7 plasma. :*)
-
The blobs intro will be out tonight if all goes well, I've had the music from Roly :)
Rel, I loved the QB metaballs, the plasma in the background has a really cool swirly pattern, both run as fast as fuck O0
-
I fuck slooooow. :|| LOL
-
Intro finished and spread all over the place :)
-
I would repeat myself here cause I wrote my comments already on Pouet, but I'd say quite impressive mate! Great to see it's in freebasic and it's quite smooth for such a software rendered screen!!!
-
Thanks Optimus :)