Page 1 of 1

OpenGL learning phase #3 completed :)

Posted: Tue Dec 18, 2018 8:14 pm
by pik33
I was learning basics of OpenGL ES 2.0 while rewriting the Ultibo example code.

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.

The differences:
- 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

- this

Code: Select all

  EGLResult:=eglSurfaceAttrib(State.Display,State.Surface,EGL_SWAP_BEHAVIOR,EGL_BUFFER_PRESERVED);
  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.

Re: OpenGL learning phase #2 completed :)

Posted: Fri Dec 21, 2018 6:02 pm
by pik33
Phase #2 completed. OpenGL example in ultibo-retro-gui now displays 2 different moving textured object, where the texture source is a window canvas.

Edit: now the texture is dynamic and shows the changing window in the real time.

Re: OpenGL learning phase #2 completed :)

Posted: Sun Dec 23, 2018 3:20 am
by mark
pik33 wrote:Phase #2 completed. OpenGL example in ultibo-retro-gui now displays 2 different moving textured object, where the texture source is a window canvas.

Edit: now the texture is dynamic and shows the changing window in the real time.


This was the first subtree update and it worked without any problems.

https://github.com/markfirmware/ultibo- ... /v20181223 includes the texture demo. Select kernel "o" (Project1) and click gltest. Very impressive. Mark.

Re: OpenGL learning phase #2 completed :)

Posted: Mon Dec 24, 2018 7:06 pm
by pik33
Phase #2a completed - a textured sphere. That was hard. I also cleaned up the main gl redraw code deleting all unneeded stuff from there and removed the colors of vertices: I don't need them any more as I have textures.

Now goto phase #3: normals and lighting.

Re: OpenGL learning phase #3 completed :)

Posted: Fri Dec 28, 2018 7:35 pm
by pik33
Phase #3 completed: objects are now lighted with diffuse, specular and ambient light.

Learning OpenGL ES at the basic level completed :)

Now, the next stage: I need some tricks, such as direct access to textures and HVS objects. This will open some possibilities. Audio filter using shaders?

Re: OpenGL learning phase #3 completed :)

Posted: Sat Dec 29, 2018 8:52 am
by pik33
I got an access to the texture memory. Its organization is as strange as it can be

For 8-bit "luminance" texture, the basic unit is 32x32 pixel square. Its 1024 pixels are addressed like this: yyxxxyyyxx.

Then these squares are placed in the texture using something like gray code or hilbert curve (it is actually NOT a hilbert curve and not a gray code, yet to be discovered what it exactly is)

Why they decided to do this in such a strange way? This explains why uploading the texture is so slow: it cannot be done using fast memory copy.

Re: OpenGL learning phase #3 completed :)

Posted: Thu Jan 03, 2019 6:03 pm
by pik33
This is not yyxxxyyyxx, this is yyxxyyyxxx :)
I have now first putpixel procedure which writes pixels directly to this strange structure. Hardcoded 256x256 as it is now, will be rewritten in asm for bigger textures.

Code: Select all

procedure TTexturebitmap.putpixel(x,y,color:byte); // test procedure

var a,b,c:byte;

begin
a:=(x  and %00000111)+((y and %00000111) shl 3)+(x and %00011000) shl 3;
b:=((y and %00011000) shr 3)+(y and %11000000);
b+=((x and %00100000) xor (y and %00100000)) shr 3;
c:=(x and %11100000) shr 2;
if (y and %01000000) >0 then c:=not c;
b+=(c and %00111000);
poke(address+a+256*b,color);
end;


address is a texture address in the gpu memory