Author Topic: Ubuntu GLUT/FreeGLUT Project Wizard  (Read 20970 times)

EyeOfMidas

  • Guest
Ubuntu GLUT/FreeGLUT Project Wizard
« on: December 24, 2012, 07:26:48 am »
So I wanted to install FreeGLUT and use Code::Blocks to develop with it. Unfortunately, the only project available is the GLUT Project, which is entirely not compatible with freeglut. All of the documentation is out of date, and the wiki is locked down so hard I can't even edit the discussion page. But I digress. The reason I am posting here is to save any developers trying to use Code::Blocks on Ubuntu (I am using 12.04 LTS but I imagine this will be more up-to-date than anything else I've found) in creating and running a GLUT project.

My solution is mostly a shotgun approach. These are the steps I took to make things work.

First, install:
Code: [Select]
sudo apt-get install g++ freeglut3 freeglut3-dev
create the file freeglut.cbp in /usr/share/codeblocks/templates/ and put in it:
Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="4" />
<Project>
<Option title="freeglut" />
<Option pch_mode="0" />
<Option compiler="gcc" />
<Build>
<Target title="default">
<Option output="freeglut.exe" />
<Option type="0" />
<Option compiler="gcc" />
<Option includeInTargetAll="1" />
</Target>
</Build>
<Compiler>
<Add directory="$(#freeglut.include)" />
</Compiler>
<Linker>
<Add library="freeglut" />
<Add library="glu32" />
<Add library="opengl32" />
<Add library="winmm" />
<Add library="gdi32" />
<Add library="user32" />
<Add library="kernel32" />
<Add directory="$(#freeglut.lib)" />
</Linker>
<Unit filename="main.cpp">
<Option compilerVar="CPP" />
<Option target="default" />
</Unit>
</Project>
</CodeBlocks_project_file>

This file is pulled from the wiki and slightly modified to use freeglut variables.

Now copy the /usr/share/codeblocks/templates/wizard/glut directory and contents to a freeglut folder in the same location.

You can either edit the wizard.script file inside this new freeglut directory to no longer reference glut32 and replace it with freeglut, or you could just replace the contents with this, which I've already done.

Code: [Select]
////////////////////////////////////////////////////////////////////////////////
//
// FreeGLUT project wizard
//
////////////////////////////////////////////////////////////////////////////////

// globals
FreeGlutPathDefault    <- _T("$(#freeglut)");
FreeGlutPathDefaultInc <- _T("$(#freeglut.include)");
FreeGlutPathDefaultLib <- _T("$(#freeglut.lib)");
FreeGlutPath <- _T("");

function BeginWizard()
{
    local intro_msg = _T("Welcome to the new FreeGLUT project wizard!\n\n" +
                         "This wizard will guide you to create a new project\n" +
                         "using the FreeGLUT OpenGL extensions.\n\n" +
                         "When you 're ready to proceed, please click \"Next\"...");

    local glutpath_descr = _T("Please select the location of FreeGLUT on your computer.\n" +
                              "This is the top-level folder where FreeGLUT was installed (unpacked).\n" +
                              "To help you, this folder must contain the subfolders\n" +
                              "\"include\" and \"lib\".");

    Wizard.AddInfoPage(_T("GlutIntro"), intro_msg);
    Wizard.AddProjectPathPage();
    if (PLATFORM == PLATFORM_MAC)
    {
        FreeGlutPathDefault="/System/Library/Frameworks/FreeGLUT.framework";
    }
    else
        Wizard.AddGenericSelectPathPage(_T("FreeGlutPath"), glutpath_descr, _T("Please select FreeGLUT's location:"), FreeGlutPathDefault);
    Wizard.AddCompilerPage(_T(""), _T("*"), true, true);
}

////////////////////////////////////////////////////////////////////////////////
// GLUT's path page
////////////////////////////////////////////////////////////////////////////////

function OnLeave_GlutPath(fwd)
{
    if (fwd)
    {
        local dir         = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
        local dir_nomacro = VerifyDirectory(dir);

        if (dir_nomacro.IsEmpty())
            return false;

        // verify include dependencies
        local dir_nomacro_inc = GetCompilerIncludeDir(dir, FreeGlutPathDefault, FreeGlutPathDefaultInc);
        if (dir_nomacro_inc.IsEmpty())
            return false;
        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("GL"), _T("freeglut.h"), _T("FreeGLUT's include"))) return false;

        // verify library dependencies
        local dir_nomacro_lib = GetCompilerLibDir(dir, FreeGlutPathDefault, FreeGlutPathDefaultLib);
        if (dir_nomacro_lib.IsEmpty())
            return false;

        if (PLATFORM == PLATFORM_MSW)
        {
            if (!VerifyLibFile(dir_nomacro_lib, _T("freeglut"), _T("FreeGLUT's"))) return false;
        }
        else
        {
            if (!VerifyLibFile(dir_nomacro_lib, _T("freeglut"), _T("FreeGLUT's"))) return false;
        }


        FreeGlutPath = dir; // Remember the original selection.

        local is_macro = _T("");

        // try to resolve the include directory as macro
        is_macro = GetCompilerIncludeMacro(dir, FreeGlutPathDefault, FreeGlutPathDefaultInc);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real inc path we had computed instead
            FreeGlutPathDefaultInc = dir_nomacro_inc;
        }

        // try to resolve the library directory as macro
        is_macro = GetCompilerLibMacro(dir, FreeGlutPathDefault, FreeGlutPathDefaultLib);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real lib path we had computed instead
            FreeGlutPathDefaultLib = dir_nomacro_lib;
        }
    }
    return true;
}

