Include OpenGL Libraries in C++, Windows 7 - c++

I am reading through a "Getting Started with OpenGL" tutorial and I came across this text:
"If you are using C/C++, then you must first set up a build environment (Visual Studio project, GNU makefile, CMake file, etc) that can link to OpenGL. Under Windows, you need to statically link to a library called OpenGL32.lib (note that you still link to OpenGL32.lib if you're building a 64-bit executable. The "32" part is meaningless). Visual Studio, and most Windows compilers, come with this library."
I am just trying to write my source files using vim, I don't want to use an IDE like VS, and from my understanding the OpenGL libraries come with Windows 7 (correct me if I'm wrong). After this point the article doesn't really go into any more detail about how to include the OpenGL libraries, and my real question is, how do I include and use the OpenGL libraries in my source files?
Is it as simple as writing #include <name of lib> or do I need to do something else with my Programming environment like editing my path variables?
Edit: I'm using the MinGW g++/gcc compiler

To get access to the include files, you need a special support library. There are more than one of these, but I would recommend GLEW. You can find the GLEW interface at http://glew.sourceforge.net/.
The reason for this is that only a very old version of OpenGL headers are available as default on Windows. The newer interface is available indirectly; you have to ask for function addresses. This is however done by GLEW for you.
So you only have to include < GL/glew.h>, and do some initialization with glewInit();
This is compatible with both Linux and Windows, especially as you use MinGW. When linking, I use the following:
MY_LIBS =
-lglew32
-lopengl32
-lWs2_32 -lole32 -lcomctl32 -lgdi32 -lcomdlg32 -luuid
I can recommend the use of a generic makefile, see http://sourceforge.net/projects/gcmakefile/
Notice that you also have to setup a context for OpenGL, before initializing GLEW. This is done differently depending on the environment. It is done when you open a window. For portable libraries, I can recommend the glfw library or freeglut.

Related

