OpenGL SDK 如何使用 Premake 创建新项目

发布于 2024-12-18 05:24:30 字数 348 浏览 1 评论 0原文

我最近开始学习 OpenGL,以开始使用 C++ 制作一些图形应用程序。我已经安装了 OpenGL SDK,并且能够在其上正确构建项目。然而,在 OpenGL SDK 网站上,几乎没有关于如何使用 SDK 的元素(例如 freeglut 等)创建新项目的信息。我有 Premake 4.0,并且我知道我必须对lua 文件,但是我不了解 lua,也不知道如何使用 Lua 文件创建新项目。那么你能帮我一下吗?我使用的是 VS2010,我应该创建项目,然后用 premake 做一些事情吗?或者创建某种 lua 文件,然后使用 premake ?任何帮助都会很棒,因为我非常迷失,并且真的很想开始使用 OpenGL。我对此进行了很多尝试,例如从 sdk 复制 lua 文件,但没有成功。

I have recently begun the process of learning OpenGL to start making some Graphical applications using C++. I have installed the OpenGL SDK and I am able to build the projects properly on that. However, on the OpenGL SDK site there is little to no information what-so-ever on how to create new projects using the elements of the SDK, such as freeglut etc. I have Premake 4.0 and I understand I have to do something with the lua files, I do not know lua however and am not sure how to use the Lua files to create a new project. So could you help me out? Im using VS2010, should I create the project, then do something with premake? Or create some sort of lua file, then use premake on that? Any help would be wonderful because I am very lost, and would really like to get started with OpenGL. I have experimented a lot with this, such as copying the lua files from the sdk, but that came with no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深爱成瘾 2024-12-25 05:24:30

如果您不熟悉 Premake4,那么我强烈建议您直接使用 Visual Studio 项目。如果您遇到问题,请准确地修改您的问题,具体说明您所做的事情以及 Visual Studio 在尝试构建时向您提供的错误消息。您应该包括:

  • 包含路径。 完整包含路径集,包括完整的绝对目录名称(包括项目和解决方案文件的路径)。
  • 静态库搜索路径。
  • 您包含的静态库。
  • 您正在构建的定义。

注意:如果您不知道其中任何一个是什么,那么您需要停下来并了解有关 C++ 项目如何工作的更多信息。您需要了解编译器如何处理包含路径、静态库、#defines 等。


如果您不熟悉 Premake4,并且仍想将 Premake4 与 SDK 一起使用,那么您首先必须成为熟悉 Premake4,无需 SDK。我可以给你一个完整的 premake4.lua 脚本,你只需插入它,更改几行,一切就会神奇地工作(如果你想要的话,你可以看看 SDK 的示例是如何构建的。具体来说,示例/premake4.lua)。但如果我这样做,你就不会学到任何东西。您只是复制并粘贴代码,而对其工作原理没有丝毫了解。

因此,我将告诉您应该采取哪些步骤来学习如何使用 Premake4。

第 1 步:Hello World,Premake 风格。您应该创建一个 .cpp 文件作为 Hello World 应用程序。它只有一个标准的 main 函数,可以将“Hello World”打印到控制台。这是最简单的部分。

最困难的部分是 Premake4 脚本。您将编写一个 Premake4 脚本来构建该项目,而不是直接创建 Visual Studio 项目。

Premake4 文档可以引导您完成制作第一个解决方案和项目的步骤。您当然需要将文件添加到该项目。您还应该了解如何使用配置,以便您可以进行调试和发布构建。调试版本应该有符号,而发布版本应该进行优化。

第 2 步:多个项目。这里,您有两个 .cpp 文件:test.cppmain.cpp。在 test.cpp 中,放置一个打印某些内容的函数。该函数不应该接受参数或任何东西。在 main.cpp 中,您应该有 main 函数来调用 test.cpp 中定义的函数。还应该有一个 test.h,它具有 test.cpp 中定义的函数的原型。

这里的技巧是你没有将它们编译成同一个可执行文件。不直接。您需要两个项目:一个名为 test ,另一个名为 maintest 项目应该是一个静态库,它编译 test.cppmain 项目将是实际的可执行文件,它编译 main.cpp。它们都应在其文件列表中包含 test.h

在这里,您将了解到解决方案可以有多个项目。这两个项目有不同的文件列表。每个项目都可以有一个单独的 kind,它单独确定该项目的构建类型。 test 项目应该是 StaticLib,而 main 项目应该是 ConsoleApp

