Squares

General FreeBASIC programming questions.
albert
Posts: 5635
Joined: Sep 28, 2006 2:41
Location: California, USA

Postby albert » Oct 06, 2011 0:58

@podvornyak

I played around a little with your GL thingy.

I almost got a set of wings out of it..

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const pi as double = atn(1)*8 '3.1415926535897932

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp
do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

        'temp += 0.01
        temp+ =rnd /50
        glbegin gl_points
                for a as double = 0 to pi step .05
                        for b as double = 0  to pi step 0.05
                                glcolor3ub 10+(a+b)/5, 5+(a+b)/5, (a+b)/15
                                'glvertex3f sin(a)*cos(b)*10*sin(temp),  sin(a)*sin(b)*10*cos(a) ,  cos(a)*10 *sin(b)
                                glvertex3f sqr(cos(a)*cos(a))*5 , sqr(sin(b)*cos(a*a*b))*5 , cos(a)*sin(b)*10
                        next b
                next a
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end
 

podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Postby podvornyak » Oct 06, 2011 3:11

Yeap. I glad you get my point. You still can use software calculations for 3d represantation, but i think GL is optimal for that. Studing GL comes intuitive. Couple of days and you can get amazing effects. Anyway here software calculation functionality.

sx = xsize/2+x*dist/(z+dist),
sy = ysize/2-y*dist/(z+dist).

where: sx sx - position of screen pixel, xsize ysize - size of screen, x y z - position in 3D, dist - distance between camera aye and point of view. Camera position 0, 0, -dist. from demo.design 3D programming FAQ
Waiting to see more experimentations from ya...
albert
Posts: 5635
Joined: Sep 28, 2006 2:41
Location: California, USA

Postby albert » Oct 06, 2011 3:59

Heres number "2" animation with the GL..

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const  pi as double = atn(1)*8 '3.1415926535897932
const rad as double = atn(1)/22.5'11.25

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp=.5 , toggle = 0
do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

       
        if toggle = 0 then temp += 0.005
        if toggle = 1 then temp -= 0.005
       
        if temp >= 3.000 then toggle = 1
        if temp <= 0.005 then toggle = 0
       
        glbegin gl_points
                for a as double = 0 to pi step rad
                        for b as double = 0  to pi step rad
                                'glcolor3ub 10+(a+b)/5, 5+(a+b)/5, (a+b)/15
                                glcolor3ub  (a+b)/5, (a+b)/b, (a+b*5)/b
                                glvertex3f  cos(temp*cos(a))*cos(b)*5 ,  atn(sin(b)*sin(temp*a))*5 ,  sqr(cos(a)*sin(b))*10
                                glvertex3f -cos(temp*cos(a))*cos(b)*5 , -atn(sin(b)*sin(temp*a))*5 , -sqr(cos(a)*sin(b))*10
                        next b
                next a
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end
 
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Postby podvornyak » Oct 06, 2011 4:32

Yes!

Try to replace "glbegin gl_points" with "glbegin gl_lines" or "glbegin gl_line_strip". Else you can add something like "glLineWidth rnd*10" or "glPointSize rnd*10"somewhere outside "glBegin ... glEnd" ;)

Code: Select all

...
for a as double = 0 to pi step rad
   for b as double = 0  to pi step rad
      gllinewidth rnd*10 ' outside
      glbegin gl_lines '!!!!!!!!!!
         glcolor3ub  (a+b)/5, (a+b)/b, (a+b*5)/b
         glvertex3f  cos(temp*cos(a))*cos(b)*5 ,  atn(sin(b)*sin(temp*a))*5 ,  sqr(cos(a)*sin(b))*10
         glvertex3f -cos(temp*cos(a))*cos(b)*5 , -atn(sin(b)*sin(temp*a))*5 , -sqr(cos(a)*sin(b))*10
      glend '!!!!!!
   next b
next a
....

That is modern way to make demoscene. Lot of amazing demos done last year on principles of "fr. Pointillisme"
http://www.youtube.com/watch?v=3mizQWhj4lo
http://www.youtube.com/watch?v=ma8KXOGS8UU
http://www.youtube.com/watch?v=A8x0KrWoQ3I
http://www.youtube.com/watch?v=g3TRZamP85c
dodicat
Posts: 6390
Joined: Jan 10, 2006 20:30
Location: Scotland

Postby dodicat » Oct 06, 2011 10:44

