Can I use programs using OpenGL and GLUT in Raspberry Pi 3b+? - opengl

I have a ready-made program code that uses OpenGL and glut, can I compile and run this program in Rasbian on Raspberry 3b+?

Yes, but with a caveat
You can use OpenGL software on RPis, but you need to note that RPIs do not implement up to the newest standard, 4.6. I think they implement up to version OpenGL 2.0 ES, but don't quote me on that.
If you want to find out, you can simply enable the GL driver in raspi-config and then run the command
glxinfo | grep "OpenGL version"
to figure out what standard you can use.
This will determine what standard of OpenGL code works and therefore what code will compile.
Only after you verify the version will you know if the code will run.
Even then, there is sooo little RAM that it may not work.
That is outside the scope of this question though.

Related

how should I interpret the output of glewinfo?

running glewinfo has a lot of information, but some of it is more confusing than helpful.
Here is my glewinfo from a laptop I have http://pastebin.com/K5p37w8a
It tells me my OpenGL version is 2.1, but when I continue reading, there are entries to GL_VERSION_3_0 up to GL_VERSION_4_0, and all of them say OK. But I can't call any of the functions listed there.
Others are tagging with OK [MISSING] this is the most confusing of them all, because either it is there, or it is missing, but it can't be both at the same time.
The glewinfo program shows you all of the entry points (functions) which are present, it doesn't tell you whether you can use the features, or whether those entry points work. A function could report as OK but your program could still crash if you call it! To figure out what features are available, you will have to look at the extension strings and the version number. You can get this information from glxinfo, you do not need GLEW.
In this case, you are using Mesa (an OpenGL implementation) with a compatibility profile (which is the default profile). In compatibility mode, Mesa is limited to OpenGL 2.1. However, if you request a core profile, Mesa will provide newer features and support a newer version of OpenGL. The same Mesa library is still used, which is why all of the OpenGL 4.0 entry points are available.
However, GLEW is somewhat broken when you use it with the core profile. The glewExperimental "fix" is a poor band-aid on a flawed implementation. For this reason, I do not recommend GLEW. glLoadGen is a good alternative.

How to use DRI instead of glx? [duplicate]

I want to use OpenGL rendering without X, with google i find it: http://dvdhrm.wordpress.com/2012/08/11/kmscon-linux-kmsdrm-based-virtual-console/ there says that it is possible. I should use DRM and EGL. EGL can create opengl context but requires a NativeWindow. DRM probably will provide me NativeWindow, is not it? Should i use KMS? I know that i must have open source video driver. I want exactly OpenGL context, but not OpenGL ES (Linux). Maybe, someone knows tutorial or example code?
Yes, you need kms stack (example). Here is a simple example under linux, it use OpenGL es, But the step to have it working against OpenGL api are simple.
In the egl attribs set EGL_RENRERABLE_TYPE to EGL_OPENGL_BIT
And tell egl which api to bind to:
eglBindAPI(EGL_OPENGL_API);
Be sure to have latest kernel drivers and mesa-dev, libdrm-dev, libgbm-dev. This pieces of code is portable on android, it's just not so easy to have default android graphic stack silenced.
note: I had trouble with 32bit version, but still don't know why. those libs are actively developed, so not sure it wasn't a bug.
*note2: depending on your GLSL version, float precision is supported or not.
precision mediump float;
note3: if you have permision failure with /dev/dri/card0, grant it with:
sudo chmod 666 /dev/dri/card0
or add current user to video group with
sudo adduser $user video
you may also setguid for your executable with group set to video. (maybe best option)

Moving from fixed-pipeline to modern OpenGL

I have done some simple OpenGL (old fixed pipeline ,without shaders ..etc) and want to start some serious "modern" OpenGL programming. (Should compile on Windows and Linux)
I have few questions.
1) In Windows , the "gl.h" doesnt have OpenGL2.0+ related API calls declared .(eg. glShaderSource() ) . How can I access these API calls?
I dont want to install graphics-card specific headers since, I want to compile this application in other machines.
2) In Linux ,If I install Mesa library can I access above OpenGL2+ APIs functions ?
There has been a long-held belief among some (due to the slowness of GL version updates in the late 90s/early 00s) that the way to get core OpenGL calls was to just include a header and a library. That loading function pointers manually was something you did for extensions, for "graphics-card specific" function. That isn't the case.
You should always use an extension loading library to get access to OpenGL functions, whether core or extension. GLEW is a pretty good one, and GL3W is decent if you can live with its limitations (3.0 core or better only).

Forcing OpenGL Core Profile Only