您还需要学习使用 links 命令将它们链接在一起。 main 项目应使用links 来指定testtest 不需要链接到某些东西。

第3步:掌握目录。

在这里,您将执行与步骤 2 相同的操作。除了一件事:将 test.htest.cpp 放在不同的目录中(当前的)。您还需要在该目录中有一个 test.lua 文件,您将使用 dofile 命令从主 premake4.lua 文件执行该文件。 test.lua 是您定义 test 项目的位置。使用 solution 命令创建解决方案后,您可以随时对 test.lua 文件调用 dofile

请注意,main 项目需要更改它找到 test.h 的目录。您还需要在 main 项目中使用 includedirs 命令告诉编译器在哪里搜索您包含的 test.h 标头main.cpp

第4步:回到SDK。现在,您应该已经足够熟悉 Premake4 了,可以回顾一下我向您指出的说明并更好地理解它们。然后,按照说明进行操作即可。当它告诉您脚本的第一行应该是什么时,请将其作为脚本的第一行。将 UseLibs 函数放在指定的位置;它甚至给你一个例子来说明它的去向。将 UseLibs 视为 linksincludedirs 的奇特组合。

If you are not familiar with Premake4, then I strongly advise you to just use Visual Studio projects directly. If you're having trouble with that, then please amend your question with exactly what you did, and exactly the error messages that Visual Studio gave you when attempting to build. You should include:

  • The include paths. The full set of include paths, including full absolute directory names (including the path of your project and solution files).
  • The static library search paths.
  • The static libraries you are including.
  • The defines you are building with.

Note: If you don't know what any of these are, then you need to stop and learn a lot more about how C++ projects work. You need to understand how compilers deal with include paths, static libraries, #defines, etc.


If you are not familiar with Premake4, and you still want to use Premake4 with the SDK, then you first must become familiar with Premake4 without the SDK. I could give you an entire premake4.lua script that you could just plug in, change a few lines, and everything would magically work (and if you want that, you could look at how the SDK's examples are built. Specifically examples/premake4.lua). But if I did that, you wouldn't learn anything. You'd just be copy-and-pasting code, without having the slightest understanding of how it works.

So instead, I'm going to tell you what steps you should take to learn how to use Premake4.

Step 1: Hello World, Premake-style. You should make a single .cpp file that is a Hello World application. It just has a standard main function that prints "Hello World" to the console. That's the easy part.

The hard part is the Premake4 script. Rather than creating a Visual Studio project directly, you are going to write a Premake4 script to build that project for you.

The Premake4 documentation can walk you through the steps of making your first solution and project. You will of course need to add files to that project. You should also learn how to use configurations, so that you can have a Debug and Release build. The Debug build should have symbols, and the Release build should be optimized.

Step 2: Multiple projects. Here, you have two .cpp files: test.cpp and main.cpp. In test.cpp, place a function that prints something. The function shouldn't take parameters or anything. In main.cpp, you should have the main function that calls the function defined in test.cpp. There should also be a test.h which has a prototype for the function defined in test.cpp.

The trick here is that you aren't compiling them into the same executable. Not directly. You want two projects: one named test and one named main. The test project should be a static library, which compiles test.cpp. The main project will be the actual executable, which compiles main.cpp. Both of them should include test.h in their file lists.

Here, you're learning that solutions can have multiple projects. The two projects have different file lists. Each project can have a separate kind, which determines the type of build for that project alone. The test project should be a StaticLib, while the main project should be a ConsoleApp.

You will also need to learn to use the links command to link them together. The main project should use links to specify test. test does not need to link to something.

Step 3: Mastering directories.

Here, you're going to do the same thing as Step 2. Except for one thing: put test.h and test.cpp in a different directory (a subdirectory of the current one). You also want a test.lua file in that directory, which you will execute from your main premake4.lua file with a dofile command. The test.lua is where you define your test project. You can call dofile on the test.lua file anytime after you have created the solution with the solution command.

Note that the main project will need to change the directory where it finds test.h. You will also need to use the includedirs command in the main project to tell the compiler where to search for the test.h header you include in main.cpp.

Step 4: Back to the SDK. At this point, you should now be familiar enough with Premake4 to look back at the instructions I pointed you to and understand them a bit better. Then, just do what the instructions say. When it tells you what the first line of your script should be, make that the first line of your script. Put the UseLibs function where it says to put them; it even gives you an example of where it goes. Think of UseLibs as a fancy combination of links and includedirs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文