// return the files this project contains
function GetFilesDir()
{
    return _T("glut/files");
}

// setup the already created project
function SetupProject(project)
{
    // set project options
    if (PLATFORM != PLATFORM_MAC)
    {
        project.AddIncludeDir(FreeGlutPathDefaultInc);
        project.AddLibDir(FreeGlutPathDefaultLib);
    }

    // add link libraries
    if (PLATFORM == PLATFORM_MSW)
    {
        project.AddLinkLib(_T("freeglut"));
        project.AddLinkLib(_T("opengl32"));
        project.AddLinkLib(_T("glu32"));
        project.AddLinkLib(_T("winmm"));
        project.AddLinkLib(_T("gdi32"));
    }
    else if (PLATFORM == PLATFORM_MAC)
    {
        project.AddLinkerOption(_T("-framework GLUT"));
        project.AddLinkerOption(_T("-framework OpenGL"));

        project.AddLinkerOption(_T("-framework Cocoa")); // GLUT dependency
    }
    else
    {
        project.AddLinkLib(_T("glut"));
        project.AddLinkLib(_T("GL"));
        project.AddLinkLib(_T("GLU"));
        project.AddLinkLib(_T("Xxf86vm"));
    }

    // enable compiler warnings (project-wide)
    WarningsOn(project, Wizard.GetCompilerID());

    // Debug
    local target = project.GetBuildTarget(Wizard.GetDebugName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttConsoleOnly); // ttConsoleOnly: console for debugging
        target.SetOutputFilename(Wizard.GetDebugOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        target.SetWorkingDir(FreeGlutPath + _T("/bin"));
        // enable generation of debugging symbols for target
        DebugSymbolsOn(target, Wizard.GetCompilerID());
    }

    // Release
    target = project.GetBuildTarget(Wizard.GetReleaseName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttExecutable); // ttExecutable: no console
        target.SetOutputFilename(Wizard.GetReleaseOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        target.SetWorkingDir(FreeGlutPath + _T("/bin"));
        // enable optimizations for target
        OptimizationsOn(target, Wizard.GetCompilerID());
    }

    return true;
}

Now, edit the config.script file in /usr/share/codeblocks/templates/wizard and add the line:

Code: [Select]
RegisterWizard(wizProject,     _T("freeglut"),     _T("FreeGLUT project"),      _T("2D/3D Graphics"));
At this point, you should be able to start up Code::Blocks and click the FreeGLUT project wizard. When it asks where your FreeGLUT library is, just put in /usr. For me, the rest of the default values worked fine and I had some red 3D shapes spinning around in no time.

Let me know if anything in this post is missing, out of date, unnecessary or just wrong and I'll adjust it. Good luck for everyone else getting into C++ FreeGLUT development in Ubuntu Linux!

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9595
Re: Ubuntu GLUT/FreeGLUT Project Wizard
« Reply #1 on: December 24, 2012, 08:01:29 am »
...if I am getting things right here all you need to do is to run the GLUT wizard and exchange the name of the lib to link against from glut to freeglut, right?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Jesseee

  • Guest
Re: Ubuntu GLUT/FreeGLUT Project Wizard
« Reply #2 on: February 24, 2013, 07:39:02 pm »
I followed your steps, however now when i start a new freeglut project, after specifying /usr, a dialog box opens for the global variable editor, saying that "In the currently active set, Code::Blocks does not know the global compiler variable "freeglut". Please define it.  Any tips on how to fix this?

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7253
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Ubuntu GLUT/FreeGLUT Project Wizard
« Reply #3 on: February 25, 2013, 07:56:00 am »
The glut-wizard works fine with my freeglut-installation on fedora without any changes.
There is just one fix: when creating the global-compiler-variable glut, I have to define the library folder explicitely, because it's /usr/lib64 on my 64-system, but default is to search in basepath/lib.

With this setting the default wizard runs fine with freeglut instead of glut.
No need to fix any library name.

aj2014

  • Guest
Re: Ubuntu GLUT/FreeGLUT Project Wizard
« Reply #4 on: June 29, 2014, 03:15:02 am »
In case anyone is still looking for a solution to this problem, or a similar problem:  

On Kubuntu 14.04 (32-bit) the libraries are typically located in: /usr/lib/i386-linux-gnu/

In the input field where Code::Blocks (v 13.12) prompts "Please select FreeGLUT's location", enter:  

/usr/lib/i386-linux-gnu/  

Worked for me.  It compiled the sample app included in C::B and ran.  

I use Kubuntu 14.04 as a guest OS in VirtualBox 4.3.12 r93733 so it complained about magic 4 and vboxvideo -- but it works.  


A copy (or link) is also located in /usr/lib/i386-linux-gnu/mesa/ -- which seems sensible 
« Last Edit: June 29, 2014, 03:43:43 am by aj2014 »

Gilgamesch

  • Guest
Re: Ubuntu GLUT/FreeGLUT Project Wizard
« Reply #5 on: November 10, 2016, 11:16:47 am »
thx alot for this guide it really helped me getting it done however there was a small error in it which kept me getting errors like "failed to lunch the wizard"
Quote
Now copy the /usr/share/codeblocks/templates/wizard/glut directory and contents to a freeglut folder in the same location.
copy just the content of the glut folder into freeglut not the folder itself