BASIC

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - sf-in-sf

Pages: [1] 2
1
GLBasic - en / android trouble on winXP
« on: 2017-Nov-04 »
Hi! i am back on XP since my win7 machine died, and win7 became expensive. Back with a lovely game I would like to check on an android tablet.
When I compile for android I get:

_______________________________________
*** Configuration: ANDROID ***
precompiling:
GPC - GLBasic Precompiler V.10.037 SN:95ed84a0 - 3D, NET
Wordcount:8 commands
compile+link:
Android=E:\GLBasic_v14\FOO\distribute\Android
success
_______________________________________
*** Finished ***
Elapsed: 21.8 sec. Time: 21:48
Build: 1 succeeded.


What is going on? I read and applied all 3 pages of the forum to no avail.
I never see a Q: drive, my "E:\GLBasic_v14\FOO\distribute\Android" never contains a /bin nor a *.apk.
Strangely this win XP self-rooted in E:\ when installing. Is it a problem?
ant is installed and replies properly "xml is missing". (see the difference between a black ant and a green robot.)
adb is working too, does recognise the tablet.
I have set the SYSTEM variables ANDROID_SWT, ANDROIDSDK, ANT_HOME, JAVA_HOME (E:\Java\jdk1.6.0_29).
What can be wrong now?
XP has no E:\users\... folder do i need to make one?
During the making of everything, which batch files are called? -so I can manually check that each (batch script) call and location is correct?
Thank you!

2
Off Topic / Cookery
« on: 2015-Nov-04 »
Between coding and coding, what is better than cooking some nice food to revigorate your tired brain?
This post is to invite you to show off your best kept cookery secrets. Is it a problem? It shouldn't, this forum is not about cooking  =D
Thanks every one!

Now guess what is my favorite cafe in Berlin? Wohnzimmer! (= living room, Helmholtzplatz).

3
Hi! I am available to code "anything" -as long as you know what you want. Gaming, maths, physics, 3D are welcome. Please use a personal message to contact me. English, German, French are o.k.
sf-in-sf

4
IDE/Syntax / IDE + code
« on: 2015-Oct-12 »
Hi there!

A)
As a Basic programmer I still want a REM command. It has the same effect as // to start a line, but it's a good old b.a.s.i.c. style. Please, a bit of respect for the elders when doing some "retro" stuff.
B)
For the purpose of code clarity, I wish a command to temporarily change the code's background color, for a particular small section. So it becomes easy to spot the zone when scrolling some long code up and down. It could be named REM_BGCOL. It accepts a color like 0x003300 or rgb(0,51,0), and a DEFAULT value to go back to the standard color. It doesn't work inside an INLINE paragraph. It only talks to the IDE and is always skipped by the compiler.
C)
When some weird behaviour occurs I often wish to have an conditional stop/break/pause/debug function. It's an extension of the DEBUG function, where the breakpoint is triggered by a condition -e.g. some abnormal values, or why not a "catch error" line.
Thank you in advance!

5
IDE/Syntax / users' themes
« on: 2015-Jun-16 »
Is there a way to share our IDE appearance own themes -fonts and colors? So we could see what others do to make life easier to read on the screen. It's about the user's experience. Please suggest something.

6
Tools / command request
« on: 2015-Jun-16 »
Hi!
It's cool to have FILEREQUEST$ available but it's not enough. It lacks a title for the window, in order to make clear what is the requester for, when you need multiple requesters to locate various things. A title should say, for example, if you wanna read or write/give-a-new-filename...
Unfortunately, I found no FOLDERREQUEST$ (tell me if I am wrong). I need it to input where all the pictures of an album are located. Or, where sorted textures live together. Is there any way around that problem?

7
I wanted to see the sky...  :happy: it took me a few hours. Now I can die in peace.
I don't guarantee it's 100% right, but it works. Image size must be 2^n+1. This fractal generator is the base for anything like terrains: you will have to re-map colors to heights of the map/image. Those textures can be mapped later to low-poly surfaces, for fast 3D.
   Limitations: a) how to make images larger than the screen? even with CREATESCREEN() I don't get it. b) MEM2SPRITE() looks fast but a similar function is needed in order to accept directly a 2D array[][], and possibly setup the image size automatically.
   What else? ...  Licence? use and modify at will, but don't sell it without my consent. Credits: please mention my artist's name: F.P. Brixey
   Some post-stretching helps further (see pictures).
Here is a useful reference: http://www.gameprogrammer.com/fractal.html
Now go and be creative! -oh, and share your best groundbreaking images here. Thank you.
CloudGen.gbas:
Code: GLBasic [Select]
// --------------------------------- //
// Project: CloudGen
// Start: Tuesday, March 17, 2015
// IDE Version: 12.308