Is there a compiler flag or another way of forcing OpenGL core profile only? I want to get an error when i use deprecated functions like glRotatef and so on.
EDIT1: I am using Linux, however, i am also interested in knowing how to do this in Windows
EDIT2: I would prefer to get an error at compile time, but runtime error would be ok as well.
You could compile your code using gl3.h instead of gl.h.
http://www.opengl.org/registry/api/gl3.h
Try wglCreateContextAttribsARB() with WGL_CONTEXT_CORE_PROFILE_BIT_ARB.
Or glXCreateContextAttribsARB with GLX_CONTEXT_CORE_PROFILE_BIT_ARB.
You might find this example useful as a testbed.
Depends on what creates your OpenGL context.
If you're using GLFW (which I sincerely recommend for standalone OGL window apps), then you can do before you create the window:
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR,3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR,1);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);
// the last line shouldn't be necessary
// as you request a specific GL context version -
// - at least my ATI will then default to core profile
Note that if you request a pre-3.0 GL context on modern hardware/drivers, you're likely to receive a newest possible context in compatibility mode instead. Check what your GPU returns from glGetString(GL_VERSION) to make sure.
If you use another API for creation of OpenGL context, check its reference manual for similar functions.
BTW:
I believe it's impossible to get an error in compile time - your compiler can't be aware what OpenGL context you will receive after your request (if any). The correct way of ensuring that you're not using out-of-version functionality is testing for glGetError().
Also, I recommend using the gl3w extension wrapper if you compile for Windows.
I have found another way to do it using the Unofficial OpenGL Software Development Kit:
http://glsdk.sourceforge.net/docs/html/index.html
By using the 'GL Load' component its possible to load a core profile of OpenGL and to remove compatibility enums and functions for versions of OpenGL 3.1 or greater. A short howto can be found here:
https://www.opengl.org/wiki/OpenGL_Loading_Library#Unofficial_OpenGL_SDK

Which OpenGL version by default installed along with MinGW?

I recently tried to lay my hands on OpenGL. Trying to grasp the API, I am using MinGW along with OpenGW. Now, I learned (or was given the advice) that I shouldn't use glBegin and glEnd anymore, since those are deprecated, but should start with OpenGL 3.1, instead. As I didn't know that the version used makes such a difference, I didn't pay much Attention as to which version I actually have installed on my computer. And, as far as I can see, there is no glVersion or similar call that I could use to determine that version.
Since I am using MinGW I went to its respective include folder and found in c:\MinGW\include\GL\gl.h:
/*
* Mesa 3-D graphics library
* Version: 4.0
[more lines]
*/
[more lines]
#define GL_VERSION_1_1 1
#if !defined(__WIN32__)
#define GL_VERSION_1_2 1
#define GL_VERSION_1_3 1
#define GL_ARB_imaging 1
#endif
[more lines]
#define GL_VERSION 0x1F02
which, to me, indicates, that the installed version is as low as 1.3. Is this the case or how could I verify my suspicion? Also, where would I find a later version (that is working fine along with MinGW) if I have 1.3 (or whatever version it is) only?
So, does someone know, if my suspicion is right and that MinGW comes with an outdated OpenGL version?
Edit I realise that this question might be taken as a duplicate of Which OpenGL version by default installed along with MinGW?, yet, I believe this question is specifically about MinGW and OpenGL, so I think that this fact allows for a (perhaps) more specific answer.
So, does someone know, if my suspicion is right and that MinGW comes with an outdated OpenGL version?
MinGW comes without "an OpenGL", your operating system (the graphics card driver, usually) provides OpenGL.
MinGW provides a header file (gl.h), and a corresponding library (libopengl32.a) which is a wrapper for opengl32.dll, a dynamic library which comes with Windows and contains the handles to OpenGL 1.0 an 1.1 functions... something around that, not sure about exact version numbers.
Then:
Most operating systems allow you to use the whole OpenGL in a similar way.
On Windows, however, in order to access the newer OpenGL functions than what's in the header and library wrapper (which you probably do have available - depending on your GPU and driver), you have to use system calls to load the function pointers to the OpenGL calls.
There are libraries which do that for you and let you use OpenGL 3/4 functionality easily. I recommend gl3w or GLEW. That's the usual way of using OpenGL on Windows.
There's glGetString(GL_VERSION).
Please note this question has been asked and answered before.
http://learningwebgl.com/blog/?p=11#troubleshooting has some good information - WebGL uses OpenGL. You can use http://www.realtech-vr.com/glview/ to confirm your test.