Git Product home page Git Product logo

rpi-opengl-without-x's Introduction

Raspberry Pi OpenGL ES 2 without an X server (using EGL)

Have you ever wanted to render things with headless (no screen) Raspberry Pi? Then this is something you might be interested in!

The following file triangle.c contains an example that renders a triangle and saves it into a output.raw file. The example uses EGL to create a pixel buffer as a surface. Normally, when using X server, you would create a window surface, but in here we do not do that at all. This example also uses OpenGL ES 2 to setup a very simple shader to render a triangle.

The triangle.c contains comments which should explain you all the necessary parts. Please note that this example will not teach you fundamentals of OpenGL! The purpose of this file is solely to demonstrate creating an OpenGL ES 2 context and getting the raw pixel output without using any virtual Linux framebuffers or physical screen (no X server).

Which Raspberry Pi works?

  • Raspberry Pi 1 (tested and works)
  • Raspberry Pi 2 (tested and works)
  • Raspberry Pi 3 (tested and works)
  • Raspberry Pi 4 (tested and works, but won't work in headless mode, you need a HDMI output works just fine in the headless mode, no longer true, see issue #11)

Raspberry Pi 1,2,3

For the Raspberry Pi 4 instructions see the next section

What do I need?

You need a GCC compiler, EGL, and GLES libraries. If you are using the latest Raspbian distro, all those are already located on the image, no extra apt-get needed. You can check if you have the GCC installed by executing gcc --version. You can also check if the GLES and EGL are installed by executing ls /opt/vc/lib which should list libbrcmEGL.so and libbrcmGLESv2.so. They are all already included in the Jessie/Stretch/Buster Raspbian! If you don't have libbrcmEGL.so, you will have to use the libEGL.so instead, which is located in the same folder.

The problem of mesa apt package

The following packages mesa-common-dev and mesa-utils do NOT work and instead they may break EGL on your OS. The libraries installed through any of the mesa packages will install incompatible version of the EGL, most likely into the /lib/arm-linux-gnueabihf folder. Don't use these! Use the ones provided by the official Raspbian OS image in the /opt/vc/lib folder!

How do I try it?

Copy or download the triangle.c file onto your Raspberry Pi. Use the following commands to compile the source file:

gcc -c triangle.c -o triangle.o -I/opt/vc/include
gcc -o triangle triangle.o -lbrcmEGL -lbrcmGLESv2 -L/opt/vc/lib

To run the executable, type the following:

./triangle

You should see the following output:

Initialized EGL version: 1.4
GL Viewport size: 800x600

At the same time, a new file should be created: output.raw. This file contains raw 800x600 RGB pixels. You can use Photoshop or any other software to import and view this file. You should be able to see the following purple triangle. Please note that the image is mirrored vertically as the pixel coordinates in OpenGL start from the bottom, not from the top. Example of the image:

Screenshot of a purple triangle

Raspberry Pi 4

Raspberry Pi 4, at the moment of writing this, has no full KMS driver, because the GPU is different from the previous ones. Instead of using the vc libraries, you will need to use the DRM/GBM.

What do I need?

You need a GCC compiler, GDM, EGL, and GLES libraries. The GCC compiler is already included in the Raspbian image. To install the other libraries, simply run:

sudo apt-get install libegl1-mesa-dev libgbm-dev libgles2-mesa-dev

You will also need to connect your Raspberry Pi to a screen. The boot config from /boot/config.txt that I have used for my tests, if it helps in any way:

dtoverlay=vc4-fkms-v3d
max_framebuffers=2
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=81

How do I try it?

Copy or download the triangle_rpi4.c file onto your Raspberry Pi. Using any terminal, write the following commands to compile the source file:

gcc -o triangle_rpi4 triangle_rpi4.c -ldrm -lgbm -lEGL -lGLESv2 -I/usr/include/libdrm -I/usr/include/GLES2

To run the executable, type the following:

./triangle_rpi4

You should see the following output:

resolution: 1366x768
Initialized EGL version: 1.4
GL Viewport size: 1366x768

At the same time, a new file should be created: output.raw. This file contains raw 1366x768 RGB pixels. You can use Photoshop or any other software to import and view this file. You should be able to see the following purple triangle. Please note that the image is mirrored vertically as the pixel coordinates in OpenGL start from the bottom, not from the top. Example of the image:

Screenshot of a purple triangle

Troubleshooting and Questions

Failed to get EGL version! Error:

Your EGL might be faulty! Make sure you are using the libraries provided by Raspbian and not the ones installed through apt-get or other package managers. Use the ones in the /opt/vc/lib folder. If that does not work, try reinstalling your Raspberry Pi OS.

I get "Error! The glViewport/glGetIntegerv are not working! EGL might be faulty!" What should I do?

Same as above.

How do I change the pixelbuffer resolution?

Find pbufferAttribs and change EGL_WIDTH and EGL_HEIGHT.

I get "undefined reference" on some gl functions!

Some GL functions may not come from GLES library. You may need to get GL1 library by executing sudo apt-get install libgl1-mesa-dev and then simply add: -lGL flag to the linker, so you get: gcc -o triangle triangle.o -lbrcmEGL -lbrcmGLESv2 -lGL -L/opt/vc/lib

How do I change the buffer sample size or the depth buffer size or the stencil size?

Find configAttribs at the top of the triangle.c file and modify the attributes you need. All config attributes are located here https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglChooseConfig.xhtml

Can I use glBegin() and glEnd()?

You should not, but you can. However, it seems that OpenGL ES does not like that and nothing will be rendered. For this you will need to link the GL library as well. Simply, add -lGL to the gcc command.

Failed to add service - already in use?

As mentioned in this issue, you have to remove both vc4-kms-v3d and vc4-fkms-v3d from R-Pi config. Also relevant discussion here: https://stackoverflow.com/questions/40490113/eglfs-on-raspberry2-failed-to-add-service-already-in-use. If you are using Raspberry Pi 4 (the triangle_rpi4.c) it might happen sometimes. I could not fully figure it out, but it might be due to incorrect EGL or DRM/GBM cleanup in the code. I say "incorrect", but I don't know where.

License

Do whatever you want.

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>

rpi-opengl-without-x's People

Contributors

matusnovak avatar tombsar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rpi-opengl-without-x's Issues

Compiling Error on RPI 3

Hey,

please help me with this fault :)
I have done everything like in the description.

