Pablo Walters
Posts: 18
Joined: Sun Nov 27, 2016 6:21 am

Has anyone been able to get glfw running?

Sun Sep 09, 2018 3:47 am

I'd like to use OpenGL under X windows.

User avatar
rpiMike
Posts: 602
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Has anyone been able to get glfw running?

Sun Sep 09, 2018 4:51 am

Yes, just turn it on by using ‘sudo raspi-config’. Select Advanced Options, GL Driver, Full KMS. Then reboot.

Pablo Walters
Posts: 18
Joined: Sun Nov 27, 2016 6:21 am

Re: Has anyone been able to get glfw running?

Sun Sep 09, 2018 5:45 am

That sounds great. I enabled GL Driver, Full KMS, and restarted.

Are there any simple examples that show how to compile a simple

c application using glfw on Raspberry PI?


I downloaded glfw from github and when I tried "cmake ." it failed with

a message that RandR headers were not found.

User avatar
rpiMike
Posts: 602
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Has anyone been able to get glfw running?

Sun Sep 09, 2018 6:56 am

I googled this example:

https://www.badprog.com/c-opengl-hello-world

You will need to install the following library:

Code: Select all

sudo apt-get update
sudo apt-get install freeglut3-dev
Save the following code as main.cpp:

Code: Select all

#include <GL/glut.h>

void displayMe(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
        glVertex3f(0.0, 0.0, 0.0);
        glVertex3f(0.5, 0.0, 0.0);
        glVertex3f(0.5, 0.5, 0.0);
        glVertex3f(0.0, 0.5, 0.0);
    glEnd();
    glFlush();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE);
    glutInitWindowSize(300, 300);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Hello world :D");
    glutDisplayFunc(displayMe);
    glutMainLoop();
    return 0;
}
I had to compile with:

Code: Select all

g++ main.cpp -o lookAtThis -lglut -lGL
Then run:

Code: Select all

./lookAtThis
Image

Pablo Walters
Posts: 18
Joined: Sun Nov 27, 2016 6:21 am

Re: Has anyone been able to get glfw running?

Mon Sep 10, 2018 1:33 am

RaspPIglfw.JPG
RaspPIglfw.JPG (68.11 KiB) Viewed 3742 times

I got glfw working on Raspberry PI using rpiMike's suggestion!


Here's the full sequence of things you have to do.

1. Select "GL Driver, Full KMS" by running raspi-config

sudo raspi-config

(Select Advanced Options, GL Driver, Full KMS. Then reboot)

2. download zip of glfw from github

https://github.com/glfw/glfw

3. install xorg-dev - this is required

sudo apt-get install xorg-dev

4. cd into the source directory and run cmake

cd glfw-3.2.1
cmake .

5. then run make

make

The examples and tests compile, and most things seem you be working,
although I do see this error message when an application starts:

libGL error: MESA-LOADER: failed to retrieve device information
MESA-LOADER: failed to retrieve device information
MESA-LOADER: failed to retrieve device information

I think glfw is a very nice way to teach OpenGL ES on Raspberry PI since you can have the window
system running, etc.

Pablo Walters
Posts: 18
Joined: Sun Nov 27, 2016 6:21 am

Re: Has anyone been able to get glfw running?

Sun Sep 16, 2018 2:33 am

FYI -

The source file glad.c in the GLFW distribution does not load functions to support VertexArrays,
Framebuffers and Renderbuffers, etc. I added a these to glad.c to make them work:

Code: Select all

diff glad.c.orig glad.c
1402a1403,1428
> 
> 	glad_glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC)load("glIsRenderbuffer");
> 
> 	glad_glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)load("glGenRenderbuffers");
> 	glad_glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)load("glBindRenderbuffer");
> 	glad_glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)load("glRenderbufferStorage");
> 
> 	glad_glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)load("glGenFramebuffers");
> 	glad_glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)load("glBindFramebuffer");
> 	glad_glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)load("glFramebufferRenderbuffer");
> 
> 	glad_glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC)load("glFramebufferTexture1D");
> 	glad_glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)load("glFramebufferTexture2D");
> 	glad_glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)load("glCheckFramebufferStatus");
> 	glad_glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)load("glDeleteFramebuffers");
> 
> 	glad_glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)load("glDeleteRenderbuffers");
> 	glad_glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)load("glGenVertexArrays");
> 	glad_glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)load("glBindVertexArray");
> 
> 	glad_glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)load("glDeleteVertexArrays");
> 
> 	glad_glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC)load("glGetRenderbufferParameteriv");
> 	glad_glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC)load("glIsFramebuffer");
> 	glad_glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC)load("glFramebufferTexture3D");
> 	glad_glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)load("glGetFramebufferAttachmentParameteriv");

Return to “OpenGLES”