// SETCURRENTDIR("Media") // go to media files

CONSTANT N%= 9 //  image size = 2^N
CONSTANT startval=0xf000
CONSTANT damping=0.72277 //high value-> high contrast. lo ->no fine tesseling.
                                        // min. value should be 0.5 i.e. 50%
GLOBAL shift=0.03611 // i.e. % of displacement. Low values produce haze.

        GLOBAL s2%=twoPn(N)+1 , xx%=twoPn(N)
GLOBAL im_dat%[]; //DIM im_dat[s2*s2] // 1D only!
GLOBAL tmp%[]   ; DIM tmp[s2][s2];

GLOBAL range%=twoPn(N-1)

//set start values of 4 corners. Subdivide the square later, and reign.
tmp[0 ][0 ]=startval
tmp[0 ][xx]=startval
tmp[xx][0 ]=startval
tmp[xx][xx]=startval

GOSUB fill

GOSUB mem2s

SHOWSCREEN ; MOUSEWAIT ; END ;

fn.gbas:
Code: GLBasic [Select]
// --------------------------------- //
// Project: CloudGen
// Start: Tuesday, March 17, 2015
// IDE Version: 12.308



FUNCTION twoPn: n%
RETURN ASL(0x1,n)
ENDFUNCTION

FUNCTION setminmax: BYREF a, mi, ma
IF a<mi THEN a=mi
IF a>ma THEN a=ma
ENDFUNCTION

FUNCTION frnd:
?IFDEF PHASE1+
        STATIC a=0.41,b
                IF RND(1)
                        b= a*(RND(2000)-1000.0)*0.001
                        RETURN b
                ELSE
                        RETURN 0.0
                ENDIF
?ELSE
        RETURN 0.0
?ENDIF
ENDFUNCTION

SUB fill:

// GLOBAL s2%=twoPn(N)+1
// DIM tmp[s2][s2];
// GLOBAL range%=twoPn(N-1) //start value.
// CONSTANT rough=0.5 ; GLOBAL shift=0.4

// Say the output values are 32bits.
// 123
// 456
// 789 Supplied: 1379
//      Goal:    2 456 8

?IF 0
STATIC i%,j%,s5%,ste%
STATIC nb%=1

REPEAT
        ste=twoPn(N-nb+1)
        ste=twoPn(N-nb+1)
//      INC div; ste=(s2-1)/div

        FOR i=1 TO nb
        FOR j=1 TO nb
                setheight(tmp[i*ste][j*ste],tmp[(i+1)*ste][(j+1)*ste]) //5
        NEXT; NEXT;

        INC nb
UNTIL (N-nb+1)<0
?ENDIF

//////////////////////////////

ini:
LOCAL incr%=twoPn(N), i%, i2%
LOCAL j%,j2% //  xx%=twoPn(N)
LOCAL cnt%=0

REPEAT
        i=0
        REPEAT
        //      DEBUG incr ; DEBUG " "
                i2=i+incr

                        j=0
                        REPEAT
                                //DEBUG j ; DEBUG "_" ; DEBUG incr ; DEBUG "  ";
                                j2=j+incr
                                        tmp[(i+i2)*0.5][ j        ]=setheight(tmp[i][j],tmp[i2][j])
                                        tmp[ i        ][(j+j2)*0.5]=setheight(tmp[i][j],tmp[i][j2])

                                        tmp[(i+i2)*0.5][ j2       ]=setheight(tmp[i][j2],tmp[i2][j2])
                                        tmp[ i2       ][(j+j2)*0.5]=setheight(tmp[i2][j],tmp[i2][j2])
IF RND(100)>33 //let's mix the 2
                                        tmp[i+incr*0.5][j+incr*0.5]=setheight(tmp[i][j],tmp[i2][j2]) //produces diagonals.
ELSE
                                        tmp[i+incr*0.5][j+incr*0.5]=setheight(tmp[i+incr*0.5][j],tmp[i+incr*0.5][j2]) //no effect?
ENDIF
                                j=j2 ; INC j2,incr
                        UNTIL j2>xx


                i=i2 ; INC i2,incr
        UNTIL i2>xx
//      ASR(incr,1) //  x0.5 ASR not working!!!
        incr=incr*0.5
        shift=shift*damping

        //(debugging safety, sorry) INC cnt; IF cnt>144 THEN END
UNTIL incr < 2
//DEBUG "fill finished.   "
ENDSUB