I get this error if i want to compile it on my RPI 3:

pi@raspberrypi:~ $ sudo gcc -c triangle.c -o triangle.o -I/opt/vc/include
triangle.c:7:1: error: expected identifier or ‘(’ before ‘<’ token

^
triangle.c:51:52: error: stray ‘\302’ in program

<title>rpi-opengl-without-x/triangle.c at master ?? matusnovak/rpi-opengl-without-x · GitHub</title> ^ triangle.c:51:53: error: stray ‘\267’ in program <title>rpi-opengl-without-x/triangle.c at master ?? matusnovak/rpi-opengl-without-x · GitHub</title> ^ triangle.c:51:87: error: stray ‘\302’ in program l-without-x/triangle.c at master · matusnovak/rpi-opengl-without-x ?? GitHub</title> ^

triangle.c:51:88: error: stray ‘\267’ in program
-without-x/triangle.c at master · matusnovak/rpi-opengl-without-x ?? GitHub</title>
^

triangle.c:91:44: warning: unknown escape sequence: '&'

triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:91:44: warning: unknown escape sequence: '&'
triangle.c:169:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘<’ token

^
triangle.c:176:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘<’ token

^
triangle.c:202:275: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:204:251: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:205:262: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:206:268: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:207:264: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:208:264: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:209:271: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:210:285: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:211:272: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:215:323: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:216:339: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:239:307: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:244:299: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:245:316: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:246:305: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:247:327: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:248:340: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:253:279: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:254:317: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:255:334: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:256:340: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:257:349: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:277:270: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:280:333: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:281:343: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:285:343: error: expected identifier or ‘(’ before ‘<’ token
link-symbol float-right text-normal color-text-tertiary pr-3">→
^

triangle.c:303:10: warning: missing terminating ' character


^
triangle.c:303:10: error: missing terminating ' character

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triangle.c:350:75: error: stray ‘\342’ in program
???
^

triangle.c:350:76: error: stray ‘\206’ in program
???
^

triangle.c:350:77: error: stray ‘\265’ in program
??
^

triangle.c:355:56: error: stray ‘\342’ in program
???
^
triangle.c:355:57: error: stray ‘\206’ in program
???
^
triangle.c:355:58: error: stray ‘\265’ in program
??
^
triangle.c:391:75: error: stray ‘\342’ in program
???
^

triangle.c:391:76: error: stray ‘\206’ in program
???
^

triangle.c:391:77: error: stray ‘\265’ in program
??
^

triangle.c:396:56: error: stray ‘\342’ in program
???
^
triangle.c:396:57: error: stray ‘\206’ in program
???
^
triangle.c:396:58: error: stray ‘\265’ in program
??
^
triangle.c:423:75: error: stray ‘\342’ in program
???
^

triangle.c:423:76: error: stray ‘\206’ in program
???
^

triangle.c:423:77: error: stray ‘\265’ in program
??
^

triangle.c:428:56: error: stray ‘\342’ in program
???
^
triangle.c:428:57: error: stray ‘\206’ in program
???
^
triangle.c:428:58: error: stray ‘\265’ in program
??
^
triangle.c:455:75: error: stray ‘\342’ in program
???
^

triangle.c:455:76: error: stray ‘\206’ in program
???
^

triangle.c:455:77: error: stray ‘\265’ in program
??
^

triangle.c:460:56: error: stray ‘\342’ in program
???
^
triangle.c:460:57: error: stray ‘\206’ in program
???
^
triangle.c:460:58: error: stray ‘\265’ in program
??
^
triangle.c:519:25: error: expected identifier or ‘(’ before ‘<’ token

{{ message }}

^
triangle.c:712:50: error: invalid suffix "f68d0d9ae15f0b54b3bdb6b92e35971d3c6d6527745ee6e71ee3fb1" on floating constant

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triangle.c:758:25: warning: missing terminating " character
data-action="
^
triangle.c:758:25: error: missing terminating " character
triangle.c:759:41: error: stray ‘#’ in program
input-entered:ref-selector#inputEntered
^
triangle.c:760:40: error: stray ‘#’ in program
tab-selected:ref-selector#tabSelected
^
triangle.c:761:38: error: stray ‘#’ in program
focus-list:ref-selector#focusFirstListMember
^
triangle.c:762:13: warning: missing terminating " character
"
^
triangle.c:762:13: error: missing terminating " character
triangle.c:775:80: warning: missing terminating ' character

                                                                 ^

triangle.c:775:80: error: missing terminating ' character

                                                                 ^~~~~~~~~~~~~~~~~~~~

triangle.c:788:109: error: expected identifier or ‘(’ before ‘<’ token
css-truncate css-truncate-overflow {{ isFilteringClass }}">{{ refName }}
^

triangle.c:800:25: warning: missing terminating " character
data-action="
^
triangle.c:800:25: error: missing terminating " character
triangle.c:801:41: error: stray ‘#’ in program
input-entered:ref-selector#inputEntered
^
triangle.c:802:40: error: stray ‘#’ in program
tab-selected:ref-selector#tabSelected
^
triangle.c:803:38: error: stray ‘#’ in program
focus-list:ref-selector#focusFirstListMember
^
triangle.c:804:13: warning: missing terminating " character
"
^
triangle.c:804:13: error: missing terminating " character
triangle.c:820:109: error: expected identifier or ‘(’ before ‘<’ token
css-truncate css-truncate-overflow {{ isFilteringClass }}">{{ refName }}
^

triangle.c:902:43: warning: missing terminating " character
<a data-pjax="true" title="Added Raspberry Pi 4 example
^
triangle.c:902:43: error: missing terminating " character
<a data-pjax="true" title="Added Raspberry Pi 4 example
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triangle.c:904:133: warning: missing terminating " character
rpi-opengl-without-x/commit/c04a155601184c0bf14901dca2f89d6a96cac519">Added Raspberry Pi 4 example
^

triangle.c:904:133: error: missing terminating " character
rpi-opengl-without-x/commit/c04a155601184c0bf14901dca2f89d6a96cac519">Added Raspberry Pi 4 example
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

triangle.c:909:111: error: expected identifier or ‘(’ before ‘<’ token
s="ellipsis-expander js-details-target" aria-expanded="false">…
^

triangle.c:973:16: warning: missing terminating " character
<div class="Box mt-3 position-relative
^
triangle.c:973:16: error: missing terminating " character
<div class="Box mt-3 position-relative
^~~~~~~~~~~~~~~~~~~~~~~~~~~
triangle.c:974:7: warning: missing terminating " character
">
^
triangle.c:974:7: error: missing terminating " character
">
^~
triangle.c:1019:69: error: stray ‘#’ in program
#include <EGL/egl.h>
^
triangle.c:1019:148: error: expected identifier or ‘(’ before ‘<’ token
s="pl-k">include <EGL/egl.h>
^

triangle.c:1019:189: error: expected identifier or ‘(’ before ‘<’ token
"><EGL/egl.h>
^

triangle.c:1023:69: error: stray ‘#’ in program
#include <GLES2/gl2.h>
^
triangle.c:1023:148: error: expected identifier or ‘(’ before ‘<’ token
s="pl-k">include <GLES2/gl2.h>
^

triangle.c:1023:191: error: expected identifier or ‘(’ before ‘<’ token
<GLES2/gl2.h>
^

triangle.c:1027:69: error: stray ‘#’ in program
#include <stdio.h>
^
triangle.c:1027:148: error: expected identifier or ‘(’ before ‘<’ token
s="pl-k">include <stdio.h>
^

triangle.c:1027:187: error: expected identifier or ‘(’ before ‘<’ token
-s"><stdio.h>
^

triangle.c:1031:69: error: stray ‘#’ in program
#include <stdlib.h>
^
triangle.c:1031:148: error: expected identifier or ‘(’ before ‘<’ token
s="pl-k">include <stdlib.h>
^

triangle.c:1031:188: error: expected identifier or ‘(’ before ‘<’ token
s"><stdlib.h>
^

triangle.c:1035:69: error: stray ‘#’ in program
#include <unistd.h>
^
triangle.c:1035:148: error: expected identifier or ‘(’ before ‘<’ token
s="pl-k">include <unistd.h>
^

triangle.c:1035:188: error: expected identifier or ‘(’ before ‘<’ token
s"><unistd.h>
^

triangle.c:1091:125: error: expected identifier or ‘(’ before ‘<’ token
nner js-file-line"> EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_NONE};
^

triangle.c:1128:72: error: expected identifier or ‘(’ before ‘<’ token
};
^
triangle.c:1141:120: error: expected identifier or ‘(’ before ‘<’ token
ode-inner js-file-line"> EGL_NONE};
^

triangle.c:1162:124: error: invalid suffix "f" on integer constant
js-file-line"> -1.0f,
^~

triangle.c:1166:124: error: invalid suffix "f" on integer constant
js-file-line"> -1.0f,
^~

triangle.c:1170:123: error: invalid suffix "f" on integer constant
js-file-line"> 0.0f,
^~

triangle.c:1174:123: error: invalid suffix "f" on integer constant
js-file-line"> 1.0f,
^~

triangle.c:1178:124: error: invalid suffix "f" on integer constant
js-file-line"> -1.0f,
^~

triangle.c:1182:123: error: invalid suffix "f" on integer constant
js-file-line"> 0.0f,
^~

triangle.c:1186:123: error: invalid suffix "f" on integer constant
js-file-line"> 0.0f,
^~

triangle.c:1190:123: error: invalid suffix "f" on integer constant
js-file-line"> 1.0f,
^~

triangle.c:1194:123: error: invalid suffix "f" on integer constant
js-file-line"> 0.0f,
^~

triangle.c:1198:72: error: expected identifier or ‘(’ before ‘<’ token
};
^
triangle.c:1211:70: error: stray ‘#’ in program
#define STRINGIFY(x) #x
^

triangle.c:1211:170: error: stray ‘#’ in program
span> STRINGIFY(x) #x
^

triangle.c:1219:94: error: expected identifier or ‘(’ before ‘<’ token
ss="blob-code blob-code-inner js-file-line"> attribute vec3 pos; void main() { gl_Position = vec4(pos, 1.0); });
^

triangle.c:1219:246: error: expected identifier or ‘(’ before ‘)’ token
vec4(pos, 1.0); });
^

triangle.c:1219:248: error: expected identifier or ‘(’ before ‘<’ token
vec4(pos, 1.0); });
^

triangle.c:1232:131: error: expected identifier or ‘(’ before ‘<’ token
-line"> STRINGIFY(uniform vec4 color; void main() { gl_FragColor = vec4(color); });
^

triangle.c:1232:254: error: expected identifier or ‘(’ before ‘)’ token
main() { gl_FragColor = vec4(color); });
^

triangle.c:1232:256: error: expected identifier or ‘(’ before ‘<’ token
main() { gl_FragColor = vec4(color); });
^

triangle.c:1445:72: error: expected identifier or ‘(’ before ‘<’ token
}
^
triangle.c:1495:259: error: stray ‘\’ in program
L display! Error: %s\n",
^

triangle.c:1524:259: error: stray ‘\’ in program
L version! Error: %s\n",
^

triangle.c:1549:267: error: stray ‘\’ in program
"pl-c1">%d.%d\n", major, minor);
^

triangle.c:1574:258: error: stray ‘\’ in program
GL config! Error: %s\n",
^

triangle.c:1615:262: error: stray ‘\’ in program
L surface! Error: %s\n",
^

triangle.c:1665:262: error: stray ‘\’ in program
L context! Error: %s\n",
^

triangle.c:1774:260: error: stray ‘\’ in program
"pl-c1">%dx%d\n", viewport[2], viewport[3]);
^

triangle.c:1803:189: error: stray ‘\’ in program
lass="pl-pds">"EGL might be faulty!\n");
^

triangle.c:1820:164: error: invalid suffix "f" on integer constant
lClearColor(0.0f, 0.0f, 0.0f, 1.0f);
^~

triangle.c:1820:224: error: invalid suffix "f" on integer constant
"pl-c1">0f, 0.0f, 0.0f, 1.0f);
^~

triangle.c:1820:284: error: invalid suffix "f" on integer constant
"pl-c1">0f, 0.0f, 1.0f);
^~

triangle.c:1820:344: error: invalid suffix "f" on integer constant
"pl-c1">0f, 1.0f);
^~

triangle.c:1948:205: error: invalid suffix "f" on integer constant
pl-c1">1.0, 0.0f, 0.5, 1.0);
^~

triangle.c:2069:241: error: stray ‘\’ in program
n>Failed to open file triangle.raw for writing!\n");
^

triangle.c:2115:72: error: expected identifier or ‘(’ before ‘<’ token
}
^
triangle.c:2150:12: warning: missing terminating ' character


^
triangle.c:2150:12: error: missing terminating ' character

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triangle.c:2173:39: error: expected identifier or ‘(’ before numeric constant
  • © 2021 GitHub, Inc.

  • ^~~~
    triangle.c:2207:12: error: stray ‘\342’ in program
    You can???t perform that action at this time.
    ^
    triangle.c:2207:13: error: stray ‘\200’ in program
    You can???t perform that action at this time.
    ^
    triangle.c:2207:14: error: stray ‘\231’ in program
    You can??t perform that action at this time.

    Double buffer issue

    Thanks for sharing the RPI4 example - much appreciated!

    The "gbmSwapBuffers" function uses two independent buffers. This is all clever as it prevents disturbance/flickering while preparing/rendering the next screen. The fact that these buffers are alternating however is also creating an issue. When only parts of a screen needs updating, you want to leave everything else untouched.

    The way the two buffers are used cause the display to mix new and old content. Another approach is to make sure every refresh cycle starts with the latest content.

    Do you see a way to make sure the background buffer used for rendering inherits whatever was displayed during the previous refresh/redraw cycle?

    The examples below show how the display keeps alternating whenever I redraw the left part only. The right part is a leftover only present in one of the two buffers. It may seem obvious to just redraw everything, but this may not be trivial for applications that rely on buffer content being preserved.

    image

    image

    Pi4 with LCD output has no vsync

    On Pi3 it has the correct 60 FPS, but Pi4 i can more than 60 (LCD refresh is especially 60Hz).

    If I do the same on HDMI, it is OK, no more than 60 FPS happens.

    I use the same gbmSwapBuffers...

    RPI4: failed to add service - already in use?

    I also get the

    failed to add service - already in use?

    message, every time. Your troubleshooting suggestion:

    "Failed to add service - already in use?

    As mentioned in this issue, you have to remove both vc4-kms-v3d and vc4-fkms-v3d from R-Pi config."

    seems to be in direct contradiction to enabling DRM which is necessary for the Pi4 to work using your code, isn't it? Am I missing something?

    * failed to add service - already in use?

    I'm sure it's something with my configuration, but I'm doing my darnedest to figure out what's going on here. If I try to compile my own OGLES-without-X stuff or use this example, this error is all I get when the executable runs. Any ideas of where to go or how to figure things out from here?

    * failed to add service - already in use?
    

    "Unable to get connector" when using a Pi Compute Module 4

    It appears that the resources->count_connectors is 0 in my case. Perhaps I have something configured incorrectly, but I suspect that this is because I do not have an HDMI connector on the host board (this is intentionally designed as a headless board).

    It appears that the connector is used to find the encoder, which is used to get the Crtc (whatever that is) which appears to be used to change buffers in other places.

    Technically I don't even need display buffer or to render anything, I'm just trying to run an OpenGL ES Compute Shader, but I figured this would be a good place to start in terms of getting GL running headless. I'm going to try to remove all the display buffer related code and get a compute shader running; does anyone know if that should work?

    [click click click]

    Okay, with removing all that, I appear to have gotten it to run through creating an EGLContext. I'm not certain, yet, but that might be all I need to proceed to compiling and running a compute shader.

    raspbian eGL issue

    Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux

    sudo apt-get install mesa-utils
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    mesa-utils is already the newest version (8.3.0-3).
    mesa-utils set to manually installed.
    0 upgraded, 0 newly installed, 0 to remove and 27 not upgraded.
    
    pi@raspberrypi:~/rpi-opengl-without-x $ 
    
    pi@raspberrypi:~/rpi-opengl-without-x $ ./triangle 
    libEGL warning: DRI3: xcb_connect failed
    libEGL warning: DRI2: xcb_connect failed
    libEGL warning: DRI2: xcb_connect failed
    Failed to get EGL version! Error: 
    
    

    PI4 support?

    Hi! - I just saw, the pi4 support todo. Will it work on Pi4?

    Running triangle_rpi4.c does not require HDMI connection

    I'm running Buster on RPI4

    Some info:

    $ uname -a
    Linux raspberrypi 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l GNU/Linux
    $ cat /proc/cpuinfo
    ...
    Hardware	: BCM2711
    Revision	: c03112
    Model		: Raspberry Pi 4 Model B Rev 1.2
    

    Steps followed:

    1. sudo apt-get install libegl1-mesa-dev libgbm-dev libgles2-mesa-dev libdrm-dev -y
    2. git clone https://github.com/matusnovak/rpi-opengl-without-x && cd rpi-opengl-without-x
    3. gcc -o triangle_rpi4 triangle_rpi4.c -ldrm -lgbm -lEGL -lGLESv2 -I/usr/include/libdrm -I/usr/include/GLES2
    4. Execute, no X server, no HDMI output connected.
    $./triangle_rpi4 
    resolution: 1680x720
    Initialized EGL version: 1.4
    GL Viewport size: 1680x720
    

    Problem with Raspberry PI 2 and Raspbian 11 (bullseye)

    Hi,

    I have been last using C++ when I was working at university 15 years ago, since that I had no need and I am really out of the topic. However, I found an interesting Project which uses OpenGL without X and I found this project but I used OpenGL last time when I was still a student (and not over C++), so forgive me if I am missing obvious connections.

    I just installed Raspbian 11 (bullseye) and found nothing to work for me. After a lot of trial I got the thing compiled and under the desktop it even rendered a file but not over SSH connection. I tested and read and finally as I was finding mesa all the time, I wondered if I installed that. I just reinstalled the OS and made the following observations:

    user@host:~ $ cat /etc/os-release
    PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
    NAME="Raspbian GNU/Linux"
    VERSION_ID="11"
    VERSION="11 (bullseye)"
    VERSION_CODENAME=bullseye
    ID=raspbian
    ID_LIKE=debian
    HOME_URL="http://www.raspbian.org/"
    SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
    BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
    

    First thing I found ist, that there is no directory "/opt/vc/lib"

    user@host:~ $ ls /opt/
    pigpio/      WidevineCdm/
    

    Aparently it has been moved to /usr/lib/arm-linux-gnueabihf/ due to some postings I found and it seems correct. In that folder I see:

    user@host:~ $ ls /usr/lib/arm-linux-gnueabihf/libEGL*
    /usr/lib/arm-linux-gnueabihf/libEGL_mesa.so.0  /usr/lib/arm-linux-gnueabihf/libEGL_mesa.so.0.0.0  /usr/lib/arm-linux-gnueabihf/libEGL.so.1  /usr/lib/arm-linux-gnueabihf/libEGL.so.1.1.0
    

    However, I read again mesa, which seems not to be working with this project, right?

    I also found that in recent versions of Raspbian I need to use
    -lGLESv2 instead -lbrcmGLESv2
    -lEGL instead -lbrcmEGL

    Probably I am heavily messing with libraries in "bullseye" but as I don't know how it is meant to be, can you maybe check what to do under fresh installed Raspbian 11 optimally over SSH as I do not have a monitor connected usually)?

    DRM failed to get resources

    Hi @matusnovak,

    First of all thank you for all the work here and for the RPI4 example.

    I've been trying to migrate or try to port this: https://github.com/boydm/scenic_driver_nerves_rpi (for Nerves, an Elixir project) in order to let the driver draw on the screen.

    I've tried to follow the instructions you setup but so far no luck. It gets stuck on the Unable to get DRM resources.

    Any thoughts?

    I can push my branch and link you to it if you need to.

    Thank you.

    ~ bjufre

    PI4 dual display with common context

    Hi!

    I ran an issue:
    when I use the code with LCD and HDMI display together, I can not activate the second display (and surface) errorless.

    First I use context 1:
    eglMakeCurrent(ctx->eglDisplay, ctx->eglSurface, ctx->eglSurface, ctx->eglContext)

    Than the context 2 with the same eglContext:
    eglMakeCurrent(ctx2->eglDisplay, ctx2->eglSurface, ctx2->eglSurface, ctx->eglContext)

    And the second gives EGL_BAD_CONTEXT.

    Anyway if I use in the second one with ctx2->eglContext at the 4th parameter, it succeeded, but it gives a blank screen (because the ctx2 contains nothing)

    What is the problem? Can U give me an example for using 2 displays with the same eglContext?

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. 📊📈🎉

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google ❤️ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.