Hi Albert
podvornyak code is crisp and clear, and he is a good tutor in gl.
And you doodle works a treat.

@ podvornyak
I am on Linux at the moment, and have just been running the sudoku (my last shortened post), and it works fine here with the mouse quit or pressing esc.
If you put an end command in the last line of the last sub, just after
Loop Until Inkey=Chr(27)
then it might help.
Linux always seems to be a bit contrary, for instance I just can't get geany to work here, so I use fbedit under Wine.
Also, maybe you should shell your own editor, I had to change gedit to kwrite for this distro.

Good luck.
@cherry
I'll have a look into the salesman thing, it seems a transport algorithm of some sort is required.
This means that I'll have to dig out some old books.
Matrices, if I rember correctly, can be used effectively in this bit of operational research.
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Postby podvornyak » Oct 06, 2011 11:05

dodicat wrote:... I just can't get geany to work here
Try to add geany repository. It should help.

Code: Select all

sudo add-apt-repository ppa:geany-dev/ppa
sudo apt-get update
albert
Posts: 5635
Joined: Sep 28, 2006 2:41
Location: California, USA

Postby albert » Oct 06, 2011 20:34

Heres another "morphing object"

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const  pi as double = atn(1)*8
const rad as double = atn(1)/22.5

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp=1 , toggle = 0
dim as double deg1 , deg2
dim as double c1,c2
dim as double s1,s2

do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

       
        if toggle = 0 then temp += 0.01
        if toggle = 1 then temp -= 0.01
       
        if temp >= 2.500 then toggle = 1
        if temp <= 1.000 then toggle = 0
       
        glbegin gl_points
                for deg1 = 0 to 360 step 1
                    c1=cos(deg1*rad)
                    s1=sin(deg1*rad)
                   
                    for deg2 = 0  to 360 step 1
                        c2=cos(deg2*rad)
                        s2=sin(deg2*rad)
                       
                        glcolor3ub cos(c2*s2*temp)/.85, cos(c2*s2*temp)/.45 , cos(c2*s2*temp)/.25
                       
                        glvertex3f tan(s1)+(c2+c1/3)*temp*4 , tan(c1)+(s2+s1/3)*temp*4 ,  tan(c1+s1)/1.5+(c2*s2*s1)
                    next
                next
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end



A COOL "Trig 3D" grid

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const  pi as double = atn(1)*8
const rad as double = atn(1)/22.5

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp=1.5 , toggle = 0
dim as double deg1 , deg2
dim as double c1,c2
dim as double s1,s2

do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

       
        if toggle = 0 then temp += 0.01
        if toggle = 1 then temp -= 0.01
       
        if temp >= 2.500 then toggle = 1
        if temp <= 1.500 then toggle = 0
       
        glbegin gl_points
                for deg1 = 0 to 360 step 1
                    c1=cos(deg1*rad)
                    s1=sin(deg1*rad)
                   
                    for deg2 = 0  to 360 step 1
                        c2=cos(deg2*rad)
                        s2=sin(deg2*rad)
                       
                        glcolor3ub cos(c2*s2*temp)/1.5, cos(c2*s2*temp)/1.25 , cos(c2*s2*temp)/.25
                       
                        glvertex3f (atan2(c1,c2)/5)*temp*5 , (atan2(s1,s2)/5)*temp*5 ,  cos(c2+s2)*2*temp
                    next
                next
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end
 

With this GL what the color ranges ??

glcolor3ub ?? , ?? , ??
albert
Posts: 5635
Joined: Sep 28, 2006 2:41
Location: California, USA

Postby albert » Oct 06, 2011 23:47

Heres a nice one.. "The Temple"

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const  pi as double = atn(1)*4
const rad as double = atn(1)/22.5

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp=1.5 , toggle = 0
dim as double deg1 , deg2
dim as double c1,c2
dim as double s1,s2

do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

       
        if toggle = 0 then temp += 0.01
        if toggle = 1 then temp -= 0.01
       
        if temp >= 2.500 then toggle = 1
        if temp <= 1.500 then toggle = 0
       
        glbegin gl_points
                for deg1 = 0 to 360 step 1
                    c1=cos(deg1*rad)
                    s1=sin(deg1*rad)
                   
                    for deg2 = 0  to 360 step 1
                        c2=cos(deg2*rad)
                        s2=sin(deg2*rad)
                       
                        glcolor3ub cos(c2*s2*temp)/1.5, cos(c2*s2*temp)/1.5 , cos(c2*s2*temp)/.25
                       
                        glvertex3f atan2( tan(c2+c2)*temp , tan(c1+c1)*temp ) *2 , atan2( tan(s2+s2)*temp , tan(s1+s1)*temp ) *2 ,  (cos(c1+s1)*3)*(temp)
                    next
                next
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end



