Android Tutorial Introduction to the libGDX library

ilan

Expert
Licensed User
Longtime User
hi,

is it possible to set a lgScn2DLabel Alignment to top and right?
i can set only 1 option but i need TOP and RIGHT.

regards, ilan
 

wonder

Expert
Licensed User
Longtime User
B4X:
'Align RIGHT (given Left and Width):
x = (Parent.Left + Parent.Width) - Child.Width

'Example: Screen (parent) / Label (child) align RIGHT
x = 100%x - Label.Width

B4X:
'Align RIGHT (given CenterX and Width):
x = (Parent.cX + Parent.Width / 2) - Child.Width

For TOP it's the same philosophy.
 

wonder

Expert
Licensed User
Longtime User
My turn now.

I have no way to test this until tomorrow, so that's why I'm asking now:
Say I have stuff being rendered into a FrameBuffer.
What would be the fastest way to send the rendered frame across a network?

B4X:
Dim Pixmap As lgPixmap = FBO.GetDefaultFrameBufferPixmap(0, 0, lGdx.Graphics.Width, lGdx.Graphics.Height, True)
Dim PixmapIO As lgPixmapIO
PixmapIO.WritePNG(lGdx.Files.external("screenshot.png"), Pixmap)
Pixmap.dispose
'Send the PNG file to IP xxx.xxx.xxx.xxx
OR
B4X:
Dim raf As RandomAccessFile
raf.Initialize(...) --> point it somehow to an IP address
Dim bytes() As Byte

bytes = FBO.GetDefaultFrameBufferPixels(0, 0, FBO.Width, FBO.Height, False)
raf.WriteBytes(bytes, 0, bytes.Length, 0) 'Not sure about the syntax here

'This solution looks obviously faster!!!
OR
B4X:
'*Your solution here*

Note: I don't care how are the bytes written (given integrity is maintained), PNG or not, flipped or not, I just want the fastest way to "get the bytes out".
 

ilan

Expert
Licensed User
Longtime User

a lgscn2dlabel has an option to set alignment

B4X:
lbl.SetAlignment2(lbl.ALIGN_Center)

or

B4X:
lbl.SetAlignment2(lbl.ALIGN_Right)

the problem is that if i set it to the right it is centered (on the height) and i want it on the top right corner

if i set first right and then top it takes only the last setting.
 

inakigarm

Well-Known Member
Licensed User
Longtime User

ilan

Expert
Licensed User
Longtime User
And what's the result of SetAlignment(ALIGN_TOP, ALIGN_RIGHT)?

i tried it but the second argument is only if you have multi lines so i did not get the result.


thanx i will try this
 

ilan

Expert
Licensed User
Longtime User

Informatix

Expert
Licensed User
Longtime User
What do you want to achieve? Transmit a snapshot through the network? Between apps using libGDX?
 

ilan

Expert
Licensed User
Longtime User
And did you try to add the constants? You did not answer.

sorry but i dont understand what you mean with constants

i tried:
B4X:
    menushopprices(2).SetAlignment2(menushopprices(2).ALIGN_Top)
    menushopprices(2).SetAlignment2(menushopprices(2).ALIGN_Right)

but only the last command is performed (.ALIGN_Right)

then i tried:
B4X:
    menushopprices(2).SetAlignment(menushopprices(2).ALIGN_Top, menushopprices(2).ALIGN_Right)

result is only on top (and centered!) because second argument is for the lines alignment
 

wonder

Expert
Licensed User
Longtime User
What do you want to achieve? Transmit a snapshot through the network? Between apps using libGDX?
I want to build a LibGDX based screen-casting solution [Android ---> PC].
That's why I don't care how the bytes are to be written. The PC "decoder" will be fast enough to decode and render on screen (B4J Canvas or C++ OpenGL).

Note: The frameBuffer doesn't necessarily have to be rendered on the Android screen.
For example, just a black screen with text "Casting in progress..."
 