When using SetPixel undefined reference to `__imp_SetPixel' collect2.exe error is given [duplicate]

C++ GUI Tutorial: undefined reference to TextOut
I have the same problem, but I'm new to programming and Code::Blocks, and I want to use the GDI32 library. How can I install it? I'm very confused because I can use the windows.h header, but some functions like TextOut aren't available.
The gdi32 library is already installed on your computer, few programs will run without it. Your compiler will (if installed properly) normally come with an import library, which is what the linker uses to make a binding between your program and the file in the system. (In the unlikely case that your compiler does not come with import libraries for the system libs, you will need to download the Microsoft Windows Platform SDK.)
To link with gdi32:
This will reliably work with MinGW-gcc for all system libraries (it should work if you use any other compiler too, but I can't talk about things I've not tried). You can also write the library's full name, but writing libgdi32.a has no advantage over gdi32 other than being more type work.
If it does not work for some reason, you may have to provide a different name (for example the library is named gdi32.lib for MSVC).
For libraries in some odd locations or project subfolders, you will need to provide a proper pathname (click on the "..." button for a file select dialog).
You can create new with project win32 gui api it has default add library -lgdi32 -luser32 -lkernel32 -lcomctl32 -mwindows or add library -mwindows in your project, it worked for me.
At a guess, you used Code::Blocks to create a Console Application project. Such a project does not link in the GDI stuff, because console applications are generally not intended to do graphics, and TextOut is a graphics function. If you want to use the features of the GDI, you should create a Win32 Gui Project, which will be set up to link in the GDI for you.

Is there any way to export (static link) an SFML project made in Dev C++?

I've seen that there are only tutorials of static linking SFML projects for Code Blocks and Visual Studio, but there isn't one for Dev C++. What I basically want is the executable to be independent, without having to execute it in the IDE. Anyone has any idea? Is it possible? I'm currently using Dev C++ 5.11 with the MinGW 64 bit compiler and the 2.4.2 version of SFML.
Dev-C++ as well as most other IDE (Code::Blocks, Qt Creator, etc.) just provide a GUI to configure flags which will then be passed on to an underlying compiler.
As such you can more or less follow the Code::Blocks tutorial and just map the different GUI fields to the ones available in Dev-C++.
Essentially, make sure to use the libraries with the -s suffix and to define SFML_STATIC.
Here's an example image I found, as I don't necessarily want to install Dev-C++:
On the right side under "Linker" you can add the SFML static libraries (e.g. -lsfml-graphics-s) and under "Preprocessor Definitions" at the bottom you can add SFML_STATIC

Programming language that doesn't require a runtime/dependency to be installed

I want to know a programming language that doesn't require a runtime/dependency to be installed on the target system. My primary target is Windows XP and above.
I tried Autohotkey but it dosent have many advance functions.
Firstly, please confirm that does 'C++' requires to install a runtime/dependency on the target system is is Win XP or later. Secondly, please suggest me an alternative to C++ that doesnt require a dependency to be installed.
UPDATE: I will be using CodeBlocks! Does the C++ code compiled with that requires a dependency?
UPDATE: Sorry for the misconception, by CodeBlocks I mean the default compiler of CodeBlocks (ie: GNU GCC Compiler or MinGW).
Everything usually depends on the project, not the language. For example, programs compiled in Visual Studio's C++ uses some runtime libraries to work properly. However, you can configure the project in such way, that these libraries are included in the executable file, thus not needing additional dependencies. Delphi works similarly.
Here's the setting for Visual Studio Project:
If you choose option with "DLL", your program will require runtime DLLs. Otherwise it will be standalone, the runtimes will be incorporated into your binary file.
Edit: In response to question edit
I'll repeat myself: it depends on project, not the compiler or IDE.
If you want to create a program that does not require anything else in order to run, except for base operating system (no .NET, no Java, no Perl, no runtime libraries, etc), then your best bet is to use C or C++ and compile your program as single statically compiled executable.
It is rather difficult to achieve in practice, but it can be done.
Codeblocks is not a compiler, but an IDE, that can use different compilers.
The most common one is MinGW.
To complie with minGW so that all the standard libraries are statically linked you shold configure your project (see "project settings") so the the linker options include the -static flag.
You can even be more specific by stecifying
-static-libgcc
-static-libstdc++

Compiling dlib examples on Windows?

I'm fairly new to C++ (a long time Lisp programmer) and am trying to compile some of the examples for dlib on Windows using MinGW. I added dlib into the PATH. I then call g++ timer_ex.cpp from the examples directory. But I get a lot of error messages.
Short of using Visual Studio, what's the best way of compiling dlib examples on Windows?
Adding the folder to PATH usually doesn't work out well for me. Instead, try this command. I just compiled the example with it without error:
g++ timer_ex.cpp ..\dlib\all\source.cpp -I.. -luser32 -lws2_32 -lgdi32 -lcomctl32 -limm32
The somewhat cryptic -I.. adds the folder one level up to the include search path. This is the right thing to do assuming your haven't changed the folder layout. But in general this is the easiest way to add something to the compiler's include search path.
You also probably want to add the -O3 option which will tell gcc to produce optimized executables. Generally this makes the resulting application a lot faster, especially if you are doing heavy numerical work.
As an aside, you should consider installing CMake. It's a convenient tool which sets up a project like this for you. It works on Windows, Linux, Mac OS and many other platforms. To use it to compile the dlib example programs you would just have to say cmake . from within the example folder and then make. There is also a free version of visual studio which is quite nice, and as a bonus cmake can automatically create the project files for you.

Tool Chain for WxWidgets explained

Where can I find an writeup that shows me how to set up a tool chain for WxWidgets (C++) on linux/ubunto and/or OS X.
I downloaded, compiled & installed WxWidgets both on linux and OS X, compiled and tried the samples, but seem to be stuck setting up a compile environment in my own home directory.
DialogBlocks from http://www.dialogblocks.com looked promising, but it insists on recompiling WxWidgets again and again .. must be something about it I don't understand.
Writing code from scratch seems to fail due to a lack of paths to libraries, tools or whatnot .. again a lack og understanding on my part, I am sure.
So, can anyone point me to a tool chain setup, that has more than the bare minimum of instructions and fills in some of the "why" instead of only the minimal "what".
Like all C/C++ programs, the compiler has to know in what directories to look for include files, and the linker has to know what libraries it should link to.
The WxWidgets package, if installed correctly, includes the program wx-config. This can be used while compiling and linking, like so:
g++ $(wx-config --cxxflags) -c my_prog.cpp
g++ my_prog.o $(wx-config --libs) -o my_prog
I've found these two pages to be of help when setting up wxWidgets for Eclipse and MinGW.