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
Related
Can anybody tell me how to compile the opengl code in emacs just like we do in visual studio?
What we should do you link the library in emacs to run opengl code in emacs? Is it even possible? I've seen the internet that you can use emacs as you IDE although it is a text editor.
Emacs is just an editor. It doesn't give a iota about what you're writing in it. Sure you can loads a gazillion macros in it, and somewhere someone might have even created a Emacs Lisp implementation of OpenGL. But that's not relevant for this question.
What editor you use is completely irrelevent to programming OpenGL!
I think what you're really interested in is, how to write Makefiles or equivalent for other build systems.
You want to compile OpenGL code? Great! To do so in C or C++ include the OpenGL headers in your source code, i.e.
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
For any other language use the appropriate bindings.
Then add the OpenGL to your linker:
For Windows:
Visual C++: Add opengl32.lib to the list of extra libraries
MinGW / GCC / Clang: Add -lopengl32 to the linker stage
For Linux:
If linking for GLvnd (recommended): Add -lOpenGL to the linker stage
If not using GLvnd: Add -lGL to the linker stage
For macOS: Add -framework OpenGL to the compiler and linker stages.
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).
I am configuring a program that works with glut to work with Qt. I am using Qt 5.1.1. and it seems that some of openGL functionality has been lost from Qt4 to Qt5. In my program I create a QOpenGLContext and I am trying to render to a QWindow with the use of a vbo. The vbo part works fine.
Some of the other parts of the program depends on glew. I get the following warning when I run the program
#warning qopenglfunctions.h is not compatible with GLEW, GLEW defines will be undefined [-Wcpp]
#warning To use GLEW with Qt, do not include <qopengl.h> or <QOpenGLFunctions> after glew.h [-Wcpp]
The output to the screen is black.
When I comment out the line
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, vboId);
which sends the pbo to the texture, a random image renders to the screen. I assume that this random image is stored in the memory which I am trying to access.
Obviously, you cannot use glew and qopenglfunctions together.
If you want to suggest that I use a QGLWidget and not a QopenGLContext with a QWindow, please explain to me how to use QGLWidget with cmake in Qt 5.1.1. I have read numerous answers suggesting that, but none of them works in Qt 5.1.1.
Posting as answer because not enough rep to comment.
To use GLEW with Qt, do not include <qopengl.h> or <QOpenGLFunctions> after glew.h [-Wcpp]
As the warning suggests, you should omit the QOpenGLFunctions include directives in favour of the GLEW includes.
Edit: After some more research, it found that QT includes the QOpenGLFunctions header somewhere in an internal file. I'll have to test a workaround myself, will come back.
Edit: General update, and apparently people misinterpreted this post as offensive and rude.
'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
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.