SUB mem2s:
LOCAL a,col
//DEBUG MEM2SPRITE(......)    --> 1 or 0.
?IF 0 // long method... because 1 dimpush[] per pixel. not good.
//this section is excluded from pgm.
FOR i%=0 TO xx; FOR j%=0 TO xx;
        IF tmp[i][j]>startval //0x10000
                DIMPUSH im_dat[], 0xff007700//tmp[i][j] //orientation correct?
        ELSE
                DIMPUSH im_dat[], 0xaaffffff
        ENDIF
NEXT; NEXT;

IF MEM2SPRITE(im_dat[],0,s2,s2) THEN DEBUG "MEM2S' is o.k. "// :( Same size! 1D array only!
?ENDIF

//\/\/\/\/\/\/\/\/\/\/\/ faster:



FOR i%=0 TO xx; FOR j%=0 TO xx;

        a=((tmp[i][j])/startval +(0.2-1.0))/0.4 -1.0; setminmax(a,-0.99,-0.001)
        //ALPHAMODE a/2550
        //col=a*RGB(200,5,8) + (1.0-a)*RGB(250,250,250)
        ALPHAMODE 0
        col=0xbb3333
        SETPIXEL i,j, col  //no, use a single DRAWRECT at the start.
        ALPHAMODE a
        col=0xeeeeee
        SETPIXEL i,j, col //

NEXT; NEXT;

//MEM2SPRITE() could be faster, but accepts only 1D arrays.
ENDSUB

FUNCTION setheight: a,b
//STATIC k
//k=RND(3636)
IF RND(1)
        //RETURN (a+b)*0.5*(1+shift*100/RND(100)) // wow!
        RETURN (a+b)*0.5*(1+shift*(1.0+RND(1)*0.5))
ELSE
        RETURN (a+b)*0.5*(1-shift)
ENDIF
// or make up your own law of displacement. Be creative.
ENDFUNCTION
 

8
3D-snippets / introduction to CAD
« on: 2015-Feb-07 »
I realized it was easier to program 3D shapes (thank you so much Gernot) than using an unknown super-whizz-bang-3D-modeller software. The aftermath of a failed project shows the basic concepts for a CAD modeller. This approach is not the most graphical one, but anything is allowed if you want to program any kind of anything, like a very special procedural deformer, or probabilistic shapes like the natural trees !....
Use, re-use, ab-use, improve, or artistically decimate at will!

main:
Code: GLBasic [Select]
// --------------------------------- //
// Project: CADpipes_A
// Start: Saturday, November 08, 2014
// IDE Version: 10.283



//notes: Maybe it would make sense to create arrays of 3Dobjects
// in order to group them, (group or "layer")
// so we can quickly choose whether to draw or ommit a whole array/group.
// It depends what you do...
// Draw a group/layer with "FOREACH ob in group_array[]".

//colors are 0xBBGGRR in hex.
//arrows        -> move the camera.
// +/-          -> zoom
// 1/3,4/6,7/9  -> move model +/- on x,y,z axes.

// to do: every obj in a different color for clarity, then
// all of them in main color for final view. (probably all vertices in white, then use X_SETTEXTURE.)
// 3 guide planes / rasters in xy yz xz would be useful, switchable with "g".


LIMITFPS 25
CONSTANT rseg%=60//20
CONSTANT r_3=1.2
GLOBAL mcol%=0xaaffaa, scrx,scry
GLOBAL mousefree%, mx,my,b1,b2,t$
GLOBAL cam_d=75, cam_phi=6, cam_theta=20, cam_px=0,cam_py=0,cam_pz=0
GLOBAL model_px, model_py, model_pz
GOSUB make_bg


//make all pieces:
make_pipe_A(1,r_3,-1,1,mcol)//small, inside the S's
make_pipe_A(2,r_3,-5,5,0xbbbbbb)
make_pipe_A(3,r_3,0,100,0xe07777)//0x99ff33)

make_shoulder_A(20,r_3,30,90,10,mcol)
make_shoulder_A(24,r_3,30,180,10,mcol)
//make_disc(201,5,360,8,0xff5500)
//make_closed_cylinder(101,5,300,30,1,-1,0x00ffff)
//---------------------------------


//  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
main:
X_MAKE2D ; DRAWSPRITE 1,0,0
X_MAKE3D 1,1024,35

X_CAMERA cam_d*COS(cam_phi)*COS(cam_theta),cam_d*SIN(cam_theta),cam_d*SIN(cam_phi)*COS(cam_theta), cam_px,cam_py,cam_pz
X_AMBIENT_LT 0,0x66bb66
X_SPOT_LT 1,0xccffff,4,2,1,  0,0,0,360

X_DRAWAXES cam_px, cam_py,cam_pz //0,0,0
GOSUB draw_all
SHOWSCREEN
HIBERNATE

