Tricks and hints

General discussion about anything related to Ultibo.
pik33
Posts: 857
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Tricks and hints

Postby pik33 » Sat Dec 15, 2018 8:18 am

I started the topic for unusual things you can find in your RPi which can be useful and are hard to find.

---------------
1. Do you want a transparent framebuffer and setting attribute in Ultibo doesn't work?

In config.txt

framebuffer_ignore_alpha=1;

You can also add

framebuffer_depth=32;

then in Ultibo framebuffer creating code mode=0 and your framebuffer is transparent now. (and you can see a black screen until you put something non-zero to alpha channel in your colors)

-------------

2. What can be a transparent framebuffer for?

You can display OpenGL (or OpenMax or OpenVG or anything) screen under it

Normally it is over the framebuffer, so how to put it under?

The answer is: the framebuffer is an DispmanX layer #-128

Set your OpenGL layer at lower number (-129 for example) and it will go under your framebuffer.

------------

3. Have your OpenGL picture cover the full screen and have it to stay forever at the place you put it at the start?

Of course, not.

You can declare any destination rectangle for your openGL layer and you can change it at the runtime

You simply change your layer parameters in the main rendering loop before calling opengl calls

Code: Select all

  DispmanUpdate:=vc_dispmanx_update_start(10);
  vc_dispmanx_rect_set(@Dst_Rect,frames mod 540,frames mod 540,960,540);
  vc_dispmanx_rect_set(@src_Rect,0,0,960 shl 16,540 shl 16);
  vc_dispmanx_element_change_attributes(DispmanUpdate,element,12,0,0,@dst_rect,@src_rect,0,0);
  vc_dispmanx_update_submit(DispmanUpdate,nil,0);   


The example moves OpenGL window diagonal, one pixel every frame and restarts from 0 every 540 frames - the code is written for fullhd screen and the opengl rectangle was set at 960x540
Beware: don't allow your DispmanX layer to reach under your screen! or you will see a strange behavior

Use update_submit without sync. The sync will be done by eglswapbuffers.

-------------
pik33
Posts: 857
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Tricks and hints

Postby pik33 » Sat Dec 15, 2018 10:20 am

Dispmanx element change flags bits. Very hard to find.

bit 0 layer, bit 1 opacity, bit 2 dest rect, bit 3 src rect, bit 4 mask, bit 5 transform
Hans
Posts: 14
Joined: Mon Feb 06, 2017 7:28 am
Location: Europe

Re: Tricks and hints

Postby Hans » Mon Dec 17, 2018 10:04 am

Hi, thanks for these pointers, very relevant to me. Perhaps you might want to edit the title to reflect that you're actually providing GL info, so that it can be found in searches later on...
Gavinmc42
Posts: 1586
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: Tricks and hints

Postby Gavinmc42 » Tue Dec 18, 2018 12:06 am

Yep rename OpenGLES, OpenMax, EGL, OpenVG, DispManX tricks.
But now that's there a search will find this again.

Some of this is not obvious at all.
pik33
Posts: 857
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Tricks and hints

Postby pik33 » Wed Dec 19, 2018 9:29 am

To enable alpha in egl/opengl:

(1) in DispmanX initialization: Alpha.flags:=DISPMANX_FLAGS_ALPHA_FROM_SOURCE;

(2) in EGL initialization:

- make ConfigAttributes table 2 position bigger: ConfigAttributes:array[0..12] of EGLint; instead of 10 in the Ultibo OpenGL example

- then

Code: Select all

ConfigAttributes[10]:=EGL_ALPHA_SIZE;
ConfigAttributes[11]:=8;
ConfigAttributes[12]:=EGL_NONE;


- your screen should be transparent now: glClearColor(0.0,0.0,0.0,0.0);

- and of course your object colors should have an alpha value as 4th element. 0=transparent, 1=opaque;

and your cube now rotates over your desktop.
pik33
Posts: 857
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Tricks and hints

Postby pik33 » Fri Jan 04, 2019 6:41 pm

A neat trick from Atari800 emulator

If you need only 256 color screen, you can tell OpenGL your texture is 8-bit luminance only. Such texture will use less memory (checked: it is stored as 8-bit values also in the texture GPU memory) and can be uploaded faster.
Then use a second texture, RGBA in this case, 256x1 pixel - it will keep your palette.
In a pixel shader get a value from your "luminance" texture and use it as an index to the palette texture and voila: you have 8-bit paletted object in OpenGL

Now if you use lighting on it, it is no more 8-bit :)

This maakes another trick possible

Max texture size is 2048x2048, regarless of its color depth. So... use RGBA texture for 8-bit bitmaps and with a few lines added to shader, you can use every color component (r,g,b,a) as an index to the palette. The result: the texture bitmap is now 8192x2048.
pik33
Posts: 857
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Tricks and hints

Postby pik33 » Thu Jan 10, 2019 9:37 am

GLSL looks like C but it is not C. The GL ES version used in RPi, called ESSL 1.0 is even more restricted.

You can use arrays. You cannot index your array with a variable. The exception is for-loop variable, but then the exit condition has also to be constant.

Avoid if..else or you will slow the shader down, even 10x Instead of ifs, you can use strange tricks described here http://theorangeduck.com/page/avoiding- ... nditionals

Float precision declarations - lowp, mediump, highp - have no real effects, it seems to be always highp.
Gavinmc42
Posts: 1586
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: Tricks and hints

Postby Gavinmc42 » Thu Jan 10, 2019 12:04 pm

GLSL/ESSL, thanks, saves me wasting too much time learning the wrong bits of GLSL.
I need a list of OpenGL similar commands that are in OpenGLES and now GLSL to ESSL.

WebGL uses OpenGLES and ESSL
This looks useful info.
http://www.pp4s.co.uk/main/tu-sms-graphics-3d.html
Wow wonder if that demo can be ported.'

Learning WebGL will be useful?
pik33
Posts: 857
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Tricks and hints

Postby pik33 » Thu Jan 10, 2019 6:36 pm

I have already learned all these topics and something more: creating a sphere, draw graphic primitives directly on textures, use 3-component (ambient, diffuse, specular) lighting and using 8-bit textures with palette :) The 8-bit textures allows me to use 8192x2048 texture on RPi which then opened the way to make OpenGL ES powered window manager in 3D space. It is now work in progress.

These demos can be ported, but not with a lot of changes in their Pascal code. We have EGL and DispmanX here; we have no windowing system so no such thing as Form1.canvas etc, and I don't know what is TGL. You have to write code without these things.

You can look at this unit https://github.com/pik33/ultibo_retro_g ... ltest2.pas although it is the unit on which I am experimenting so it changes a lot with every commit and is not always usable :)
mark
Posts: 1325
Joined: Mon Oct 03, 2016 2:12 am
Location: Indianapolis, US

Re: Tricks and hints

Postby mark » Fri Jan 11, 2019 8:17 pm

https://github.com/markfirmware/ultibo- ... /v20190111

includes your sphere and cube. On two instances of execution, both the sphere and cube were black without the colorful texture.

Mark

Return to “Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests