I've been using OpenGL extensions on Windows the painful way. Is GLEW the easier way to go? How do I get started with it?
Yes, the OpenGL Extension Wrangler Library (GLEW) is a painless way to use OpenGL extensions on Windows. Here's how to get started on it:
Identify the OpenGL extension and the extension APIs you wish to use. OpenGL extensions are listed in the OpenGL Extension Registry.
Check if your graphic card supports the extensions you wish to use. Download and install the latest drivers and SDKs for your graphics card.
Recent versions of NVIDIA OpenGL SDK ship with GLEW. If you're using this, then you don't need to do some of the following steps.
Download GLEW and unzip it.
Add the GLEW bin path to your Windows PATH environment variable. Alternatively, you can also place the glew32.dll in a directory where Windows picks up its DLLs.
Add the GLEW include path to your compiler's include directory list.
Add the GLEW lib path to your compiler's library directory list.
Instruct your compiler to use glew32.lib during linking. If you're using Visual C++ compilers then one way to do this is by adding the following line to your code:
#pragma comment(lib, "glew32.lib")
Add a #include <GL/glew.h> line to your code. Ensure that this is placed above the includes of other GL header files. (You may actually not need the GL header files includes if you include glew.h.)
Initialize GLEW using glewInit() after you've initialized GLUT or GL. If it fails, then something is wrong with your setup.
if (GLEW_OK != glewInit())
{
// GLEW failed!
exit(1);
}
Check if the extension(s) you wish to use are now available through GLEW. You do this by checking a boolean variable named GLEW_your_extension_name which is exposed by GLEW.
Example:
if (!GLEW_EXT_framebuffer_object)
{
exit(1);
}
That's it! You can now use the OpenGL extension calls in your code just as if they existed naturally for Windows.
Personally I wouldn't use an exit command.
I would throw an exception so you can clear any other initialisation up at the end of the function.
ie:
try
{
// init opengl/directx
// init directaudio
// init directinput
if (GLEW_OK != glewInit())
{
throw std::exception("glewInit failed");
}
}
catch ( const std::exception& ex )
{
// message to screen using ex.what()
// clear up
}
And I agree with OJ - if you want to write tutorials for others, then this is really the wrong place for it. There are already a load of good places for opengl tutorials. Try this one for instance.
I lost some time, but finally I managed to get GLEW working.
I'm using Windows7 (x64), Eclipse CDT and MinGW, and the way is that:
Download MSYS (for MinGW) and rember to have MinGW installed correctly (PATH enviroinment variable set correctly):
http://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.10/MSYS-1.0.10.exe/download?use_mirror=freefr&download=
Once MSYS installed, go to:
http://glew.sourceforge.net/
and download the TGZ package, which is intended to use with UNIX systems
Then open the package (you can use 7zip as well) and find the "Makefile".
Open it and with a text editor (Notepad should work fine) find the row which contains "GLEW_DEST" and replace it with something like "GLEW_DEST ?= C:/MinGW"
Now you are ready to go, open MSYS (C:\MinGW\msys\1.0\msys.bat in my case) and in the shell opened, go to the folder where the "Makefile" is.
Then write a simple: "make install" and the work is done (at least for me it worked)
PS: I also copy-pasted glew-1.10.0-win32\glew-1.10.0\bin\Release\Win32 file's into my System32 folder, and in Eclipse CDT I added the library "glew32" in the linker option and added a #include <GL/glew.h> before #include <GL/glut.h>
Related
I am targeting GL Core Profile on Linux. When I directly use the system GL headers like so:
#include <GL/glcorearb.h>
...then everything works as expected, and I can use GL extensions too, e.g. glPushGroupMarkerEXT() calls.
But since I've integrated imgui, I have been forced to go through a GL Loader (I was not able to make imgui work without a loader.)
So I have followed the imgui examples, and now use gl3w.
Now that I go through gl3w, I can no longer use those GL extensions:
src/wld.cpp:373:2: error: use of undeclared identifier 'glPushGroupMarkerEXT'
I looked, but gl3w does not seem to come with a separate header for extension, like glew does: the glxew.h file.
Does this mean that I cannot use glPushGroupMarkerEXT() if I use gl3w as a GL loader?
Ok, so it wasn't mentioned in the README before (it is now, I created a pull rq) but there is a command line option to gl3w's generator script:
gl3w_gen.py --ext
When using the --ext flag, the extensions will be available in the generated GL/glcorearb.h header.
The gl3w packed with the imgui repository was generated without this flag, hence the extensions were not available.
I'm trying to use the png++ library. Already added it to the library search path in eclipse (windows user, if relevant), but I get the
fatal error: png++/png.hpp: No such file or directory
I really don't know what to do.
Thank you!
Okay. You need to check your settings one by one.
It (png++) is a C++ library, so you must have C++ compiler set in your
run/debug settings.
Add your library include folder to that compiler's settings
To actually link to the library, you need to add the .lib/.a files or DLLs to linker settings.
I'm not much of a user of Eclipse CDT but that's how it works. If you are trying to do image manipulation without prior C++ experience, I suggest you to go with python/Java, they are easy to use.
After days, tears and blood, my professor (PhD Daniel Brake) figured it out! Here is what we did to make it work. I hope you never need to use this library on a Windows machine (conf: Windows 10, MinGW, Eclipse):
Make sure that you have the MinGW installation manager, have all the packages on the basic setup installed, and in "all packages", look for "msys-zlib", class dll
Now open the cmd (Windows+x, A, to open in admin mode)
You have to open the "msys.bat", go to C:\MinGW\msys\1.0\msys.bat
It will open a unix-like terminal, then type:
mingw-get install libz-dev
cd /path/to/libpng/folder
./configure -prefix=/mingw
make
make install
Google png++, download it, and using the MinGW terminal go to the folder that contains it:
cd /path/to/png++/folder
tar -zxf png++-0.2.x.tar.gz -C
In the png++ page, go to http://savannah.nongnu.org/bugs/?46312 and donwnload the file to the png++ folder
Replace the error.hpp file
Using a text editor, open the error.hpp file you just downloaded
Add #include <sstream> to the includes
look for the part and comment it:
strerror_r(errnum, buf, ERRBUF_SIZE);
return std::string(buf);
Now, add this in the same block of above:
std::stringstream ss;
ss << errnum;
return ss.str();
Save and close
Now, open Eclipse, create the project for the png++
Go to Configuration > C/C++ Build > set Configuration to "Debug [Active]"
Then C/C++ Build > Settings > GCC C++ compiler, add to "Include paths (-l)", the path to the folder png++ and the path to the folder that contains the file png.h, in my case it's in "C:\MinGW\msys\1.0\mingw\include"
Go to MinGW C++ Linker > Libraries, add to "Libraries (-l)" just the word "png" and in the "Library seach path (-L)" the path to the folder of libpng.a, in my case, "C:\MinGW\msys\1.0\mingw\lib"
save
to use it, in the header, add #include <png.hpp> (not #include <png++/png.hpp>)
it will have a warning, you can ignore it
it doesn't works!
in your MinGW terminal, go to the folder that have the "eclipse.exe" and open the Eclipse that way (don't ask me, my professor said something about path, I have no idea why)
Maybe you can simply use another compiler, but I couldn't, or use Linux.
Firstly, I know this question has been asked many, many times; I have read at least five or ten variations, but none of the answers given worked in my case. I have the line:
helloWorld = SDL_LoadBMP("helloworld.bmp");
in the main.cpp file of my Xcode 5 project. The directory structure is as follows:
TestProject1
main.cpp
Resources
helloworld.bmp
TestProject1.1
TestProject1.xcodeproj
Of course, I have tried different paths, i.e. Resources/helloworld.bmp, and yes, the Resources folder is imported into the project. However, the statement returns NULL because (according to SDL_Error) it cannot find the file. Now, the line:
helloWorld = SDL_LoadBMP("/fully/qualified/path/to/helloworld.bmp");
works fine, so it is not a problem with my code. What is the generally accepted way to get Xcode to work with relative paths for resources? I am looking for a method that will be portable (to the platforms that SDL supports, ofc on different computers/devices) when I make a larger project, and am open to using a different IDE if Xcode cannot make portable C++ projects. Miscellaneous other things I have tried after reading other questions:
Adding helloworld.bmp to Build Phases > Copy Files.
Adding the code:
// ----------------------------------------------------------------------------
// This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
// error!
}
CFRelease(resourcesURL);
chdir(path);
std::cout << "Current Path: " << path << std::endl;
#endif
// ----------------------------------------------------------------------------
to the beginning of main.cpp (returns "Expected unqualified-id" compiler error on the if (!CFURL...) line).
Using an absolute path - as I said, this works, but I want portability.
Calling getcwd: this is C++ code. Is there something I am missing here? It doesn't seem like getcwd is a C++ function.
In your Build Phases you need to create a new build phase of type Copy Files.
Set Destination to be 'Resources' and leave Subpath blank unless you want to have a subfolder in your resources (can be useful when you have a lot and want to separate eg fonts, textures, sounds etc)
Leave Copy only when installing unticked
Then just add the resources to that build phase, in your case helloworld.bmp
You should then be able to load by doing:
helloWorld = SDL_LoadBMP("helloworld.bmp");
or if you used a Subpath:
helloWorld = SDL_LoadBMP("textures/helloworld.bmp");
This is the same sort of way you could bundle the SDL2.framework with your application. There is a tutorial here - http://zamma.co.uk/setup-sdl2-in-xcode-osx/ and in Part 3 it describes how to bundle the frameworks if you are interested.
Overal though the best way to do fully portable builds is going to be something like CMake or Gradle.
Trying to run the following:
#include<iostream>
#include<boost/filesystem/operations.hpp>
namespace bfs=boost::filesystem;
int main()
{
bfs::path p("second.cpp");
if(bfs::exists(p))
std::cout<<p.leaf()<<std::endl;
}
I got some errors in cygwin so I decided to try out netbeans, and used the following as a guide. I added all links and the following for filesystem Project -> properties -> Linker ->Libraries -> Add option -> Other -> -lfile_system as noted here. I have run a separate test using #include<boost/any.hpp> so I am not currently doubting that my boost is not installed correclty.
It seems weird to me that it is "file_system", so I also tried "filesystem" but to no avail.
When i hold Ctrl and click on #include<boost/filesystem/operations.hpp> my netbeans brings up my operations.hpp file so it seems okay (linked properly internally that it can "see" what I want it to see).
The solution to installing boost came in the following form:
1 - If you have any path variables that are being used for Visual Studio you should temporarily change the variable during installation. This is a good guide. Once that is done, this is one step completed.
2 - Download and install MinGW. This is a very easy process and you can find the installer files here.
Once you have done these things (if you are in the same situation as me), you will now be able to properly install boost.
Horay!
Using Boost with cygwin step by step
Create a new Project
It is better to take the names given here in this tutorial exactly. Later ask: It does not work, can then be easier to find.
I do not think I need to mention all T:\ must of course be replaced with your drive.
Project Name : Boost-cyg-Test
Now your Project should look like
Open main.cpp
Overwrite the generated code with the following. We want to that, first of all everything works without error.
Therefore, please do not use your own special code.
It is difficult to find a fault. Then told after several ask, to get:
I have used my own code
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;
int main()
{
path p("second.cpp");
if (exists(p)) { std::cout<<p.leaf()<<std::endl; }
}
In this section we assume that "boost" is already compiled.
goto Tools -> Options
Your C++ Code Assistance options should look something like this.
If this is not so, we should let Netbeans create that for us.
Add New Tool Collection
After we have completed this dialog with OK, we should find the settings shown above. ( C++ Code Assistance options).
Copy all libs into the right place
Let's create a new folder 'boost'.
With a search tool, search in your compiled Boost folder for *.a
My Boost is compiled with the shared option so we find :
For our short App. we need only 2 files.
libboost_filesystem-gcc45-mt-d-1_53.dll.a
libboost_system-gcc45-mt-d-1_53.dll.a
But if we're at it to copy two files, we can copy all files.
So mark all found .a files and copy them into the directory just created
T:\cygwin\lib\boost .
Now we do the same with our .dll files.
Mark all .dll files and copy it in your ?:\cygwin\bin directory.
If you only have compiled static librarys, you can skip this point.
Now it's time to modify our project settings.
As you can see i put my source Boost folder into cygwin
and
As we have already noted above, we need two .a files.
with Add Library navigate to T:\cygwin\lib\boost and select
libboost_filesystem-gcc45-mt-d-1_53.dll.a
libboost_system-gcc45-mt-d-1_53.dll.a
Now you'll notice that this name was shortened by netbeans to:
boost_filesystem-gcc45-mt-d-1_53.dll
boost_system-gcc45-mt-d-1_53.dll
This is somewhat confusing. It looks as if a .dll is standing here. But it is really a .a file.
Set a breakpoint in main.cpp. Now we start debug.
I have marked the important part, the two libs, with an arrow.
All libs are found and after make has finished, stops at the breakpoint.
The output:
Build Boost for Cygwin
For all who want to create boost with shared library itself.
Download boost_1_53_0.zip
Create a folder in your ?:\cygwin directory.
boost_1_53_0
Extract the zip file into that directory.
It should look like:
open a cmd window, cd to boost_1_53_0 directory.
To have a clean build we need a PATH that have only the cygwin home and bin.
In the cmd type.
SET PATH=T:\cygwin;T:\cygwin\bin
and test the path.
PATH
Type
bootstrap.bat
Type
.\b2 --build-dir=T:\boost-cyg toolset=gcc variant=debug link=shared runtime-link=shared
After some time the build is finished.
Now you have the same environment that we have used in the tutorial.
If you get a Error : gcc not found
copy (not rename) in ?:\cygwin\bin folder, for example : (names may differ).
i686-pc-cygwin-gcc-4.5.3.exe to gcc.exe
and
i686-pc-cygwin-g++-4.exe to g++.exe
Hope it helps you.
Could you paste the error you get when compiling ?
I am not used to compile programs in a Windows environment, but I think as Jesse Good suggested in a comment that you have a linker error.
You may solve it by using -lboost_filesystem instead of lfile_system.
To find out how your libs are called, you get the name of your lib (on my unix environment I have libboost_filesystem.so), strip the "lib" prefix and the ".so" or ".a" suffix (must be different in a Windows environment).
if your boost installation is correct and you are sure about it then for Unable to resolve identifier try Code Assistance->Reparse Project from context menu of the project. It tries to recover broken code model by reparsing project from scratch. if that didn't workout try closing IDE and removing code model cache.
p.s. do you have compilation errors?
I'm learning SFML library and i picked a code from the tutorial. it opens a window and it should make me able to close it again but when i close it it says
Debug Error!
Run-Time Check Failure #2 - stack around variable 'App' was corrupted.
and then the console stops working.
this is my code:
int main()
{
// Create the main window
sf::Window App(sf::VideoMode(800, 600, 32), "SFML Events");
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
// Display window on screen
App.Display();
}
return EXIT_SUCCESS;// = return 0
}
linking to the debug libraries are
sfml-system.lib
sfml-window.lib
sfml-system-d.lib//these are debug files
sfml-window-d.lib
if i ramove the first 2 and built my program it doesn't give errors but when i open it it says :
the application was unable to start correctly (0xc0150002). click ok to close the application
i have a 64 bit computer. and in microsoft vc++ 2010 i can do build solution or debug and i always do build solution.
and i am building in release mode but i have also tried both and they both didn't work
could someone please tell me what i could do to prevent this from happening or how this comes.
For these application startup issues,it is always a good idea to check if all dlls in the dependency closure are accessible - that is, are they all in the search PATH? We usually use dependency walker to check which dlls are missing, or use gflags for runtime diagnostic
While put your dlls with your exe in same folder works, it does not scale well, one way I usually do is put the library path in PATH environment variable.
And one thing to notice, sfml comes with prebuilt binrary for vs2005 and vs2008, as you are using vs2010, the underlying c runtime library(msvcrt) is different, there would be potential problems - you would better build sfml from source yourself using vs2010 or use vs2005/vs2008, just to be consistent
if you wouldnt like to use DLLs and would like to compile SFML into exe, here is tutorial:
2.0 http://www.sfml-dev.org/tutorials/2.0/start-vc.php
you need to add preprcessor directive SFML_STATIC , and include additional libs u are using in your program into linker -> input
I also had some related problems when I first time used this (and equivalent libs). Here is some points to take in count:
Do not use precompiled libraries/dlls. Learn how to use CMake, boost_build (boost libraries), Scons (mongoDB) etc. and build libraries according to currently used compiler/platform (of course if there is such possibility). After some time this process became pretty easy and simple and this will save a lot of time later for other projects.
Read SFML tutorials on making a simple project. They are easy to read and understand. May try to generate also examples with CMake and build them to see how they work. Another good tutorial is the book on SFML programming (which have a huge push on using C++11, which I think is great).
As pointed out add SFML_STATIC to "Preprocessor definitions" if don't want to use DLLs and I think is better to set "Windows (/SUBSYSTEM:WINDOWS)" in linker options (if I correctly understood from "and then the console stops working" statement).
Better to place libsndfile-1.dll and openal32.dll in release/debug folder where app is generated, from what I saw VC++ have a bad behavior on finding dlls from provided paths.