BASIC

Author Topic: Generic Questions  (Read 8836 times)

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Generic Questions
« on: 2013-Jan-26 »
Hi  to all people of the forums!
I do not read the forum for long time and I had a few questions.

1) GLBasic support ADS for Android? and iPhone?
2) Is implemented WIFI for Andoid? and iPhone?
3) and Bluetooth? (Android and iPhone)

Thanks for the replies!  :good:

Offline hardyx

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 491
    • View Profile
Re: Generic Questions
« Reply #1 on: 2013-Jan-26 »
All you are asking must be implemented by the programmer.
The language allows inline C++ code, and writting objetive-c modules in iPhone.
There is Ads library and Bluetooth library for iPhone in the forum.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: Generic Questions
« Reply #2 on: 2013-Jan-26 »
Hmm im not sure how he means his questions. With native GLB you cant establish a wifi connection, but if the user established a connection, you can use it with GLB NET_ and SOCK_ commands and program networking games.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Re: Generic Questions
« Reply #3 on: 2013-Jan-26 »
I comme here every day, and now I know about the BT for iphone...  :O
Thanks hardyx... but it's you know if it's possible to connect an Arduno whit the Bluetooth of iPhone?¿, I think in the new model can be done, because the bluetooth it's the new SmartBluetooth, protocol or model, I'm not sure really what it's.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10708
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Generic Questions
« Reply #4 on: 2013-Jan-27 »
No. Apple dors not allow to program bluetooth other than the gamechannel connection. You can get an SDK for a high price. Android should be posdible. Wifi is no problem.

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Generic Questions
« Reply #5 on: 2013-Jan-27 »
Thanks for the reply!  :good:

Another question:
how to read with the command sprite2mem, the colors palette of a sprite?

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: Generic Questions
« Reply #6 on: 2013-Jan-27 »
The SPRITE2MEM reference in the help is pretty useful for that. You will need to sequentially traverse through the pixels to pick up their individual colors. a=alpha. r,g,b are self explanatory. x=sprite column, y=sprite row. width=width of sprite.

Quote
//SPRITE2MEM()
ok = SPRITE2MEM(pixels%[], num%)

LOCAL r%,g%,b%,a%
LOCAL abgr% = pixels%[x + y*width]
r = bAND(abgr, 0xff)
g = bAND(ASR(abgr,8), 0xff)
b = bAND(ASR(abgr,16), 0xff)
a = bAND(ASR(abgr,24), 0xff)
« Last Edit: 2013-Jan-27 by backspace »
I came, I saw, I coded.

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Generic Questions
« Reply #7 on: 2013-Jan-30 »
I read the guide!  :good:

But I'm not sure to read the pixels in the correct way:

Code: GLBasic [Select]
   REDIM pixels%[width*height]


   SPRITE2MEM(pixels%[], num%)

        LOCAL abgr%

    test$ = "test1.txt"
        OPENFILE(1, test$, FALSE)

FOR y = 0 TO (height) - 1
        FOR x = 0 TO (width) - 1

                 abgr% = pixels%[y+x]
       
                                WRITELINE  1, abgr%

   NEXT
  NEXT

 

is that correct?

MrTAToad

  • Guest
Re: Generic Questions
« Reply #8 on: 2013-Jan-30 »
No - basically you are just reading one line.  You need something like :

Code: GLBasic [Select]
abgr%=pixels(x+(y*640)]

where 640 should be replaced with your actual screen width

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Generic Questions
« Reply #9 on: 2013-Jan-31 »
mmmm ... I dont not understand ...
you can explain it with an example?

Thanks  :booze:

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: Generic Questions
« Reply #10 on: 2013-Jan-31 »
Haven't read the thread fully but I'm guessing the problem is that you don't read the array right. Memory is only one dimension, it's one long line. Every line on the screen is a small section on this memory area. To be able to use X and Y to locate a pixel in this memory you need to multiply Y with the width of the screen. Then add X to get the horizontal position. This gives you the memory address you need to get to the right pixel

Formula becomes:
memory_position = (Y * width_of_screen) + X

First line, fifth pixel will be (0 * 640) + 4 = 4
Second line, fifth pixel will be (1 * 640) + 4 = 644

Look up the position 644 in the array and you get the right pixel
array[644] = <your color>
« Last Edit: 2013-Jan-31 by Moru »

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Generic Questions
« Reply #11 on: 2013-Jan-31 »

I tried, but I get error on the size of the array:


Code: GLBasic [Select]
   REDIM pixels%[width*height]

   SPRITE2MEM(pixels%[], num%)

        LOCAL abgr%

    test$ = "test1.txt"
        OPENFILE(1, test$, FALSE)

        FOR y = 0 TO (height) - 1
                FOR x = 0 TO (width) - 1
       
                         abgr% = pixels%[x + (y*480)] // 480 width of screen
                                        WRITELINE  1, abgr% + "\n"
           NEXT
        NEXT


 

MrTAToad

  • Guest
Re: Generic Questions
« Reply #12 on: 2013-Jan-31 »
Sorry - it should be the width of the sprite, and not the screen.

Offline Kyo

  • Dr. Type
  • ****
  • Posts: 350
    • View Profile
Re: Generic Questions
« Reply #13 on: 2013-Jan-31 »
Ok now it works,  :booze:
 but it is very very slow to read a sprite 200x200 px.

Code: GLBasic [Select]
FOR y = 0 TO (height) - 1
                FOR x = 0 TO (width) - 1
       
                         abgr% = pixels%[x + (y*width)]

           NEXT
        NEXT
 
How can I optimize the reading?

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: Generic Questions
« Reply #14 on: 2013-Jan-31 »
Should be no task for a modern computer at all, they are fast enough to do this. But some tiny improvements:
Code: GLBasic [Select]
        DEC height
        DEC width
        FOR y% = 0 TO height
                FOR x% = 0 TO width
       
                        abgr% = pixels%[x + (y*width)]

                NEXT
        NEXT
And also make sure, that width and height are integers. And if you dont need to do this every loop, dont do it! Just do it as often as you need, it, if you need it just one time, do it before the main loop.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64