ilan

Expert
Licensed User
Longtime User
A constant is a value that cannot change

yes this is something i know

but i dont understand how you want me to set the constant

ALIGN_TOP+ALIGN_RIGHT when i write something like this i get unknown member

anyway as @inakigarm suggested, setting the value 18 works as expected.
 

Informatix

Expert
Licensed User
Longtime User
I want to build a LibGDX based screen-casting solution [Android ---> PC].
That's why I don't care how the bytes are to be written. The PC "decoder" will be fast enough to decode and render on screen (B4J Canvas or C++ OpenGL).
Transmitting the array of bytes (Pixmap.Pixels) in a zipped format is probably faster than creating and transmitting a PNG file but you have to be able to recreate the image from it on the PC side.
Note that the FastIO library from ProBundle is faster than the RandomAccessFile library.
 

Informatix

Expert
Licensed User
Longtime User
yes this is something i know

but i dont understand how you want me to set the constant

ALIGN_TOP+ALIGN_RIGHT when i write something like this i get unknown member

anyway as @inakigarm suggested, setting the value 18 works as expected.
According to your code above, that should be
menushopprices(2).ALIGN_Top+menushopprices(2).ALIGN_Right
That's more obvious than 18.
In fact, Alignment should work exactly like Gravity.
 

wonder

Expert
Licensed User
Longtime User
Glad I bought the ProBundle...

Now, why do you say Pixmap.Pixels and not FBO.GetDefaultFrameBufferPixels? They're both of type Byte().
 

Informatix

Expert
Licensed User
Longtime User
Glad I bought the ProBundle...

Now, why do you say Pixmap.Pixels and not FBO.GetDefaultFrameBufferPixels? They're both of type Byte().
There's not a great difference between them. GetDefaultFrameBufferPixels is a helper function that I added to LibGDX. Here's its code:
B4X:
    public static byte[] GetDefaultFrameBufferPixels (int X, int Y, int Width, int Height, boolean FlipY)
    {
        Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);
        final ByteBuffer pixels = BufferUtils.newByteBuffer(Width * Height * 4);
        Gdx.gl.glReadPixels(X, Y, Width, Height, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);
        final int numBytes = Width * Height * 4;
        byte[] lines = new byte[numBytes];
        if (FlipY) {
            final int numBytesPerLine = Width * 4;
            for (int i = 0; i < Height; i++) {
                pixels.position((Height - i - 1) * numBytesPerLine);
                pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
            }
        } else {
            pixels.clear();
            pixels.get(lines);
        }
        return lines;
    }
 

wonder

Expert
Licensed User
Longtime User
Since I'm never going to use FlipY, I could remove it to make it lighter:
B4X:
public static byte[] GetDefaultFrameBufferPixels (int X, int Y, int Width, int Height)
{
    Gdx.gl.glPixelStorei(GL20.GL_PACK_ALIGNMENT, 1);
    final ByteBuffer pixels = BufferUtils.newByteBuffer(Width * Height * 4);
    Gdx.gl.glReadPixels(X, Y, Width, Height, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixels);
    final int numBytes = Width * Height * 4;
    byte[] lines = new byte[numBytes];
    pixels.clear();
    pixels.get(lines);
    return lines;
}
But... why return "lines" instead of "pixels"? How is "lines" affected by pixels.get(lines)?
 

ilan

Expert
Licensed User
Longtime User
According to your code above, that should be
menushopprices(2).ALIGN_Top+menushopprices(2).ALIGN_Right
That's more obvious than 18.
In fact, Alignment should work exactly like Gravity.

ofcourse, you are rigt @Informatix !!

the SetAlignment2 of an label expect an int
and .ALIGN_Top = 2
and .ALIGN_Right = 16
so menushopprices(3).ALIGN_Top+menushopprices(3).ALIGN_Right = 18

did not thought about that option, thank you, i learned something new today
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…