The result is gltest2 unit in the ultibo-retro-gui repository. You can double click gltest there.
The unit can be used in the place of original example unit in a pure Ultibo environment. In the main example unit replace GL unit with the gltest2.pas, remove 'uses retromalina' from it and add xres,yres variables instead (your monitor resolution) and change KeyPressed to ConsoleKeyPressed (also readkey to ConsoleReadKe) Call gltest2_start; to see the cube.
Maybe I will make a pure Ultibo example out of it in the way described above.
- I replaced the matrix related functions with overloaded operators
- there is error in the frustum calculation. The near is set at -2, but has to be >0 or the functions will not compute the matrix. It returns identity matrix instead. Then there is a line of code which scales it to the aspect ratio. It is unnecessary if the frustum was properly calculated.In my code near is 1, far is 6 and the cube is translated 4 units in Z axis. This gives a proper perspective viewed cube.
- to do translating I added a translating matrix
- I also addded an orthogonal view matrix
Code: Select all
if EGLResult = EGL_FALSE then Exit;
doesn't do anything useful because there is glclear at every frame so there is nothing to preserve. It destroys performance instead, adding unnecessary memory copy.(5 ms of 16 available wasted at full HD)
The copy is performed because this is a double buffered environment.
To make the code shorter I removed any error checking while initializing egl and dispmanx. This can be restored later, without it the code is easier to understand and that was my goal for the phase #1.
Starting the phase #2: understanding texturing in GL ES 2.0.