GLEW and Freeglut won't work together? - opengl

I am trying to use geometry shaders in my OpenGL application that is currently using Freeglut, and I am trying to use GLEW to do that because as I understand it, the geometry shader functionality is in an extension. My include order is as follows:
#define GLEW_STATIC
#include <glew.h>
#include "freeglut.h"
However when I do this I get lots of linker errors like the following:
error LNK2001: unresolved external symbol ___glewAttachShader
I do not receive any errors when I only use the basic OpenGL functionality (that it, things that are not in the extensions) so I know that the compiler is finding all the "basic" libraries like glu32 etc. I am using Visual Studio 2008. Any suggestions?

It's a linker error that says it did not find a glew entrypoint.
Link against the glew library (you did not see the error before because you did not use any extension, I assume).
Edit:
Actually, this is directly related to your usage of "GLEW_STATIC".
From the GLEW page:
On Windows, you also have the option of adding the supplied project file glew_static.dsp to your workspace (solution) and compile it together with your other projects. In this case you also need to change the GLEW_BUILD preprocessor constant to GLEW_STATIC when building a static library or executable, otherwise you get build errors.
What this says is that it is your responsibility to build and include the glew source files when you use the GLEW_STATIC setup.

Related

Direct2D Only Partially Linking in C++ Builder

I've got a C++ Builder (Rad Studio Berlin) project setup to use Direct2d. Canvas drawing works just fine with the TDirect2DCanvas which would indicate Direct2D is linking properly. Everything renders smoothly. However, I need to use a matrix. I get linking error when I try to. For example, when try I:
canvas->RenderTarget->SetTransform(D2D1::Matrix3x2F::Rotation(15.0, D2D1PointF(100, 100)));
...I get the following linking error:
[ilink32 Error] Error: Unresolved external 'D2D1MakeRotateMatrix' referenced from C:\DP\TRUNK\SRC\CLIENTSIDE\APPLICATIONS\VIEWER\WIN32\DEBUG\MIMAGE.OBJ
C++ builder was supposed to already be setup to link against direct2d if I just include the headers. Can anyone help me link against the appropriate files in the C++ Builder way?
I found the solution from a different source. Here it is:
After some research, this issue has not been determined to be a bug.
For many of the standard Windows API functions, the IDE will add the correct library automatically so that the dependencies on the function references will be satisfied. With DirectX (which is somewhat uncommonly used), the IDE does not automatically supply the library which corresponds to the header file, so this is causing the unresolved linker errors.
The solution is to either (as I mentioned previously) add the D2D1.lib to the project, or statically reference it in code:
// as long as D2D1.lib is on the library search path, it should be found
#pragma comment(lib,"D2D1.lib")
Some developers add the above line of code to their headers and so all you need to do is include the header and all is well... the DirectX team did not do this and hence the unresolved linker errors.
Hope this clarifies the issue,

'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

