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!
Related
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.
I have a code in Visual studio that I want to implement in Arduino. But there is a problem. Many libraries usable in Visual Studio aren't usable in Arduino IDE. How can I use them in my Arduino code. To be precise, the libraries I want to use are
#include <iostream>
#include <iomanip>
#include <queue>
#include <string>
#include <math.h>
#include <ctime>
respectively.
Okay so I know I have <iostream> available in Arduino. <math.h> is also available I think along with <string> library.
The main problem is to how to use #include <queue> and its functions such as priority_queue() and other fucntions of iostream like .pop()?
Arduino behind the scenes is using the avr-gcc compiler, which provides support for many of the features of the C++ language. It does not, however, include an implementation of libstdc++, which means that a lot of the libraries and features you are used to having with other development environments are just not there. A big reason for this is that it is just not practical to implement some of that functionality on a small microcontroller.
There are several libraries available that implement simplified versions of some of the functions and data structures you are wanting to use. You can find a list (but not necessarily a complete one) of these libraries here:
http://playground.arduino.cc/Main/LibraryList
For example QueueList might be a good alternative to <queue>.
Whatever you find, you are likely to have to refactor your code to use them. When you run into problems implementing those libraries and changes, I would recommend heading over to https://arduino.stackexchange.com/ to get more arduino specific answers.
It is detailed over here:
https://www.arduino.cc/en/Hacking/BuildProcess
The include path includes the sketch's directory, the target directory
(/hardware/core//) and the avr include directory
(/hardware/tools/avr/avr/include/), as well as any library
directories (in /hardware/libraries/) which contain a header
file which is included by the main sketch file.
And these are the libraries supported by avr-gcc (the compiler that Arduino uses)
http://www.nongnu.org/avr-libc/user-manual/modules.html
I'm developing a software on an Arch Linux platform with NCurses. It has an #include <ncurses.h> in a global header.
My collaborator works in Windows and emulates a bash shell with Cygwin. However, cygwin installs ncurses libraries such that you have to use #include <ncurses/ncurses.h>. It's trivial to change, but our Git history could consist of that line changing back and forth multiple times if one of us forgot which seems silly.
Is there some kind of preprocessor check I could do to use the appropriate path?
As #BoBTFish said, you should specify the include path in the Makefile (different for each platform). If not, you can use the macro __CYGWIN__ (or __CYGWIN32__, not sure which one will work) to detect if you're using cygwin, like
#ifdef __CYGWIN__
#include <ncurses/ncurses.h>
#else
#include <ncurses.h>
#endif
See http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/predefined-macros-platform.html for more details.
'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.