Where are the OpenGL header files located on MacOSX? - opengl

In /usr/include ,
I tried grepping for GL gl and OpenGL .. .but can't find it.
Where are these header files located?

They are located at /System/Library/Frameworks/OpenGL.framework/Headers. To include them, just use:
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>
#include <GLUT/glut.h>
etc. Make sure to link against the appropriate frameworks, eg)
cc <your_file.c> -framework GLUT -framework OpenGL
for OpenGL and GLUT

This is a good old thread to revive, because the correct answer changed. The accepted answer of /System/Library/Frameworks/OpenGL.framework/Headers was totally correct when it was written. But with Xcode 5 (I believe it changed with Xcode 4 already), this is not the case anymore.
All SDK files are now installed into /Applications/Xcode.app. The exact location of the headers depends on the platform the application is built against. As an example, the OpenGL headers for OS X 10.9 are in:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/OpenGL.framework/Headers

It's worth noting that one also needs to have XCode itself set up (not just installed), as well as the XCode Command-Line Tools, even if one is not building the application in XCode.

XCode automatically exposes all header files from a framework added to a project via the framework's name.
So, "cocoa.h" is part of "cocoa.framework" - hence #include <cocoa/cocoa.h>
OpenGl is included <OpenGL/gl.h> rather than the more expected <GL/gl.h> on other platforms.

In MacOS 10.12.6, they're under /opt/X11/include, e.g. /opt/X11/include/GL/gl.h.

Related

Compiling the Canon SDK on macOS

I'm trying to compile a very basic program (for the first time) on macOS. The program was written on windows with the help of the Canon SDK. This SDK is available for Windows as well as for macOS. There is however an issue I'm coming against. The SDK consists of 3 header files and a linker file ( .lib for windows and .framework for mac). As I never worked with macOS I first had to figure out how to link the .framework file.
OSX How to compile a framework using GCC/G++ sitting in a current working directory or subdirectory C/C++
This is the solution I found here.
However, I still run into an issue. In one of the files (EDSDK.h) there is an include of windows.h.
Actual code:
#ifdef __MACOS__
#include <CoreFoundation/CoreFoundation.h>
#else
#include <windows.h> <--Error
#endif
This include gives me an error as there is no window.h on the macOS. After some searching, I came across this question:
Where can I get windows.h for Mac?
Where the answer suggests making a dummy windows.h and one by one satisfy the missing definitions. This however was impossible as the SDK uses too much definitions from windows.h ( and other files included in the windows.h ) to be viable.
How do I go about compiling my program that uses the Canon SDK. Do I setup a dual boot setup and link to the actual windows.h?

Installing OpenGL and compiling with command line on Windows

So there is the problem: when I compile #include <GL/gl.h> or #include <GL/glu.h> error occurs: no such file or directory. I updated NVidia drivers but error stays.
I have been struggling in setting up OpenGL without GLUT. I have read countless tutorials, but all of them are for Microsoft Visual C++, which requires placing gl.h in this IDE internal include folder. And I am trying to using only command line to compile winapi applications.
What dlls should I download and where to place them?
In Windows, OpenGL is provided as a static library, you do not need to get any DLLs (your graphics driver will provide OpenGL extensions). GL.h and GLU.h are included in the Windows SDK, along with OpenGL32.lib and GLU32.lib. However, if you want to use anything other than OpenGL 1.1., you will need to get wglext.h and glext.h from Khronos. Your driver will provide the extension prototypes, which you get using wglGetProcAddress (this function is linked in with OpenGL32.lib).

Setting up Opengl for Borlandc++

