Generic Questions

Previous topic - Next topic

Kyo

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:

hardyx

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.

kanonet

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

mentalthink

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.

Kitty Hello

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.

Kyo

Thanks for the reply!  :good:

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

backspace

#6
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)
I came, I saw, I coded.

Kyo

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

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

Kyo

mmmm ... I dont not understand ...
you can explain it with an example?

Thanks  :booze:

Moru

#10
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>

Kyo


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

Sorry - it should be the width of the sprite, and not the screen.

Kyo

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?

kanonet

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