This is the environment I currently use: Eclipse-Luna, C++11 on Linux Mint -Rebecca.
When I try to use modern OpenGL like with VAOs or VBOs I get Compiler Errors such that methods could not be resolved.
For Example:
GLuint VaoID; //GLuint is working
glGenVertexArrays(1, &VaoID);
or:
GLuint VboID;
glGenBuffers(1, &VboID);
glBindBuffer(GL_ARRAY_BUFFER, VboID);
glBufferData(GL_ARRAY_BUFFER, vbo_size, data, usage);
I checked the GL/gl.h, GL/glext.h and noticed that I have only got OpenGL 1.x methods in there.
So I checked my OpenGL version glxinfo|grep "OpenGL". Which seems to be fine:
glxinfo|grep "OpenGL"
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.1.3
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 10.1.3
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
Trying to install or update the packages again only states that everything is up-to-date.
sudo apt-get install freeglut3 freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libglew1.5-dev' for regex 'libglew1.5'
Note, selecting 'libglew-dev' instead of 'libglew1.5-dev'
Note, selecting 'libglew-dev' instead of 'libglew1.5-dev'
freeglut3 is already the newest version.
freeglut3-dev is already the newest version.
libglew-dev is already the newest version.
libglu1-mesa is already the newest version.
libglu1-mesa-dev is already the newest version.
libgl1-mesa-dev is already the newest version.
libgl1-mesa-glx is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 150 not upgraded.
So is there a way of fixing this without manually messing with the include directory?
And if there isn't how do I get an up to date header fitting my OpenGL version?
I checked the GL/gl.h, GL/glex.h and noticed that I have only got
OpenGL 1.x methods in there.
For GL/gl.h, that is actually how it is supposed to be. If you want to use OpenGL in a platform-independent manner, you can only rely on GL 1.1 being exported by the GL lib, and should also not assume anything more in the headers. GL/glext.h should actually contain something more. But by default, it will not provide function declarations for the newer functions. A recent version of that file can always be obtained from the OpenGL website, btw.
For everything beyond GL 1.1, you should use GL's extension mechanism, which basically means that you have to query the function pointers for each and every GL function >= GL 1.2 at run time. The glext.h header provides the function pointer type declartations, and enum constants, and additional data types. So this basically looks like this for each extension (and new core functionality are considered "extensions" in this context):
#ifndef GL_ARB_vertex_buffer_object
#define GL_ARB_vertex_buffer_object 1
// new types
typedef ptrdiff_t GLsizeiptrARB;
typedef ptrdiff_t GLintptrARB;
// constants for GLenum values
#define GL_BUFFER_SIZE_ARB 0x8764
#define GL_BUFFER_USAGE_ARB 0x8765
#define GL_ARRAY_BUFFER_ARB 0x8892
// ...
// function pointer tpes for every function
typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
// ...
#ifdef GL_GLEXT_PROTOTYPES
// function declatations
GLAPI void APIENTRY glBindBufferARB (GLenum target, GLuint buffer);
GLAPI void APIENTRY glDeleteBuffersARB (GLsizei n, const GLuint *buffers);
// ...
#endif
#endif /* GL_ARB_vertex_buffer_object */
So the function declarations are only effective if GL_GLEXT_PROTOTYPES has been defined. But you shouldn't do that. It will only work if the GL lib happens to export these symbols, and that is not required on most platforms.
Usually, one does not want to load hundreds of GL function pointers manually. There are a couple of OpenGL loading libraries which hanlde all this for you under the hood. And GLEW - which you already installed for some reason - is one of those, so you probably want to use it. Note that GLEW has some issues on its own, notably it is somewhat broken when used in conjunction with modern core profile OpenGL contexts, but it can still be used.
I forgot to mention that I had already included GL/glew.h in my headers. But that didn't fix the compile errors. I checked the file glew.h with eclipse and it shows several error messages. The topmost line marked with an error looks like this:
#error glext.h included before glew.h
Apparently order of includes matters here. After some fiddling the problem boiled down to a very simple change of code. Here is what I had:
#include <GLFW/glfw3.h>
#include <GL/glew.h>
Solution looks like this:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
So I just swapped those two lines and it worked. Thanks for your suggestions again.
Also I removed the GL/gl.h completely.
Related
There's an OpenGL project I have to work on for a course I am attending.
There were link errors due to GLEW. After some research, I found out that on OSX GLEW is not necessary.
I included following headers.
//#include "CL/cl_gl.h"
#include <OpenGL/glu.h>
#include <OpenGL/gl.h>
//#include <OpenGL/glext.h>
//#include <GLUT/glut.h>
But I am still getting compile errors of following kind:
use of undeclared identifier 'GL_TEXTURE_BUFFER_EXT'
glBindTexture(GL_TEXTURE_BUFFER_EXT, 0);
^
Where on OSX is the GLenum GL_TEXTURE_BUFFER_EXT resp. GL_TEXTURE_BUFFER defined?
The EXT variant will only be defined in glext.h or the headers which come or are generated by the various GL extenstion loaders. The actual GL_TEXTURE_BUFFER enum is defined in OpenGL/gl3.h. On OSX, modern GL is part of the OS, and you can directly link the modern GL funtions. However, I would still recommend using some GL loader, just for portability reasons.
error: ‘glDispatchCompute’ was not declared in this scope
I have been working for a month on my setup doing fine. But I have problems using the compute shader. Netbeans says glDispatchCompute isn't declared even though I can Ctrl+click it and see it lying in glew.h, which is included.
OS: Ubuntu 12.10
IDE: Netbeans 8.0
This is what i get from GL_VERSION and whatnot:
GL Vendor : ATI Technologies Inc.
GL Renderer : AMD Mobility Radeon HD 5000 Series
GL Version (string) : 4.4.12874 Compatibility Profile Context 14.10.1006.1001
GL Version (integer) : 4.4
GLSL Version : 4.30
I have tried including anything I can think of:
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glcorearb.h>
#include <GL/glut.h>
#include <GL/glext.h>
// ... //
glDispatchCompute(32, 32, 1);
I have intellisense up to GL_VERSION_4_5 defined in glew.h
I can compile and link shaders with GL_COMPUTE_SHADER and #version 430
I have the capability GL_ARB_compute_shader
-lGLEW -lGL is added to command line
glDispatchCompute requires 4.3
https://www.opengl.org/sdk/docs/man/html/glDispatchCompute.xhtml
I thought maybe it's because I only have 14.1 Catalyst, but I saw someone use glDispatchCompute on 13.xx.
My card's and driver's capability in detail:
http://feedback.wildfiregames.com/report/opengl/device/Mobility%20Radeon%20HD%205000
I can make regular 3D programs that use OpenGL, just not with compute shader so far.
What am I missing?
EDIT:
After update to glew 1.11.0 I get:
undefined reference to `__glewDispatchCompute'
collect2: error: ld returned 1 exit status
I made a game in C++ with OpenGL ES rendering and using OpenAL for sound. To make it work on iPhone I could not use ALUT so I use only "al.h" and "alc.h".
I now try to build my game with the last Android SDK, that supports native applications and added sound support with OpenSL ES. (I believed OpenSL ES was to OpenAL what OpenGL ES is to OpenGL.)
I would like to know if by chance there is an equivalent to the "alc.h" file for OpenSL ES :
#if defined (MYAPP_IOS)
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#elif defined (MYAPP_ANDROID)
#include <EGL/egl.h>
// alc.h equivalent for OpenSL ES here ?
#else
#include <AL/al.h>
#include <AL/alc.h>
#endif
If not, does anybody know a way to handle context and device in OpenSL ES in a similar way than OpenAL (or maybe a way to handle that in both without needing "alc.h" ?). The two errors Android ndk-build returns are of that type :
error: ISO C++ forbids declaration of 'ALCcontext' with no type
I found this on the site that seemed to have what you're looking for:
Android OpenAL?
Looks like someone was able to compile OpenAL for Android. Hopefully this can get you started!
I downloaded SDL 1.2.14
on Windows 7
and I have Mobility Radeon X1800 driver installed.
I'm using Microsoft Visual C++ 2010 Express.
I added the SDL include and library directories in the "VC++ Directories"
I added the following Additional Dependencies:
opengl32.lib;
glu32.lib;
SDL.lib;
SDLmain.lib;
I added the SDL.dll to my program folder
I didn't add any opengl directories!
#include "SDL.h"
#include "SDL_opengl.h"
bool running = true;
int main(int argc, char* args[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen = SDL_SetVideoMode(640,480,32,SDL_OPENGL);
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 640/480, 1.0, 200.0);
while(running) {
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Swich to the drawing perspective
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5f, 0.5f, 0.0f);
glVertex3f(-1.0f, 1.5f, 0.0f);
glVertex3f(-1.5f, 0.5f, 0.0f);
glEnd();
SDL_GL_SwapBuffers();
}
SDL_Quit();
return 0;
}
This program draws a simple triangle.
I include 2 header files above and my Opengl code just works!
I don't know if my triangle is done on a the GPU or CPU. And what openGL version I'm using?
I mean i heard that Microsoft don't update there opengl files any longer and that they use CPU implementation of OpenGL 1.1 or something.
How do I know what version of OpenGL I'm using? And can I check at run time?
How do I know if I'm using a CPU or GPU implementation? And can I check at run time?
Thanks for look at my problem.
call glGetString
Here is Microsoft's documentation for glGetString. It just repeats the SGI doc and tells you the function is found in gl.h and opengl32.lib.
Actually when you install your video card driver it "replaces" the opengl existing in your machine, so you will be using that version.
Multiple versions of OpenGL are present at the same time, and which one is used depends on the HDC used to initialize OpenGL. For example, applications running in the local login session can get hardware-accelerated GL while those running in a remote desktop session get the CPU-based implementation ( Ben Voigt )
The currently header and lib that comes with Visual Studio only has OpenGL 1.1 in it, so to access more modern stuff you need to call the wglGetProcAddress to get pointers to the new functions.
Here you can find more information: http://www.opengl.org/wiki/Getting_started
So I'm trying to bring a c++ project using Qt and OpenGL written and compiled on a Linux machine over to my Windows 7 machine at home, but I'm running into some difficulty. First I learned that some gl things (like GL_TEXTURE0) were no longer defined because gl.h doesn't define them for windows. Also, the glext.h that I have does not define some functions like glActiveTexture. Both of these issues I found could be solved by bringing in a newer glext.h.
My most immediate issue seems to be that I'm not bringing it in correctly. If I do:
#define GL_GLEXT_LEGACY //should prevent old glext.h from being included
#define GL_GLEXT_PROTOTYPES //should make glActiveTexture be defined
#include <qgl.h>
#include "glext.h" //local up-to-date glext.h
#include <QGLShaderProgram>
then make tells me that I have undefined references to glActiveTexture. If I include QGLShaderProgram before glext.h, then I still have that problem, but make also warns me that I am redefining quite a few things that are defined in both QGLShaderProgram and glext, so I know the latter file is being included. Any help would really be appreciated.
You are on a right path, but like Nick Meyer wrote, you need to get pointers to the functions at runtime.
There is a nice and clean example already in Qt installation directory, at least since 4.6. Check "Boxes" from "demos"-directory. There is glextensions.h/cpp that takes care of those required functions in Qt-way, using Qt's QGLContext etc.
If you're lazy like me, just hop over to
http://glew.sourceforge.net
and use that, no need to fiddle around with different header files and manually retrieving function pointers. It's as simple as
/* in every source file using OpenGL */
#include <GL/glew.h>
and
/* for each OpenGL context */
if( createGLContext(...) == SUCCESSFULL )
glewInit()
If you're using Qt you should probably use qmake - and just add
QT += opengl
to your qmake project file.