unresolved external symbol using GLEW, SDL and OpenGL in VIsual studio 2010 express [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I'm using this OpenGL tutorial. I used SDL for the creation of my window and now i need to use glew (see the One more thing section on the bottom of the tutorial). But whatever i link, include, copy or define all i get is unresolved external symbol errors.
I have:
Linked my project to the GLEW Lib folder
Added the include folder to my include path
Copied the include,bin and lib files to the C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\ in the appropiate maps
copied glew32.dll and glew32mx.dll to my system32 folder
included and defined different files (see screenshots 2)
I will let the screenshots do the talking, what did i forget?
Screenshots:
were supposed to go here but due to the new user rule i can't include them here. Here is a link
I think that you need to link to glew32sd.lib or glew32s.lib (depending on debug or release build configuration), since you've defined GLEW_STATIC.
Here's a snippet from a pre-compiled header on a win32 glew application we finished recently. It shows the libraries we linked to:
#pragma comment( lib, "OpenGL32.lib")
#pragma comment( lib, "GLu32.lib")
#pragma comment( lib, "freeglut_static.lib")
#define GLEW_STATIC
#if defined _DEBUG
#pragma comment(lib, "glew32sd.lib")
#else
#pragma comment(lib, "glew32s.lib")
#endif
#include <GL\glew.h>
#include <gl\GL.h>
#include <gl\GLU.h>
Note that we used glew32s.lib and glew32sd.lib (the debug equivalent), which I believe is the static lib for glew.
If you have referenced the library and include folders correctly, the only other issue I can think of is that you may need the dll files to be copied into the output folder for your project.
So for example if your project builds to c:\MyProject\Debug\MyProject.exe, copy the dlls to c:\MyProject\Debug.
I hope this helps.
This may not solve your immediate problem but may help you dodge other incoming later. I don't know. What I provide is merely a recommendation of another resource for learning how to do what you asked about.
Now, I think your first link is broken, because it links to the screenshots for me. I was about to check out the tutorial but couldn't because of that.
Anyway, I've been using a book called OpenGL SuperBible 5th ed; which is very easily digested.
It sets out expecting you do not know anything about 3D graphics, how to include the libraries, create a window for your system etc. However, it goes into great detail without being overly hard to read for a long while. I finished the book in two weeks (well, during a holiday, doing nothing else).
I'm not affiliated to the book owner in any way, I just liked it a lot and it seems to me that what you're struggling with was graciously handled by it.

Difference between OpenGL files glew.h and gl.h/glu.h

I've built an OpenGL program with my glu and gl header files default included in windows 7 professional edition. Now, I've bought a book that describes OpenGL game development. The author of this book said, I have to include the glew header into my project. After I've done this I got some unresolved external symbol errors.
So, now I'm really confused.
I've worked earlier with glBegin and glEnd statements in my program. Now I've to work with glBindBuffers and glGenBuffer etcetera, but I get the unresolved external symbol errors, like that:
1>cWindows.obj : error LNK2001: unresolved external symbol __imp___glewBindBuffer
1>cMdlLoader.obj : error LNK2001: unresolved external symbol __imp___glewBindBuffer
1>cMdlLoader.obj : error LNK2001: unresolved external symbol __imp___glewBufferData
1>cMdlLoader.obj : error LNK2001: unresolved external symbol __imp___glewGenBuffers
Is there anyone here who can explain the difference between these header files and what I have to do with them?
I goggled many times, but on different sites there are much more confusing words like "glee" or "glut".
You're mixing up 3 different things here:
OpenGL
the GL Utilities (GLU) which are not part of OpenGL
and the GL Extension Wrangler (GLEW)
GLEW and GLU are completely different things and you can not replace one with another.
GL/gl.h are the base OpenGL headers, which give you OpenGL-1.1 function and token declarations, any maybe more. For anything going beyond version 1.1 you must use the OpenGL extension mechanism. Since this is a boring and tedious task, that has been automatized by the GLEW project, which offer all the dirty details packed up in a easy to use library. The declarations of this library are found in the header file GL/glew.h. Since OpenGL extensions don't make sense without basic OpenGL, the GLEW header implicitly includes the regular OpenGL header, so as of including GL/glew.h you no longer need to include GL/gl.h.
Then there's GLU, a set of convenience methods, which BTW are seriously outdated and should not be used in any modern OpenGL program. There's no modern GLU, so just forget about it. Anyway, it's declarations are made available by the header GL/glu.h (the one you were asking about).
The errors you get have nothing to do with include files though. Those are linker errors. Just including the declarations is only half of the job. The other half is linking the actual definitions and those are not in the header by the library file; libglew.so or libglew.a on a *nix OS, glew.lib or glew32.lib or glews.lib or glew32s.lib on Windows. If not using the static versions (those without the 's') you also must have installed the right DLL.
So to use GLEW you need to include the header and add it to the list of libraries in the linker options. Also you must call glewInit(); once you've obtained a OpenGL context in your program.
gl: This is the base header file for OpenGL version 1.1. That means if you want to use any functionality beyond version 1.1, you have to add any extension library on this.
glew: OpenGL Extension Wrangler Library. This is a cross-platform library for loading OpenGL extended functionality. When you initialize this library, it will check your platform and graphic card at run-time to know what functionality can be used in your program.
glu: This is OpenGL utilities library, which has been not updated for long time. Don't need to use this header file.
glut: OpenGL Utility Toolkit for Windowing API. This is good for small to medium size OpenGL program. If you need more sophisticated windowing libraries, use native window system toolkits like GTK or Qt for linux machines.
glfw: OpenGL Frame Work. Another multi-platform library for creating windows and handling events. FreeGlut can be used as an alternative. glfw is designed for game development.
glm: OpenGL Mathematics. It helps implementing vectors and matrices operations.
I am very new to OpenGL stuff, so please correct me if I'm wrong.

GCC SDL + GLEW linking errors

I have a static library in which I'm calling OpenGL extension functions via GLEW. As the project is being built in GCC (NetBeans 7.0), and GLEW's binaries are only shipped in Visual-C flavor, I have built GLEW (1.7.0) as a static library, with GCC. (I would also be interested why this is necessary, as GLEW seems to be pure C, in which ABI and cross-compiler compatibility isn't an issue AFAIK.)
In my static library I define GLEW_STATIC and NO_SDL_GLEXT as project preprocessor directives (-D), then I
#include "GL/glew.h"
#include "SDL/SDL.h"
The static library is then linked against in a (test) application, which also links against the following libraries, in the following order:
my_static_library
mingw32
glew32
opengl32
SDLmain
SDL
This setup gives me two undefined reference errors in my static library:
undefined reference to `_imp____glewGetStringi'
undefined reference to `_imp__glewInit'
Indeed, these are two calls made to GLEW functionality, in the static library. There are however other calls that the linker used to complain about (before -DGLEW_STATIC), yet seem to be ok now.
I wasn't able to improve the situation by swapping the order of linkage to opengl32 and glew32 (some more undef'd refs to wgl... calls). Furthermore, GLEW_STATIC (and NO_SDL_GLEXT) used to be defined in the test application but that has been removed and doesn't seem to matter.
Why do the remaining errors occur and what can I do to get rid of them, i.e. how can I use GLEW in GCC with SDL?
You library was built in such a way, as to link to the DLL version of GLEW - _imp____glewGetStringi and _imp__glewInit are import library symbols, i.e. the combination of defines resulted in the following line appearing when compiling;
extern __declspec(dllimport) PFNGLGETSTRINGIPROC __glewGetStringi;
This can happen if you don't define GLEW_STATIC while compiling your library (but you do; double check each object)
or
your version of GLEW has a bug in the headers. In GLEW 1.7.0 it works as expected.