//arrows -> move the camera, theta and phi.
//keypad -> 5 = recenter all, else move model's x,y,z.
// 1,4,7 <=> x,y,z and East<=> increase, West <=> decrease.
//Axes: RGB <=> xyz. Easy!
IF KEY(74) THEN INC cam_d,2
IF KEY(78) THEN DEC cam_d,2
        setminmax(cam_d, 2, 300)
IF KEY(203) THEN INC cam_phi,2
IF KEY(205) THEN DEC cam_phi,2

IF KEY(200) THEN INC cam_theta,2
IF KEY(208) THEN DEC cam_theta,2
        setminmax(cam_theta, -84,84)

IF KEY(79) THEN INC model_px,5 //kp1
IF KEY(81) THEN DEC model_px,5 //3
IF KEY(75) THEN INC model_py,5 //4
IF KEY(77) THEN DEC model_py,5 //6
IF KEY(71) THEN INC model_pz,5 //7
IF KEY(73) THEN DEC model_pz,5 //9
IF KEY(76) // kp "5" = "help, I'm lost"
        cam_px=0 ; cam_py=0 ; cam_pz=0 //unused, always 0, weird movements otherwise.
        model_px=0 ; model_py=0 ; model_pz=0
ENDIF
IF KEY(48) THEN GOSUB make_bg
//note: the inc/dec should follow the zoom values,as an option.

GOTO main
//   //////////////////////////////////////////////////////////

 

fn.gbas
Code: GLBasic [Select]
// --------------------------------- //
// Project: CADpipes_A
// Start: Saturday, November 08, 2014
// IDE Version: 10.283




//*****************************
// obj  1+ --> pipes          *
// obj 20+ --> shoulders      *
//*****************************

FUNCTION make_pipe_A: obnum%, r, l1,l2,col//straight pipe
//LOCAL rseg%=120,
//LOCAL r= 0.33, l1=-2.0, l2=2.0
STATIC ka, kb
X_OBJSTART obnum//1
        FOR i=0 TO rseg-1
                ka=360*i/rseg ; kb=360*(i+1)/rseg
                X_OBJADDVERTEX r*COS(ka),r*SIN(ka),l1, 0,0,col
                X_OBJADDVERTEX r*COS(ka),r*SIN(ka),l2, 0,0,col

                X_OBJADDVERTEX r*COS(kb),r*SIN(kb),l1, 0,0,col
                X_OBJADDVERTEX r*COS(kb),r*SIN(kb),l2, 0,0,col
                        X_OBJNEWGROUP
        NEXT

X_OBJEND
ENDFUNCTION

FUNCTION make_shoulder_A: obnum%,r,sh_seg%,sh_an,sh_r,col  //rounded corner
// works like a deformer. Here the pipe segments' Nb are always rseg!
// bow's length <- shoulder's r and angle. easy.
STATIC ka, kb, ka2,kb2, x1,y1, x2,y2, x3,y3,z3, x4,y4,z4, x5,y5,z5, x6,y6,z6
X_OBJSTART obnum
        FOR i=0 TO rseg-1
                ka=360*i/rseg ; kb=360*(i+1)/rseg
                x1=r*COS(ka)+sh_r ; y1=r*SIN(ka)
                x2=r*COS(kb)+sh_r ; y2=r*SIN(kb)

                FOR j=0 TO sh_seg-1
                        ka2=sh_an*j/sh_seg ; kb2=sh_an*(j+1)/sh_seg
                        x3=x1*COS(ka2)
                        x5=x1*COS(kb2)
                        x4=x2*COS(ka2)
                        x6=x2*COS(kb2)
                        y3=y1 ; y5=y1 ; y4=y2 ; y6=y2

                        z3=x1*SIN(ka2)
                        z5=x1*SIN(kb2)
                        z4=x2*SIN(ka2)
                        z6=x2*SIN(kb2)

                        X_OBJADDVERTEX x3,y3,z3, 0,0,col
                        X_OBJADDVERTEX x5,y5,z5, 0,0,col
                        X_OBJADDVERTEX x4,y4,z4, 0,0,col
                        X_OBJADDVERTEX x6,y6,z6, 0,0,col
                        X_OBJNEWGROUP
        NEXT ; NEXT

X_OBJEND
ENDFUNCTION //ENDSUB worked!


?IF 0 //not compiled, now unused:
// 2D is 200+
FUNCTION make_disc: obnum%, r,an,sectors,col%
STATIC ka, kb
X_OBJSTART obnum //200+
        FOR i=0 TO sectors-1
                ka=an*i/sectors ; kb=an*(i+1)/sectors
                X_OBJADDVERTEX r*COS(ka),r*SIN(ka),0,  0,0, col
                X_OBJADDVERTEX 0,0,0,  0,0, col
                X_OBJADDVERTEX r*COS(kb),r*SIN(kb),0,  0,0, col
                X_OBJNEWGROUP
        NEXT
