Search code examples
c++openglvisual-studio-2013visual-studio-expressfreeglut

Using OpenGL with Visual Studio 2013 Express


To give you an idea of what I am really trying to do. My goal is to create a c++ program in Visual Studio and using OpenGl display a blackscreen and a white dot in the middle of the screen.

Before I can even get to the coding part though, I have to include the OpenGL library somehow.

Looking at OpenGL documentation they say that it's already installed, I just need to initialize it.

I'd rather not have to do all the initialization work as it's already been done several times, such as FreeGLUT, but I have 2 real problems that I currently just do not understand.

1) How do I compile FreeGlut? I've downloaded the source code for FreeGLUT here http://prdownloads.sourceforge.net/freeglut/freeglut-3.0.0.tar.gz?download

I configured it with CMAKE into a visual studio 2013 compatible project. but once I open it with Visual Studio and try to compile it, I get a bunch of errors saying:

Error C1083: Cannot open include file: 'EGL/egl.h': No such file or directory   c:\freeglut-3.0.0\include\gl\freeglut_std.h 136 1   One_static

2) Once I get it compiled, how do I link it to my c++ project so that I can do

#include<FreeGLUT.h>

or

#include <GL/glut.h>

?


Solution

  • Most likely CMake did configure it wrong; EGL is used in embedded systems (think Android, set-top boxes, and such) not Windows. Double check that CMake does something sensible there.

    After you've built FreeGLUT copy it somewhere convenient (do not copy it into the Visual Studio installation directory) and add the directories where you placed FreeGLUT to your own OpenGL project's compiler and linker search paths (reachable in the Visual Studio Build configuration).

    Personally I place customly built libraries at

    C:\local\include\ (the header files)

    and

    C:\local\lib (the .lib, .a and .dll files)

    I also tend to give libraries an architecture infix like x86_32 or x86_64. e.g. freeglut-x86_64.dll. It's unlikely Windows will ever get some kind of "fat binary" in which the code for several architectures can be merged.

    For convenience put the DLL path into the system search path for DLLs. When deploying your program copy the required DLLs into the same directory as the EXE files.