Difference between revisions of "Using FreeGlut with Code::Blocks"

From Code::Blocks
m
m
Line 9: Line 9:
 
The freeglut ZIP file will contain this..  
 
The freeglut ZIP file will contain this..  
  
[b]freeglut_1 image you can see below.[/b]
+
[[File:Freeglut_1.jpg]]
  
 
copy all those files into the C:\Program Files (x86)\CodeBlocks\mingw folder. ( This is the folder where you see Include and Lib folders. This is important. ) If it asks you to overwrite folders, that's ok, say yes. It wont overwrite anything important.
 
copy all those files into the C:\Program Files (x86)\CodeBlocks\mingw folder. ( This is the folder where you see Include and Lib folders. This is important. ) If it asks you to overwrite folders, that's ok, say yes. It wont overwrite anything important.
Line 254: Line 254:
 
So yea.. run the demo right out of the original CodeBlocks code and you will see some red spinning objects. :)
 
So yea.. run the demo right out of the original CodeBlocks code and you will see some red spinning objects. :)
  
[b]freeglut_2 image you can see below.[/b]
+
[[File:Freeglut_2.jpg]]

Revision as of 11:12, 8 July 2011

NOTICE : This wiki page is being worked on and is not finished.

step one.. get freeglut. Latest binaries. Do NOT get only the source code. GET THE BINARIES. [ Example : freeglut-MinGW-2.6.0-3.mp.zip ] ( Think of it as Glut32 Binaries, which the source code to that is never available since its proprietary. ) Once you get the GLUT demo working, then you can play with the freeglut source code.

Make sure you install Code::Blocks with MinGW. Latest version. ( Installed with just the defaults and I am using Windows 7 64-Bit )

The freeglut ZIP file will contain this..

Freeglut 1.jpg

copy all those files into the C:\Program Files (x86)\CodeBlocks\mingw folder. ( This is the folder where you see Include and Lib folders. This is important. ) If it asks you to overwrite folders, that's ok, say yes. It wont overwrite anything important.

Now, copy, do not move, copy the freeglut.dll file that should now be in your C:\Program Files (x86)\CodeBlocks\minGW folder into your C:\Windows folder. ( The reason for this is because Windows is in your path, and to keep the confusion down, I just copy it to there. You can always change it later. ) It would be highly advised that you ADD the C:\Program Files (x86)\CodeBlocks\MinGW\bin folder to your path as well. ( If you do not know how to do that, you should not be programming )

So now you have copied the correct files and are ready to setup CodeBlocks.

So now, if you installed this on a 64Bit Windows, you should have a folder that has Program Files as a name but with the x86 on it too. Well that is where codeblocks installed too.

So now goto this folder : C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\templates\wizard\glut

in there you will see a file named wizard.script. Its this file where it is looking for Glut32. You just simply replace any reference to Glut32 with freeglut. And it really is that simple.

NOTE : USE NOTEPADD

Here is what it should look like.

wizard.script

////////////////////////////////////////////////////////////////////////////////
//
// GLUT project wizard
//
////////////////////////////////////////////////////////////////////////////////

// globals
GlutPathDefault    <- _T("$(#glut)");
GlutPathDefaultInc <- _T("$(#glut.include)");
GlutPathDefaultLib <- _T("$(#glut.lib)");
GlutPath <- _T("");

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

    local glutpath_descr = _T("Please select the location of GLUT on your computer.\n" +
                              "This is the top-level folder where GLUT 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)
    {
        GlutPathDefault="/System/Library/Frameworks/GLUT.framework";
    }
    else
        Wizard.AddGenericSelectPathPage(_T("GlutPath"), glutpath_descr, _T("Please select GLUT's location:"), GlutPathDefault);
    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, GlutPathDefault, GlutPathDefaultInc);
        if (dir_nomacro_inc.IsEmpty())
            return false;
        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("GL"), _T("glut.h"), _T("GLUT's include"))) return false;

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

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


        GlutPath = dir; // Remember the original selection.

        local is_macro = _T("");

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

        // try to resolve the library directory as macro
        is_macro = GetCompilerLibMacro(dir, GlutPathDefault, GlutPathDefaultLib);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real lib path we had computed instead
            GlutPathDefaultLib = 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(GlutPathDefaultInc);
        project.AddLibDir(GlutPathDefaultLib);
    }

    // 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(GlutPath + _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(GlutPath + _T("/bin"));
        // enable optimizations for target
        OptimizationsOn(target, Wizard.GetCompilerID());
    }

    return true;
}


This line "project.AddLinkLib(_T("Glut32"));" should now say "project.AddLinkLib(_T("freeglut"));"

Because of windows Protections, it will force you to save it somewhere else. Just save it to your desktop and then MOVE the file into the same folder as the old one and overwrite. It will ask for permission, click continue. ( or yes on some machines ).

Now.. one more file to edit and your done..

go to this folder by back tracking a little bit : C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\templates

in there you will find glut.cbp

This is the file that is for your project to work off of. You need to edit this too. Here is the code :

glut.cbp

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="4" />
	<Project>
		<Option title="glut" />
		<Option pch_mode="0" />
		<Option compiler="gcc" />
		<Build>
			<Target title="default">
				<Option output="glut.exe" />
				<Option type="0" />
				<Option compiler="gcc" />
				<Option includeInTargetAll="1" />
			</Target>
		</Build>
		<Compiler>
			<Add directory="$(#glut.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="$(#glut.lib)" />
		</Linker>
		<Unit filename="main.cpp">
			<Option compilerVar="CPP" />
			<Option target="default" />
		</Unit>
	</Project>
</CodeBlocks_project_file>

See this line "<Add library="Glut32" />" should now say "<Add library="freeglut" />"

Because of windows Protections, it will force you to save it somewhere else. Just save it to your desktop and then MOVE the file into the same folder as the old one and overwrite. It will ask for permission, click continue. ( or yes on some machines ).

So save those files and run codeblocks. Choose Glut. And where it asks where Glut is, point to : C:\Program Files (x86)\CodeBlocks\MinGW. It will find the glut.h file you need. It will ask you what compiler, I use GNU GCC Compiler. ( The name MinGW is not in the list for some reason. ) So yea.. run the demo right out of the original CodeBlocks code and you will see some red spinning objects. :)

Freeglut 2.jpg