X_OBJEND
ENDFUNCTION
FUNCTION make_closed_cylinder: obnum%, r,an,sectors,thickup,thickdown,col%
STATIC ka, kb
X_OBJSTART obnum //200+
        FOR i=0 TO sectors-1
                ka=an*i/sectors ; kb=an*(i+1)/sectors
                X_OBJADDVERTEX r*COS(ka),r*SIN(ka),thickup,  0,0, col
                X_OBJADDVERTEX 0,0,thickup,  0,0, col
                X_OBJADDVERTEX r*COS(kb),r*SIN(kb),thickup,  0,0, col
                X_OBJNEWGROUP//stripe mode only.
                X_OBJADDVERTEX r*COS(ka),r*SIN(ka),thickdown,  0,0, col
                X_OBJADDVERTEX 0,0,thickdown,  0,0, col
                X_OBJADDVERTEX r*COS(kb),r*SIN(kb),thickdown,  0,0, col
                X_OBJNEWGROUP//stripe mode only.

                X_OBJADDVERTEX r*COS(ka),r*SIN(ka),thickup,  0,0, col
                X_OBJADDVERTEX r*COS(kb),r*SIN(kb),thickup,  0,0, col
                X_OBJADDVERTEX r*COS(ka),r*SIN(ka),thickdown,  0,0, col
                X_OBJADDVERTEX r*COS(kb),r*SIN(kb),thickdown,  0,0, col
                X_OBJNEWGROUP//(edge)
        NEXT
X_OBJEND
ENDFUNCTION
?ENDIF //unused functions

FUNCTION setminmax: BYREF a, mi, ma
IF a<mi THEN a=mi
IF a>ma THEN a=ma
ENDFUNCTION

gosubb.gbas
Code: GLBasic [Select]
// --------------------------------- //
// Project: CADpipes_A
// Start: Saturday, November 08, 2014
// IDE Version: 10.283


SUB draw_all:
X_MOVEMENT -model_px, -model_py, -model_pz ; X_PUSHMATRIX
//top wave:----------------
FOR i=0 TO 2
        X_MOVEMENT 40*i,0,0 ; X_PUSHMATRIX
                GOSUB draw_S1
        X_POPMATRIX
NEXT
//  (end segment)
X_MOVEMENT 100,0,0 ; X_ROTATION 180, 0,1,0
        X_DRAWOBJ 24,0
X_MOVEMENT 0,0,0

//mid wave
X_MOVEMENT 0,0,30 ; X_PUSHMATRIX
        GOSUB draw_S2
X_POPMATRIX

//bottom wave
        X_MOVEMENT 0,0,60 ; X_PUSHMATRIX
                GOSUB draw_S2
        X_POPMATRIX

//montants hauts / Frame bar:

        X_MOVEMENT -30,0,0 ; X_DRAWOBJ 3,0

X_POPMATRIX
ENDSUB

SUB draw_S1:
X_MOVEMENT -20,0,0 ; X_ROTATION 180, 0,1,0
        X_DRAWOBJ 24,0
X_MOVEMENT 0,0,2 ; X_DRAWOBJ 24,0

X_MOVEMENT 10,0,1 ; X_DRAWOBJ 1,0
X_MOVEMENT -10,0,1 ; X_DRAWOBJ 1,0
ENDSUB

SUB draw_S2:

        FOR i%=1 TO 3
                X_MOVEMENT i*40-40,0,0
                        X_DRAWOBJ 24,0
                X_MOVEMENT i*40-50,0,-1 ; X_DRAWOBJ 1,0
                X_MOVEMENT i*40-30,0,-1 ; X_DRAWOBJ 1,0
        NEXT
        FOR i%=1 TO 2
                X_MOVEMENT i*40-20,0,-2 ; X_ROTATION 180, 0,1,0
                        X_DRAWOBJ 24,0
        NEXT

        //2 end 90 elbows:
        X_MOVEMENT -20,0,-2 ; X_ROTATION 90,0,1,0 ; X_DRAWOBJ 20,0
        X_MOVEMENT 100,0,-2 ; X_ROTATION 180,0,1,0 ; X_DRAWOBJ 20,0
        // 2 end straights:
        X_MOVEMENT -25,0,-12 ; X_ROTATION 90,0,1,0 ; X_DRAWOBJ 2,0
        X_MOVEMENT 105,0,-12 ; X_ROTATION 90,0,1,0 ; X_DRAWOBJ 2,0
ENDSUB


