Till now I've been developing OpenGL apps using GLEW in Visual Studio, but I recently switched to macOS and I'm trying out Xcode.
One very important thing to me is that I want the IDE to show me what parameters a function requires as I type it, and this worked fine on VS.
Unfortunately, GLEW defines OpenGL functions with the preprocessor command #define, and Xcode doesn't seem to handle that very well as it doesn't show me the parameter list for those functions.
For now I only found a couple of functions that work correctly and they are the glBindTexture(), glBindTexture() and glDrawElements() functions.
Is there a way to let Xcode now that the others( the glBufferData() function, for example) are also functions and that it should go retrieve the parameters list for me?
The main purpose of GLEW is to provide you with function pointers to OpenGL functions. However, on macOS this is not really necessary. You can do something like this:
#if defined __APPLE__
#include <OpenGL/gl3.h>
#else
// Or however you use GLEW
#include <GL/glew.h>
#endif
This will not provide prototypes for anything newer than 4.1, however, so you would have to #ifdef those parts out. Any functions which are not available at runtime will simply be NULL, which is basically the same way that GLEW works.
The other alternative is to use an OpenGL loader which provides a more IDE-friendly header. These do exist, I think glLoadGen is an example.
Related
Following this tutorial I was trying to manage my OpenGL buffers for an OpenGL context I created using SFML, under a visual studio environment. I installed SFML and Glew in their latest versions, did correct linking, and I am able to work with primitives like OpenGL glClear, glBegin and glVertext3d.
However there is plenty of other OpenGL functions that I can t seem to be able to call like glEnableVertexAttribArray or glBindBuffer and I would like to understand why. I noticed that the default OpenGL version set by SFML context is 4.6 but I can t find proper documentation for these functions on khronos website for this version. Moreover my visual studio doesn t even recognize theses functions as part of any library but I might have missed some includes given that I rely on SFML/OpenGL.hpp. Documentation on SFML side is very ligth on this subject...
Thanks !
I am able to work with primitives like OpenGL glClear, glBegin and glVertext3d. However there is plenty of other OpenGL functions that I can t seem to be able to call like glEnableVertexAttribArray or glBindBuffer and I would like to understand why.
The reason for this is that the opengl32 library on windows only provides OpenGL 1.1 functionality, everything else is brought in by your graphics card driver. To actually access these functions, windows provides a function to load them. However, writing all the declarations and loading all functions is a lot of work (See Load OpenGL Functions in the OpenGL Wiki) so libraries exist which do this for you, one such library is glew, "The OpenGL Extension Wrangler Library". After you created your OpenGL context (which SFML does), you must call glewInit() which then loads all the other functions. The declarations for those functions are also provided by glew, so make sure to include the glew header instead of your systems or SFMLs opengl header.
I can't seem to find where GL_UNSIGNED_INT_8_8_8_8_REV is defined. Googling around, I only seem to find places where it had been defined manually:
#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
It doesn't appear to be in gl/GL.h or gl/GLU.h or even anywhere in Windows.h.
Windows ships with an outdated version of <gl/GL.h> (the Windows version of this file was obsolete back in 1998, as of 2013 it still hasn't been updated). You will need to use something like GLEW to get access to modern OpenGL features on Windows. This will provide a complete OpenGL header, as well as a library to automatically detect OpenGL extensions.
'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
I've set the linker to additional dependencies opengl32.lib;glu32.lib;sfml-main-d.lib;
When I run it, I get loads of errors about APIEntry or something in one of the OpenGL files. SFML is also set up fine.
Here is my code:
#include <iostream>
//#include <Windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
using namespace std;
void main()
{
}
It works fine if I include Windows.h, but I really don't want to make it windows-specific (Since the only reason I switched to C++ from C# is for cross platform and I'm not too fussed on Java)
If you're going to use OpenGL, then you should employ a proper OpenGL Loading Library to get your function pointers. These libraries have headers that will include whatever platform-specific stuff is needed to make the header work, using appropriate #defines and so forth.
If you're starting out you're probably not interested in the lower level stuff as setting up your own OpenGL context and such. I would recommend you take a look at GLFW at http://www.glfw.org/ - it is what I prefer for OpenGL. It is open source and cross platform for both Windows, linux and MAC.
Good luck!
I'm trying to use OpenGL VBO's, but the functions associated with their use, glGenBuffersARB() for instance, are all undefined. Immediate mode functions are fine of course, it's only these.
I'm using VS2010, with the SFML library. One of the include headers in that library includes both <GL/gl.h> and <GL/glu.h>, and the executable is linked against glu32.lib and opengl32.lib
Why are only these functions missing, and how would I be able to include their use?
GLEW will define them, as will other GL extension libraries.
Information can be found here: http://www.opengl.org/resources/features/OGLextensions/
Using an extension that includes new function call entry-points is harder in Win32 because you must first request the function pointer from the OpenGL ICD driver before you can call the OpenGL function.
GLEW does this for you.