I have copied the glut.h file in c:/turbo/tc/include/ directory and glut32.dll in c:/windows/System32/.
After this what should I do ?
your path implies old Borland Turbo C++ 3.1 to me
which was the old MS-DOS C++ IDE (similar to Borland TP 7.0 pascal IDE)
in which you can not have classic 32bit OpenGL
there were some 16bit MS-DOS versions of GL+GLUT compatible ports of glut+gl libs.
so unless you do not have them then it will not work no matter you do
if you do then read the provided readme.txt or whatever to see how to use it
there were some tutorials on them but I strongly doubt you will find them on the internet
because most of old programing portals is off-line and stuff lost forever ...
if you have newer compiler like Borland C++ BCC 5.0 or newer
then just include headers
link lib files for used dll's for example:
#include "my_GL_headers\\glut.h"
#pragma link "my_GL_headers\\glut.lib"
use implib tool if you do not have them or are incompatible
because most provided libs are for MSVC++
which are incompatible with standard Intel object format
for more info see difference between COMF and OMF
some header files already link their lib files so do this only if you have unresolved externals ...
If you use IDE like Borland C++ builder 1,2,3,4,5,6 or Developer Studio 2006 Turbo C++
then look at this answer of mine: How to render an openGL frame in C++ builder?
all the headers and libs are included in IDE ...
PS this is how mine usual GL includes look like in BDS2006 projects
#include <windows.h>
#include <jpeg.hpp>
#include <math.h>
#define GLEW_STATIC
#include "gl\glew.c"
#include "gl\gl.h"
#include "gl\glu.h"
#include "gl\glext.h"
#include "gl\wglext.h"
#include "gl\glut.h"
where gl is project source local folder
including all headers/objs/libs ...
the only lib you need is glut.lib (if you want to use glut)
GLEW can be either as lib/dll/obj or as C++ source code
I prefer the C++ source version under borland/embarcadero

How to use openGL with gcc on Mac?

I'm trying to run this openGL example on my Mac from command line using gcc. The XCode is installed, gcc was used many time with other programs (w\o graphics).
Following to this topic I run:
g++ 1.cpp -framework OpenGL -lGLU -lglut
and get:
1.cpp:12:21: fatal error: GL/glut.h: No such file or directory
I found glut.h at /System/Library/Frameworks/GLUT.framework/Headers/ and noted that structure is different (not GL folder). But even removing GL/ and using -I/System/Library/Frameworks/GLUT.framework/Headers/ does not help a lot..
So I wonder - how to use openGL with gcc on Mac properly?
Your first problem is that Apple's Framework infrastructure actively sabotages portability of code by placing OpenGL headers in a nonstandard path. On Apple platforms the OpenGL headers are located in a directory named OpenGL instead of just GL.
So to portably include the headers you have to write
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
Your other problem is, that GLUT is not part of OpenGL and an independent, third party library, that's no longer contained within the OpenGL framework. You need to use the GLUT Framework. And of course that one uses nonstandard include paths as well:
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
Compile with the -framework OpenGL -framework GLUT options.
On mavericks using the include
#include <GLUT/glut.h>
works if you compile with the following line
g++ 1.cpp -framework OpenGL -framework GLUT

'glGenBuffers' was not declared in this scope. Windows 7. Qt 4.8.1

'glGenBuffers' was not declared in this scope
thats the error which I get after trying to use that metod. How to add appropriate libs or sth else and what i should add and how. I'm using win 7 and qt 4.8.1. I've read about GLEW but I don't know how to add it to windows or qt.
It's a FAQ. Windows defines the OpenGL ABI (B for binary interface) only up to version OpenGL-1.1 – anything beyond that must be loaded at runtime using the extension loading mechanism. Most easily done by using a wrapper library like GLEW.
I've read about GLEW but I don't know how to add it to windows or qt.
If you want to use any 3rd party library, you've to learn how to do that. It boils down to install the library and its header in some system wide directory, but outside the regular compiler tree, and add those directories to the include and library search paths.
I use this code for including GLEW and Glut for cross-platform development:
#ifndef GL_H
#define GL_H
#ifdef __APPLE__
#include <GL/glew.h>
#include <GLUT/glut.h>
#else
#include <GL/glew.h>
#include <GL/glut.h>
#endif
#endif // GL_H
I encapsulate that into a file called gl.h and include that anywhere I need an OpenGL context. You will need to research how to install GLEW on your system. Make sure that you install the correct build of GLEW for your compiler. If you use Visual C++ 2010 or MinGW, it will be slightly different as far as where to put the libs and include files. You could always build from source too, but that is a more advanced route.
If you would like some sample code on how to get started with Qt and OpenGL, I've got a repository on Bitbucket with some code that I wrote for an OpenGL programming class here: https://bitbucket.org/pcmantinker/csc-4356/src/2843c59fa06d0f99d1ba90bf8e328cbb10b1cfb2?at=master