Menu

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.

Show posts Menu

Messages - sf-in-sf

#46
Quite a few things don't work on android because of GLES. Gernot describes that nicely in a topic about deploying to iOS. The same problems happen because of GLES restrictions. I remember that grabsprite, texture bump, shadows, etc. don't work. I found it useful to build all the 3D demo programs to (your device)/my tablet to see what works and what doesn't.
However everything works on a computer thanks to openGL.
#47
It took me a while to learn and experiment with POLYVECTOR.
The code could be faster: I just noticed that each segment calculates 2 sin and 2 cos, i.e. 2x too much.... the new point's coordinates must be kept in memory (static for example) and used later for the next segment, as the old point. No need to calculate twice.
I'm busy now. Please have a go and see if that new version is really faster. If it goes very fast then SHOWSCREEN will set a limit of 60 objects per second, which isn't right. I'll be back next week or so.
#48
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?
#49
Fuzzy, I didn't try your code but it looks fine. Here is my version. Polyvector is definitely fast. For large circles increase the gon value, and reduce it for small circles, for best appearance and speed.
Code (glbasic) Select
// --------------------------------- //
// Project: drawcirc-polyv
// Start: Saturday, September 14, 2013
// IDE Version: 10.283

SETSCREEN 800,600,0 //whatever
GLOBAL gon%, r%, th%, col%, cx%,cy%

here:
r=50+RND(200)
th=1+33*RND(2)
col=RGB(255*RND(1),255*RND(1),255*RND(1))
cx=RND(800) ; cy=RND(600)
IF RND(1)=1 // 50% odds.
gon=120 // steps nb, reduce for v.small circles.
ELSE
gon=3+RND(5) // n-gon.
ENDIF
drawcircpolyv(gon,cx,cy,r,th,col)
USEASBMP // ad lib
SHOWSCREEN
GOTO here
//END

FUNCTION drawcircpolyv: g%,cx%,cy%,r%,t%,c%
LOCAL sin1,sin2,cos1,cos2
STARTPOLY -1,2 // no texture, strip mode.
//(use or generate a texture with blended edges
// to skip alpha values interpolation. Donate to inkscape).
// 0___2___4__
//  \ / \ / \
//   1___3___5 etc
// parallelograms are 0-1-2-3, 2-3-4-5, 4-5-6-7, etc.

FOR i% =0 TO g-1
sin1=SIN(i*360/g) ; cos1=COS(i*360/g)
sin2=SIN((i+1)*360/g) ; cos2=COS((i+1)*360/g)
POLYVECTOR cx +cos1*(r-t*0.5), cy+sin1*(r-t*0.5), 0,0,c //0, inbound
POLYVECTOR cx +cos1*(r+(t+1)*0.5), cy+sin1*(r+(t+1)*0.5), 0,0,c //1, outbound
POLYVECTOR cx +cos2*(r-t*0.5), cy+sin2*(r-t*0.5), 0,0,c //2, inbound
POLYVECTOR cx +cos2*(r+(t+1)*0.5), cy+sin2*(r+(t+1)*0.5), 0,0,c //3, outbound
// (t+1) allows thickness =1.
NEXT
ENDPOLY
ENDFUNCTION
#50
oh yes, of course. The pb is somewhere else. Maybe some repeated GENSPRITE() 's on the fly too... I don't know yet. Update: dalvik debugger "ddms" seems to only work on linux.
EDIT - SOLVED
It's a kind of memory leak. See the 1st post edits.
#51
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
QuoteConst 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
#52
Thanks for the comments everyone. Someone more experienced is welcome to re-write the code in a better way, and post it to the community. Thanks in advance.
I find this tuto is an important key to get started with the  object functionality of GLb, and I feel it should appear in a form or another in the help files / manual, Gernot. It's a pitty that "self" is not documented.
#53
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.
#54
Does 'dda' have more features than 'ddd'?
From blender I export a '3ds' file, then use the 3D converter in the GLb tools and save a 'ddd' version in /Media folder. It worked perfectly for me, with correct colors and lighting.
#55
Hi!
Using CONSTANT is safer than GLOBAL or LOCAL when declaring genuine constants.
#56
Hi!
It's safer to use CONSTANT than GLOBAL or LOCAL when you declare constants. It's impossible to change their values afterwards, and they are compiled as constants, not using the r.a.m. which is faster to run.
-
I noticed a few GRABSPRITE. This means the game will be totally fine only on PCs/mac. On android or iOS you will get white squares -and it's not Gernot's fault.
A way around it -a bit slower- is to draw everything in a different screen (use CREATESCREEN), i.e. on its associated image. Then you can work on the image at will, like SPRITE2MEM, SETPIXEL  etc. When ready just draw the image on the main screen with USESCREEN -1.
#57
Tutorials / mainloop()
2013-Jul-24
Hi!
Here is an attempt at running a "mainloop" for all objects at once, like in python. Interesting for gaming or GUI design. Objects of different types get created and deleted dynamically. It's also a solution to get an abstract class functionnality in GLb, without C++.
Have good fun!
Code (glbasic) Select
// --------------------------------- //
// Project: TYPE_1 (pure abstract classes in C++ failed)
// Start: Saturday, July 20, 2013
// IDE Version: 10.244