This one is "The Target"

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const  pi as double = atn(1)*4
const rad as double = atn(1)/22.5

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp=1.5 , toggle = 0
dim as double deg1 , deg2
dim as double c1,c2
dim as double s1,s2

do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

       
        if toggle = 0 then temp += 0.01
        if toggle = 1 then temp -= 0.01
       
        if temp >= 2.500 then toggle = 1
        if temp <= 1.500 then toggle = 0
       
        glbegin gl_points
                for deg1 = 0 to 360 step 1
                    c1=cos(deg1*rad)
                    s1=sin(deg1*rad)
                   
                    for deg2 = 0  to 360 step 1
                        c2=cos(deg2*rad)
                        s2=sin(deg2*rad)
                       
                        glcolor3ub cos(c2*s2*temp)/1.5, cos(c2*s2*temp)/1.5 , cos(c2*s2*temp)/.25
                       
                        glvertex3f  (c1+c2)*temp*1.75 , (s1+s2)*temp*1.75 ,  log(c1*s1+s2*c2)/5 /cos(c1*s2*c2)
                    next
                next
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end



This one is "WWII Space-Ship"

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const  pi as double = atn(1)*4
const rad as double = atn(1)/22.5

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp=1.5 , toggle = 0
dim as double deg1 , deg2
dim as double c1,c2
dim as double s1,s2

do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

       
        if toggle = 0 then temp += 0.01
        if toggle = 1 then temp -= 0.01
       
        if temp >= 2.500 then toggle = 1
        if temp <= 1.500 then toggle = 0
       
        glbegin gl_points
                for deg1 = 0 to 360 step 1
                    c1=cos(deg1*rad)
                    s1=sin(deg1*rad)
                   
                    for deg2 = 0  to 360 step 1
                        c2=cos(deg2*rad)
                        s2=sin(deg2*rad)
                       
                        glcolor3ub cos(c2*s2*temp)/1.5, cos(c2*s2*temp)/1.5 , cos(c2*s2*temp)/.25
                       
                        glvertex3f  (c1+c2)*temp*1.75 , (s1+s2)*temp*1.75 , log((c2*s2*c1*s1))/5
                    next
                next
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end
 
albert
Posts: 5635
Joined: Sep 28, 2006 2:41
Location: California, USA

Postby albert » Oct 07, 2011 3:42

This one is "DumBell"

It really multi (candy colored)

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const  pi as double = atn(1)*4
const rad as double = atn(1)/22.5

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp=1.5 , toggle = 0
dim as double deg1 , deg2
dim as double c1,c2
dim as double s1,s2

do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

       
        if toggle = 0 then temp += 0.01
        if toggle = 1 then temp -= 0.01
       
        if temp >= 2.500 then toggle = 1
        if temp <= 1.500 then toggle = 0
       
        glbegin gl_points
                for deg1 = 0 to 360 step 1
                    c1=cos(deg1*rad)
                    s1=sin(deg1*rad)
                   
                    for deg2 = 0  to 360 step 1
                        c2=cos(deg2*rad)
                        s2=sin(deg2*rad)
                       
                        glcolor3ub  cos(c1)/1.25 , cos(s1)/1.25 , cos(c1+s1)/1.15
                       
                        glvertex3f  atn(s1*c1/c2/c2)*temp , atn(s1*c2*s2*4)*temp , ( atan2(c1*c2 ,c2*s2) )*3*atn(temp)
                    next
                next
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end


This one is "Two Birds"

Code: Select all

' w, s, a, d, q, e, right , left, space, esc
const false = 0
const true  = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-15, xr, yr, zr, xrs=5, yrs=1, zrs' transitions of camera

Const  pi as double = atn(1)*4
const rad as double = atn(1)/22.5

dim shared as uinteger vw, vh, vb=32, status = 1 'videosettings