SUB make_bg:
GETSCREENSIZE scrx,scry
CREATESCREEN 1,1,scrx,scry ; USESCREEN 1
LOCAL c%
FOR i=0 TO scrx STEP (scrx/12.0)
        IF RND(100)>33
                c=0x010101*(55+RND(190))
        ELSE
                c=BOR(RND(0xffffff),ASL(0xff,8*RND(2))) //not dull, 1 chanel is full on.
        ENDIF
        DRAWRECT i,0, scrx,scry,c
NEXT

USESCREEN -1
ENDSUB
 



9
==== EDIT =====
   Finally my obfuscator works -a long, difficult job. It keeps the GLb commands and translates the rest into confusing generic "values", in selectable styles. The media files are automatically copied and renamed with fancy-names which are re-used in the source files accordingly. It worked with my 2505-commands game project, spanned on 10 *.gbas files, and about 50 media files. {Get it on the android market: flip7. By the way the first version costs 1$ and any advice is welcome about monetizing the app in a better way}.
  Back to the obfuscator: the generated code is meaningless : functions, variables, media files, are meaningless, random, looking all similar and confusing. But the program still works like before.
  • Supported features : multi-files, all GLb commands, media copy + renaming, intact 0x..... numbers, mark some words as keep-unchanged, automatic comment removal, choose/make your own style for generated words. Preprocessor code still works.
  • Not supported so far : INLINE'd code.

   Drop me a message if you are interested. You can get the customizable source code for a small price. Licence  :rtfm:  use and modify freely, you only. Don't distribute or sell anything in any way without my agreement. Please contact me for any unspecified case.

10
This example shows zooming in 2D with 2 fingers on android. Gernot's example must be changed for android: I get 16 detected mice permanently, but never more than 4 pointers. "Pinch" is about looking at fingers behaviour, and can control the 3D camera as well. Pointers location and number are shown on screen. Works on Archos tablet 10.1 G9. Have fun and tell us your story.
Code: GLBasic [Select]
// --------------------------------- //
// Project: pinch00
// Start: Tuesday, April 15, 2014
// IDE Version: 10.283
// SETCURRENTDIR("Media") // go to media files

SYSTEMPOINTER TRUE
CONSTANT rectNb%=33 // up to you
GLOBAL scrx%,scry%, zoom=1.0, cx,cy
GLOBAL sqx[],sqy[],sqw[],sqh[],sqcol%[]
GLOBAL mx%, my%,b1%,b2%
DIM sqx[rectNb+1] ; DIM sqy[rectNb+1] ; DIM sqw[rectNb+1] ; DIM sqh[rectNb+1] ; DIM sqcol[rectNb+1]
        FOR i% =0 TO rectNb
                sqx[i]=RND(900)*0.001 ; sqy[i]=RND(900)*0.001
                sqw[i]=0.05 +0.001*RND(155) ; sqh[i]=0.05 +0.001*RND(155)
                sqcol[i]=RGB(255/(1+RND(4)),255/(1+RND(4)),255/(1+RND(4)))
        NEXT

GETSCREENSIZE scrx,scry ; cx=scrx*0.5 ; cy=scry*0.5

//********************
WHILE TRUE
        GOSUB redraw
        ?IFDEF WIN32
                GOSUB kees //windows only. No double glazing.
        ?ENDIF
        GOSUB mousedetect
        SHOWSCREEN
WEND
//********************

END

SUB redraw:
FOR i%=0 TO rectNb
        DRAWRECT scrx*(0.5+(sqx[i]-0.5)*zoom),scry*(0.5+(sqy[i]-0.5)*zoom), _
        scrx*zoom*sqw[i], scry*zoom*sqh[i],sqcol[i]
NEXT
ENDSUB

?IFDEF WIN32
SUB kees:
STATIC k$
        k$=INKEY$()
        SELECT k$
                CASE "," // <<
                        zoom=zoom*0.99
                CASE "." // >>
                        zoom=zoom*1.01
        ENDSELECT
ENDSUB
?ENDIF

SUB mousedetect:
STATIC newmousecount%, zoomMem, mem //mouse distance
STATIC mouseAmount%
        newmousecount=GETMOUSECOUNT() ; mouseAmount=0
//draw pointers
        FOR i%=0 TO newmousecount-1
                //0->15 on android, all the time.
      SETACTIVEMOUSE i
      MOUSESTATE mx, my, b1, b2
      IF (b1+b2)
        drawmouse(i) ; INC mouseAmount
      ENDIF
      PRINT newmousecount, 10,200
      // always =16 on android, Archos tablet G9 10.1
        NEXT