// --------------------------------- //
// Project: TYPE_2
// Start: Tuesday, July 16, 2013
// IDE Version: 10.244


// SETCURRENTDIR("Media") // go to media files
SETSCREEN 500,500,0
SYSTEMPOINTER FALSE
//LIMITFPS 30

GLOBAL oblist%[] AS ob // like a pure abstract class, an array of various objects.
//GLOBAL collist%[] ; DIMDATA collist%[],0xcc66ff,0x00bb55, 0x0055ff,0xcc7777, 0x777777
TYPE ob
shape$ ="sq" // is the TYPE of each object, in fact.
// used later in a "switch" to apply the correct drawing function,
// like a function member of each object in C++.
color% = 0x666666 //default color
val1=0 ; val2=0 ; val3=0 // generic, use varies depending on the type of object.
px ; py ; vx ; vy
// weapons% =0
intelligence% = 4 // (bonus included, haha)
dizziness% =1
bounces%=4 // max. bounces allowed, the deletion criterium.
ENDTYPE

start:
FOR bzzz% = 1 TO 440 ; new_ob() ; NEXT // create n objects
GLOBAL t0%, t% , stamp%
LOCAL ciao%
t0=GETTIMERALL() ; t=t0+2000

mainloop://____run_all_objects_at_once__________________._____________________
WHILE TRUE
FOREACH z IN oblist[]
ciao=animate(z)
IF ciao >0 THEN DELETE z // [death]
//DELETE must be inside a loop, otherwise you need to know
// the (int) position of object z inside the array oblist[]. How do you get that?
// Please post me the answer if you know it.
NEXT
PRINT LEN(oblist[]), 5,5
SHOWSCREEN
stamp=GETTIMERALL() // MUST be GLOBAL apparently, too tricky otherwise.
IF stamp >t
t=t+500+RND(700) //1789+RND(1984)
new_ob()  // [birth]
// DRAWRECT 10,10,222,222, RGB(255,255,0) // visualize creation time
ENDIF
WEND
//______________________________________________________._____________________


FUNCTION new_ob:
LOCAL z AS ob // new, inherits default values
// z.color = collist[RND(4)]
z.color = bOR(RND(0xffffff), ASL(0x000000f0,8*RND(2)))
// avoiding dark or unsaturated colors.

IF RND(1) // if shape is sq
z.px =250.0 ; z.py =250.0
z.vx =rnddr2() ; z.vy =rnddr2()
z.val1=6+RND(30) ; z.val2=6+RND(30)
// more t.b.c.
ELSE
z.px =250.0 ; z.py =250.0
z.vx =rnddr2() ; z.vy =rnddr2()
z.shape$="tri" ; z.val1=RND(84)-42
ENDIF
DIMPUSH oblist[], z
ENDFUNCTION
FUNCTION animate: z AS ob