screen 19
screeninfo vw, vh
Screenres vw, vh, vb, 1, 2
        windowtitle "test"
        glMatrixMode GL_PROJECTION
        glLoadIdentity
        gluPerspective 90, vw/vh, .1, 500
        glMatrixMode GL_MODELVIEW

        glLoadIdentity
        glblendfunc GL_SRC_ALPHA, GL_ONE
        glpointsize 6
        glenable gl_blend

'-----------------------------------------------------------------------

dim as double t, temp=1.5 , toggle = 0
dim as double deg1 , deg2
dim as double c1,c2
dim as double s1,s2

do while status=1

        t=timer
        glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
        glloadidentity
        gltranslatef xt, yt, zt
        glrotatef xr, 1, 0, 0
        glrotatef yr, 0, 1, 0
        glrotatef zr, 0, 0, 1       

       
        if toggle = 0 then temp += 0.01
        if toggle = 1 then temp -= 0.01
       
        if temp >= 2.500 then toggle = 1
        if temp <= 1.500 then toggle = 0
       
        glbegin gl_points
                for deg1 = 0 to 360 step 1
                    c1=cos(deg1*rad)
                    s1=sin(deg1*rad)
                   
                    for deg2 = 0  to 360 step 1
                        c2=cos(deg2*rad)
                        s2=sin(deg2*rad)
                       
                        glcolor3ub  cos(c2)/1.25 , cos(s2)/1.25 , cos(c2*s2)/1.15
                       
                        glvertex3f  atn(s1*c1/c2/c2)*temp , atn(s1*c2*s2*4)*temp , ( atan2(c1*c2 ,c2*s2) )*3*atn(temp*c1/c2*s1)
                    next
                next
        glend



        screensync
        flip
        glflush



        if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

        yrs = yrs + multikey(&h4D)/10 - multikey(&h4B)/10
        yr = yr + yrs
        xrs = xrs + multikey(&h50)/10 - multikey(&h48)/10
        xr = xr + xrs
        zt = zt + (multikey(&h10) - multikey(&h12))/10
        yt = yt + (multikey(&h11) - multikey(&h1F))/10
        xt = xt + (multikey(&h20) - multikey(&h1E))/10

        if multikey(&h39) then xrs=0: yrs=0: zrs=0: end if ' stop transitions

loop
end
 
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Postby podvornyak » Oct 07, 2011 4:41

albert wrote:With this GL what the color ranges ??

3ub - 3 unsigned byte
glcolor3ub 255 , 255 , 255

3f- 3 float
glcolor3f 1 , 1 , 1

You can check out here http://www.opengl.org/sdk/docs/man/

Code: Select all

void glColor3b(GLbyte red, GLbyte green, GLbyte blue);
void glColor3s(GLshort red, GLshort green, GLshort blue);
void glColor3i(GLint red, GLint green, GLint blue);
void glColor3f(GLfloat  red, GLfloat green, GLfloat blue);
void glColor3d(GLdouble red, GLdouble green, GLdouble blue);
void glColor3ub(GLubyte red, GLubyte green, GLubyte blue);
void glColor3us(GLushort red, GLushort green, GLushort blue);
void glColor3ui(GLuint red, GLuint green, GLuint blue);
void glColor4b(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha);
void glColor4s(GLshort red, GLshort green, GLshort blue, GLshort alpha);
void glColor4i(GLint red, GLint green, GLint blue, GLint alpha);
void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
void glColor4d(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha);
void glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
void glColor4us(GLushort red, GLushort green, GLushort blue, GLushort alpha);
void glColor4ui(GLuint red, GLuint green, GLuint blue, GLuint alpha);


glEnable gl_blend - enables color mixing/blending
glDisable gl_blend - color is exact as set but overprinting background.
albert
Posts: 5635
Joined: Sep 28, 2006 2:41
Location: California, USA

Postby albert » Oct 07, 2011 5:21

!! THANKS !!
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Postby podvornyak » Oct 07, 2011 9:55

Pendulum circles.

Code: Select all

'esc - quit
const false = 0
const true = 1

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-50 'translation
dim shared as double xr, yr=60, zr, xrs, yrs=0.01, zrs 'rotations

dim shared as uinteger vw, vh, vb=32 'video
screeninfo vw, vh
Screenres vw/2, vh/2, vb, 1, 3
windowtitle "test"

glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 45, vw/vh, .1, 500
glMatrixMode GL_MODELVIEW
glLoadIdentity

