Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Why must OpenGL projects be built? (CMake, premake, etc)

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    7

    Why must OpenGL projects be built? (CMake, premake, etc)

    Hi,

    As you might have already guessed I'm completely new to OpenGL, and graphics programming in general, and I have what might seem like a stupid question:

    Why do you have to build a workspace/project using tools like premake, CMake etc, in order to use OpenGL?
    A lot of tutorials says that you have to, but I have yet to find one that can give a good explanation as of why.

    And as an extension to that question, I wonder: Wouldn't it be sufficient to simply put all header files, code files, link libraries, and so on, in the appropriate folders and directories,
    and simply supply the compiler with the appropriate flags and search paths?

    I fail to understand why one cannot simply compile OpenGL applications like any other C/C++ application, are OpenGL applications, or any other graphics application for that matter, so different?

  2. #2
    Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    355
    You only have to link opengl32 to compile your project.
    Probably you are using program that are designed to be compiled on multiple platform. In this case CMake generate the project for your platform.
    Use project configuration is a good habit and it's a must on linux platform where every distribution have different development environment.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  3. #3
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    I fail to understand why one cannot simply compile OpenGL applications like any other C/C++ application, are OpenGL applications, or any other graphics application for that matter, so different?
    The purpose of, for example, a tutorial is to get someone up and running quickly. The fastest way to do that is to give them code that comes with a working build system. And since everyone has their own build systems, the most effective way to provide a working build system is to use a build system that works with any other build system.

    See, you seem to like just compiling from the command-line. That's great... for you. Most other programmers, especially new ones. do not. They want some GUI application that they can just run. They want a ready-made makefile that they can download and make. And so forth.

    They don't want to have to be told, "This tutorial requires these dependencies, so download them all, compile them, include their headers in your compiling command line, then include their libraries in your linking command line, etc." So we provide them with a safe, simple, and effective alternative that is easy to use and works all the time.

    Personally, even if you're comfortable compiling stuff from a command-line, you really should use some form of build system. If you make anything larger than a few files, it really helps.

    And as an extension to that question, I wonder: Wouldn't it be sufficient to simply put all header files, code files, link libraries, and so on, in the appropriate folders and directories,
    and simply supply the compiler with the appropriate flags and search paths?
    No. There is no "the compiler". There are many compilers, used by many different people. Windows has Visual Studio and GCC by way of MingW. These use two completely different command-lines. Things are more standardized on Linux, where Clang and GCC use the same options.

    And how would you "supply the compiler with the appropriate flags and search paths?" Even if you pick a compiler, the most this would be would be a batch/script file of some sort. That's a very difficult thing to write and maintain. And considering that there are very good build systems out there that turn what would be long, complex build scripts into what may be 30-lines of easily maintainable code... I see no reason why someone would even want to do that.

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    7
    Thanks for the two answers.

    Alfonse, I can see how this makes sense for the purpose of making an universal tutorial, that it makes it incredibly much easier to accommodate for the many different setups the ones following the tutorial might have.

    However if I were to build my own application, independent of a tutorial that is, would it be necessary to use third-party utilities like CMake and premake then?
    As I in that case would build an .exe file, with my compiler, that would at the very least be able to run under the same platform it was developed on, be it windows, OSX, or one of the particular linux-distributions.

    I guess my question could be rephrased to wether this would be a necessity when you are developing something yourself, and not following the prewritten code provided by a tutorial.

    I'm currently using Code::Blocks as an IDE, and I don't know how this works for other IDEs, but in Code::Blocks it's quite simple to configure your own compiler, provided you have some knowlegde about the API and your compiler, to handle APIs like OpenMP, OpenGL and so on when building the .exe.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    7
    Thanks for the answers.

    Alphonse, I do of course see that tools like CMake and premake make good sense to use for a tutorial in order to accomodate for the many different setups people following the tutorial might have.

    However, maybe I should rephrase my question into wether this is a necessity when developing something yourself, and not simply copy-pasting code from a tutorial?

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    However, maybe I should rephrase my question into wether this is a necessity when developing something yourself, and not simply copy-pasting code from a tutorial?
    Of course not. You can use whatever build tools you want. So long as you know how use them and which libraries you need to link with.

  7. #7
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    7
    Ok, thanks for helping me get some clarity on this subject.

    Since I'm new to Graphics programming I did get a little confused when every online tutorial said you have to use tools like CMake and premake, as I have never really needed any third-party tools for plain C/C++ programming.
    I think tutorials should mention that it isn't a necessity for the purpose of graphics programming itself, when it isn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •