codeblocks freeglut配置笔记

<span style="font-family: Arial, Helvetica, sans-serif;">1、 codeblocks中配置freeglut</span>

犹豫codeblocks中已经有了glut的模板了,只需要将其中的glut替换成freeglut即可。 为此我们要做的事情有两件,(1)、将freeglut的头文件和库文件复制到codeblocks中对应的目录去,(2)、改变glut模板中,对glut的引用为对freeglut的引用

具体的做法是:

从这个链接下载freeglut,按照自己的需求下载对应的版本:  freeglut Download

然后,将其中的内容全部复制到,codeblock主目录(主目录就是codeblock安装时,我们选择安装的路径了,在这个目录里,我们可以看到codeblocks.exe这个可执行程序)中的mingw,如果有重复的话,就直接覆盖。

再将freeglut.dll放到C:\windows中去(C盘是我这里的系统盘),到这里完成了第一步


然后,第二步就是,找到codeblock主目录下的share\CodeBlocks\templates\wizard\glut,其中有一个wizard.script 这个文件就是glut模板工程的脚本文件了,将

project.AddLinkLib(_T("freeglut"));
if (!VerifyLibFile(dir_nomacro_lib, _T("freeglut"), _T("GLUT's"))) return false;
这两句话,中的glut32修改成freeglut,这里已经改完了。
修改完成得文件是这样的。


//
// 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;
}


最后,就是修改templates文件夹下的glut.cbp了,

将这句话 <Add library="Glut32" /> 的Glut32改为 freeglut


修改完成后的文件是这样的

<?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>



到此 就配置完成啦。


参考链接; http://wiki.codeblocks.org/index.php?title=Using_FreeGlut_with_Code::Blocks

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值