//fingers' gym (best with 2 fingers...)
        SELECT mouseAmount //how many fingers on screen?
                //CASE 1 // glide
                //     
                CASE 2 //zoom. Implement rotation here.
                // could change camera position and FOV in 3D.
       
                        IF mem=0.0 //fresh fingers
                                mem=getdistance()
                                zoomMem=zoom //store the start values.
                        ELSE // pinch that spot, enjoy the magic
                                zoom=zoomMem*getdistance()/mem
                        ENDIF
                //CASE 3 //special config. Usable.
                //CASE 4 //Usable too. Wave a white flag.
                DEFAULT
                        mem=0.0 // fingers off
        ENDSELECT
ENDSUB

FUNCTION drawmouse: n%
STATIC p%
        FOR i%=0 TO n
                p=55+i+i+i
                DRAWLINE mx-p,my-p,mx+p, my-p, 0xffff00
                DRAWLINE mx-p,my+p,mx+p, my+p, 0xff99ff
                DRAWLINE mx-p,my-p,mx-p, my+p, 0xff99ff
                DRAWLINE mx+p,my-p,mx+p, my+p, 0xffff00
        NEXT
ENDFUNCTION

FUNCTION getdistance:
STATIC mx1%,mx2%,my1%,my2%,bb%,bbb%,d
        SETACTIVEMOUSE 0
        MOUSESTATE mx1,my1,bb,bbb
        SETACTIVEMOUSE 1
        MOUSESTATE mx2,my2,bb,bbb
        d=SQR((mx1-mx2)*(mx1-mx2) +(my1-my2)*(my1-my2))
PRINT "                       ", 30,30
PRINT d,30,30
RETURN d
ENDFUNCTION

11
IDE/Syntax / 3 features suggestion
« on: 2013-Oct-30 »
[-]  I'd like to set myself the background color of some portions of the code, for better readability.
[-]  The "find" (ctr-f) tool needs an option to search directly through all *.gbas files of the project, when you have many of them.
[-]  Sometimes it's useful to add a comment in the middle of a long line. How about implementing something like /-shortcomment-/ ?

12
3D / 3D transparency
« on: 2013-Oct-30 »
Hi!
I need an X_ALPHAMODE, or an X_OBJADDVERVERTEX with RGBA colors. Any idea?
Not easy I guess. GL ES for android makes it even worse...

Code: GLBasic [Select]
// --------------------------------- //
// Project: test-3D-transparency
// Start: Wednesday, October 30, 2013
// IDE Version: 10.283


SETCURRENTDIR("Media") // go to media files

CONSTANT MK3D1%=1, MK3D2=256, MK3D3=80 // zfar down to 16 is still o.k. for this example!
LOADSPRITE "smallpicture.png",1
DRAWSPRITE 1, 3,3

X_OBJSTART 0
        X_OBJADDVERTEX -1.0,-1.0,0.0,  0.0,1.0, 0xffffff        //SW
        X_OBJADDVERTEX -1.0, 1.0,0.0,  0.0,0.0, 0xffffff        //NW
        X_OBJADDVERTEX 1.0 ,-1.0,0.0,  1.0,1.0, 0xffffff        //SE
        X_OBJADDVERTEX 1.0 ,1.0 ,0.0,  1.0,0.0, 0xffffff        //NE
        // Note: is there no way to enter an alpha color?
        //      As soon as you use a color different from 0xffffff
        //      the ALPHAMODE stops working, stopping transparency.
       
        // Problem: I must choose either vertex colors or transparency,
        // but I need both.
X_OBJEND

        X_MAKE3D MK3D1, MK3D2, MK3D3//1,256,80
        X_CAMERA 0,0,3,  0,0,0
        X_SETTEXTURE 1,-1
        ALPHAMODE -0.33
       
        FOR i%= -4 TO 0
                X_MOVEMENT 0,0,i
                X_DRAWOBJ 0,0
        NEXT
               
SHOWSCREEN
MOUSEWAIT
END

13
I'm glad it works. It saves a COS() and SIN() calculation. It's an emulation of 2 integrating op-amps in a loop producing a sin and a cos signal. The integration factor -frequency dependent- is not compensated yet. Before asking many questions please study the analog computer, or the theory of servos and feedback stability. It's a great tool to produce nice or unexpected movements. Wish you fun and creative experimenting. Please share your examples.
Code: GLBasic [Select]
// --------------------------------- //
// Project: sinosc1
// Start: Saturday, September 14, 2013
// IDE Version: 10.283
//Emulates the analog computer, with 2 integrators and a loop.