glblendfunc GL_SRC_ALPHA, GL_ONE
glpointsize 1
glenable gl_blend

dim as double temp, pi=atn(1)*4
dim as ubyte status = 1

do while status=1

   glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
   glloadidentity

   gltranslatef xt, yt, zt
   glrotatef xr, 1, 0, 0
   glrotatef yr, 0, 1, 0
   glrotatef zr, 0, 0, 1       

   temp += 0.01

   glbegin gl_points
      for a as double = 0 to pi-0.007 step 0.03
         for b as double = 0  to pi*2-0.007 step 0.03
            glcolor3f cos(a)*sin(b)/2, tan(a*temp)/100, sin(a)*cos(b)/2
            glvertex3f sin(a)*cos(b)*10, sin(a)*sin(b)*10, cos(a)*10 *sin(b)
         next b
      next a
   glend

   flip
   glflush

   if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit

   yr = yr + yrs
   xr = xr + xrs

loop
end
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Postby podvornyak » Oct 07, 2011 11:36

I've being thinking here and deside to make another propose. Should use multiprocess to reach more expensive results. Becouse of calling bunch of trigonometric function each loop, program run slow with more complex data.

Code: Select all

const false = 0
const true = not false

#include once "GL/gl.bi"
#include once "GL/glu.bi"

dim shared as double xt, yt, zt=-30 'translete camera
dim shared as double xr, yr, zr 'rotate camera
dim shared as double xrs=0.1, yrs=0.5, zrs 'rotate speed

dim shared as byte tread_stop = 0 'thread stop check value
dim shared as double value_sin, value_cos, value_tan, value_atn

dim shared as double a 'loop value

sub emmitt (setup as any ptr) ' threat-sub block
   do
      value_sin = sin(a)
      value_cos = cos(a)
      value_tan = tan(a)
      value_tan = atn(a)

   loop until tread_stop = 1 ' loop exit check
end sub

dim as any ptr emmitter ' thread memory address
emmitter = threadcreate(@emmitt) ' launch thread

' now thread working

dim shared as uinteger vw, vh, vb=32 'video
screeninfo vw, vh
Screenres vw/2, vh/2, vb, 1, 3

   windowtitle "test"
   glMatrixMode GL_PROJECTION
   glLoadIdentity
   gluPerspective 45, vw/vh, .1, 500
   glMatrixMode GL_MODELVIEW
   glLoadIdentity

   glblendfunc GL_SRC_ALPHA, GL_ONE
   glenable gl_blend

'-----------------------------------------------------------------------
dim as double temp, pi=atn(1)*4
dim as ubyte status = 1

do while status=1

   glclear GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
   glloadidentity

   gltranslatef xt, yt, zt
   glrotatef xr, 1, 0, 0
   glrotatef yr, 0, 1, 0
   glrotatef zr, 0, 0, 1       

   temp += 0.01
   for a  = 0 to pi*10 step 0.001
      glpointsize 1*value_tan
      glbegin gl_points
         glcolor3f tan(a*temp)/100, -tan(a*temp)/100, 0.04
         glvertex3f value_cos*value_tan*10, value_sin*value_cos*10, sin(value_tan)*cos(value_tan)+value_tan
      glend
   next a
   screensync
   flip
   glflush

   yr = yr + yrs
   xr = xr + xrs

   if multikey(&h01) or inkey = chr(255)+"k" then status = 0 'quit
loop

tread_stop = 1 ' stopping threads
ThreadWait (emmitter) 'wating until thread stops

end
It gives more flexible approach. Still searching optimal way to synchronize treads. This solution gives little speedup. But less speed consuming in over 200k cycles of main loop.
Last edited by podvornyak on Oct 07, 2011 17:35, edited 1 time in total.
dafhi
Posts: 1335
Joined: Jun 04, 2005 9:51

Postby dafhi » Oct 07, 2011 12:57

definitely some scene material :)
albert
Posts: 5635
Joined: Sep 28, 2006 2:41
Location: California, USA

Postby albert » Oct 07, 2011 22:01

@podvornyak

Thats real flashy!!

I was having the same problem with the speed.

I was thinking of pre-solving the trig portions and plugging the "end result vars" into the GL statement..Rather than calling the GL with the actual formulas, which i think is what slows it down..

Or pre-solving the whole thingy into arrays and then call the GL statement with the array loops..

Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 3 guests