Page 1 of 1

Another Pi4 GL working example - Lazarus

Posted: Thu Aug 15, 2019 8:07 am
by pik33
Install Lazarus from SVN (not apt-get install :( - the .deb package for Buster is damaged on RPi AND on PC too :( )

Code: Select all

svn checkout https://svn.freepascal.org/svn/lazarus/tags/lazarus_2_0_4
cd lazarus_2_0_4
make clean
make bigide
Run Lazarus
Open GL control example
Compile
Run

It simply works

As the example seems to be very old it seems to use the fixed pipeline - no hand-made shaders
But... it simply works :)

Update:

The new pipeline can be also used: I am now trying to get it working - now having the vertex shader compiled. As I have my own GL demo source I wrote for Ultibo now I am trying to move it here :)

Re: Another Pi4 GL working example - Lazarus

Posted: Fri Aug 16, 2019 2:46 am
by Gavinmc42
Strange, I did an apt-get install fpc then apt-get install lazarus and they just worked, weeks? ago.
Broken recently? Mine is Laz 2.0.0. fpc 3.0.4
Also it helps if you install freeGLUT.

I have compiled some OpenGL fpc examples that use glut, did not even need Lazarus.
Working through the fpc OpenGL tutorials, they work.
Some stuff does not, too many libs, GL, GLU, GLX, GLEW, Glut, FreeGlut, it get confusing at times

With Tim's shadertoy, mesa demos and geexlabs demos/shader/utils, seems to be lots of stuff that just works in C.
The trick seems to be to find examples that use what we have without being too old or too new.

I would love to have a GLSL compiler in Free Pascal, for obvious reasons :lol:
A Pascal version of freeGlut might be handy but making it a lib???.a and linking it might work too.
I know FPC and others langs like Go, Rust can use C files, I just don't know how yet.

You know Pi's are now Desktop Computers when stuff just works.

Re: Another Pi4 GL working example - Lazarus

Posted: Fri Aug 16, 2019 6:53 am
by pik33
Strange, I did an apt-get install fpc then apt-get install lazarus and they just worked, weeks? ago.
It seems to work until you want to add a component and rebuild Lazarus. Then it crash. It also crashed when I tried to compile the OpenGL example - cannot find openglcontrol or something related to it.

This is a Debian problem because it behaves exactly the same on a x86 Debian.

So I got Lazarus from svn, built id and all works as it should.

Then there are at least 2 working GL examples in there, both using old pipeline, which is much simpler (quads and no shaders)


To use a new pipeline you have to add glext unit. So uses gl, glu, glext.

Then you can compile a shader

Code: Select all

  r := glCreateShader(GL_VERTEX_SHADER);
  Source:=PChar(vertexSource);
  glShaderSource(r, 1, @Source, Nil);
  glCompileShader(r);  
 
So today I will try to move the example from ultibo-retro-gui with a sphere and a cube to the RPi4 line by line to have a Pascal/Lazarus/Linux template using OpenGL 2.1 with Lazarus

Re: Another Pi4 GL working example - Lazarus

Posted: Fri Aug 16, 2019 7:05 am
by Gavinmc42
Wireframe 20 had a bit on Livecoding
A mention of Kodelife - it just works :D
https://hexler.net/products/kodelife#_

Re: Another Pi4 GL working example - Lazarus

Posted: Sat Aug 17, 2019 6:55 pm
by pik33
I have now my cube-and-sphere demo working using Lazarus in Raspbian/X (without a text display yet)

Differences between RPi3/Ultibo/OpenGL ES 2 and RPi4/X/OpenGL 2.,1 encountered so far:

- no precision in shaders, they cannot compile with it
- bgra textures seem to be not supported. The texture has to be rgba although you can pass bgra to it

This works:

Code: Select all

  glTexImage2D(GL_TEXTURE_2D, 0, GL_rgba, 256, 1, 0, GL_bgra, GL_UNSIGNED_BYTE, @pallette);
This worked in RPi3/Ultibo and doesn't work with RPi4:

Code: Select all

  glTexImage2D(GL_TEXTURE_2D, 0, GL_bgra, 256, 1, 0, GL_bgra, GL_UNSIGNED_BYTE, @pallette);
- I don't know how to get alpha channel working with RPi4/X

Re: Another Pi4 GL working example - Lazarus

Posted: Sat Aug 17, 2019 7:05 pm
by PeterO
glTexImage2D(GL_TEXTURE_2D, 0, GL_bgraa, 256, 1, 0, GL_bgra, GL_UNSIGNED_BYTE, @pallette);

Is this a typo ? AH !!! You've fixed it :-)

PeterO

Re: Another Pi4 GL working example - Lazarus

Posted: Sat Aug 17, 2019 7:07 pm
by PeterO
I've chosen to target OpenGLES 3 for all my work as it's more up to date that openGL 2.1 !
PeterO

Re: Another Pi4 GL working example - Lazarus

Posted: Sun Aug 18, 2019 6:11 am
by pik33
This bgra stuff, without a typo, costed me a lot of time to debug, as the texture was black. So I played with the shader to switch this on, off, etc until I tried to switch to rgba and voila: what should be red was blue, but at least not black. So I tried to return to bgra with the second argument: works.

Still I don't know how to switch alpha channel on. This

Code: Select all

glEnable(GL_ALPHA_TEST);   
didn't do the trick: still no alpha.