SETSCREEN 800,200,0
CONSTANT cx%=400, theta=0.115 //time constant
// signal 1 and signal 2: (initial state)
GLOBAL s1=0,s2=33, _s1,_s2
WHILE TRUE
        integrate()
        DRAWRECT cx+s1, 12, 20,60, RGB(255,155,0)
        DRAWRECT cx+s2, 94, 20,60, RGB(0,255,255)
        FOR i%=0 TO 800 STEP 40
                DRAWLINE i,166, i,200,0xffffff
        NEXT
        SHOWSCREEN
WEND

FUNCTION integrate:
        _s1=s1 ; _s2=s2
        s2=s2-theta *_s1*0.8
        s1=s1-theta *(-_s2)
       
        IF s2>220 THEN s2=220+(s2-220)*0.92 // knee-clip the 1st op-amp.
        IF s2<-220 THEN s2=-220+(s2+220)*0.92 //necessary but not too hard please.

ENDFUNCTION
Offtopic: here is an interesting test; imagine the blue and red bars are mounted at the edge of rotating disc. When you see the disc in motion, does it turn to the right or the left?

14
Hi!
I managed to debug my android tablet (archos 10.1 g9) thanks to "ddms" command line on xubuntu linux. (dalvik debug monitor service. Should work in console on windows too, once you have adb.)
Bug: after 8 resizings using "USESCREEN 2" and POLYVECTOR those corresponding sprites disappear from the screen. It happens after about 20 times in the emulator, and never on windose. I'm surprised that only the sprites disappear. The rest drawn with POLYVECTOR keeps running o.k. I thought DRAWSPRITE was less consuming... Then the debugger repeats "glBindRenderbufferExt failed 8cdd". If you look at http://code.google.com/p/monkey-ext/source/browse/monkey/modules/opengl/gles20_src.txt?r=34f0e133a20e2fc86e0060b0f962c1c6aace282d you will see that 0x8cdd means
Quote
Const GL_FRAMEBUFFER_UNSUPPORTED
.
Thank you for any suggestion.

UPDATE:
   ddms seems to only work on linux.
hint for beginners: *) install adb etc... *) in a console type: "adb devices". (if you don't see the device it isn't installed yet.) *) "adb usb"  *)"ddms". *) then watch the debug window to see what the device or emulator does.
Linux newbies? get a "live cd" of xubuntu or lubuntu and burn the *.iso on a cd with "isoburn". Set the bios to boot on the cd before the hd. in 5 minutes it's up and running, without hd installation.

UPDATE / SOLVED.
I found that my resize routine calls a GENSPRITE() everytime. By repeating this, I end up busting the sprite memory, so the new sprites are empty and invisible. This is where it can be dangerous to develop on an oversized machine with plenty of ram: the problem doesn't show up. Then I find GENSPRITE() dangerous too. It's o.k. to load sprites at the beginning of a program, but if you use it regularly you should remember to de-allocate the previous sprites. Perhaps >> LOADSPRITE "",  old_sprite_num works? I haven't tried.
Finally I don't understand the error message. What's the relationship with busting the sprite (or ram?) memory ?
Finally I'd like to recommend the test of running the app in the emulator with small memory size, in order to spot this kind of problem: MEMORY LEAKS

15
GLBasic - en / member functions of TYPE
« on: 2013-Aug-27 »
Here is an example of encapsulted functions inside a TYPE. Keep in mind they are supposed to be the external "public buttons" of your objects.
It works like that.
I didn't get the green "this" to work -both in GLb and C- but appearently "self" would be the right word. I will try it.
Code: GLBasic [Select]
// --------------------------------- //
// Project: encaps_function
// Start: Thursday, August 22, 2013
// IDE Version: 10.283 // just updated

// The green "this" remains a mystery to me,
// but the program works like that:
TYPE sq
        size%=100;
        dir%=1;
        //dummy%=0
        FUNCTION changesize: // a member function, "encapsulated".
                INLINE //Now use the different C syntax:
       
                if (dir>0)
                        {INC(size); //should be this.size?
                                if (size>222)
                                {size=200; dir=0;}     
                        }
                else
                        {DEC( size);
                        if (size<77)
                                {size=88 ; dir=2;}
                        }
        //      ENDIF // not in C.
                ENDINLINE

        ENDFUNCTION
        FUNCTION draw:
                INLINE
                DRAWRECT( 33,33,size,size, 0xffbb99);
                ENDINLINE
        ENDFUNCTION
ENDTYPE

LOCAL s AS sq  //instanciation
WHILE TRUE
// call member functions of the object:
        s.changesize()
        s.draw()
        // i.e. push the external buttons of
        // the closed object.
        SHOWSCREEN
WEND

// P.S. a typical example of such member functions are
// "accessors", used to get or set the encapsulated values
// of the object from the outside.
 

Pages: [1] 2