INLINE
//moves, common, C-style:
z.px +=z.vx ; z.py+=z.vy;
if(z.px <50)
{z.vx =rnddr(); z.vy=rnddr2()  ; z.px=50;   z.bounces-=1 ; if (z.bounces <1) {return(7);}}
if(z.py <50)
{z.vy =rnddr(); z.vx=rnddr2()  ; z.py=50;   z.bounces-=1 ; if (z.bounces <1) {return(7);}}
if(z.px >450)
{z.vx = -rnddr(); z.vy=rnddr2(); z.px =450; z.bounces-=1 ; if (z.bounces <1) {return(7);}}
if(z.py >450)
{z.vy = -rnddr(); z.vx=rnddr2(); z.py=450;  z.bounces-=1 ; if (z.bounces <1) {return(7);}}

ENDINLINE

//switch to apply the right function:
IF z.shape$ = "sq" // "according to the type" like an abstract class.
DRAWRECT z.px,z.py,z.val1,z.val2,z.color
ELSEIF z.shape$="tri"
STARTPOLY -1,1 //no texture, iMode=tri
POLYVECTOR z.px, z.py-z.val1,   0,0, z.color
POLYVECTOR z.px+10, z.py,       0,0, z.color
POLYVECTOR z.px-10, z.py,       0,0, z.color
ENDPOLY
ELSE
// another default type of object.
ENDIF // ...should be usable to make a custom GUI.

RETURN 0 // i.e. "don't delete this element"
ENDFUNCTION
FUNCTION rnddr:
RETURN (RND(3000)+5)/1000.0
ENDFUNCTION
FUNCTION rnddr2:
IF (RND(1)) ; RETURN rnddr()
ELSE
RETURN -rnddr()
ENDIF
ENDFUNCTION

#58
Quote from: CW on 2013-Mar-18
How do you think your code for creating simple disks would compare, speed wise, with plotting a disk to the screen, doing a GRABSPRITE of that disk, [...]

Hi cw!
I never use GRABSPRITE, it doesn't work on iOS and android. It returns a white square on android. See Gernot's introduction to iOS in the online manual.
#59
Code (glbasic) Select
// We need something like
POKE 53280, 0
im_loc% = VARPTR(my_foot_image_73052)
// same with VARSEG
POKE im_loc, 0xB787


Hi guys!
As the bear says, "sorry for the long paws!"... :D...  Eventually I'm back after a test of MEM2SPRITE. Good news: yes it speeds things up. I get a constant 2.2 fps at 1.1 GHz or so, and a 800x600 window -no double glazing, sorry.
But the constant fps is not normal, regardless whether a huge circle/ellipse or a tiny dot has been printed. It means that the plotting job to the array[] is very fast (only tested with no alpha, oh lazy me), but the rest is slow. Can DRAWSPRITE be so slow? Mmmh... I don't think so but need to check. If not, MEM2SPRITE would be the slow element (?...).
//*******
Anyway, I'd like to find a fast way to do it, for an app. Please can anyone help us? How can I find (in inline C) the pointer to the back buffer, so that I can plot directly into it instead of {into the array[], then MEM2SPRITE, then DRAWSPRITE, then SHOWSCREEN}?
If this question was tricky or cheeky, here is another option: 1) with CREATESCREEN I create a sprite to the right size. 2) Again, what is the pointer to that sprite? Pleeeeeeease!...
And thanks in advance.
#60
Same for me here. I tried the donut with only a blue ambient light, and it's clear that the lighting is next to the camera. The shadows shouldn't exist and they are way too dark.
Who knows a good reference/tutorial for the direct openGL calls like
glNewList(2, GL_COMPILE)
glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(   0,    0)
glVertex3f( -50,  80, 0)
glCallList(2)  ..........................etc? Thank you!

(quoted from testOGL on this forum)