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.
-
Are you talking about [this SDK?](http://glsdk.sourceforge.net/docs/html/index.html) If so, it has [instructions on how to use it for projects, both with Premake and without.](http://glsdk.sourceforge.net/docs/html/pg_use.html) – Nicol Bolas Nov 25 '11 at 03:51
-
Yes that SDK< however the instructions there do not give much information on the premake file and what I need to do with premake, vs2010, and the lua file. – user1032369 Nov 25 '11 at 04:01
-
@user1032369 call premake with the right parameters and then you get a `*.sln` file, usually in a folder called `vs2010` if you generated it for that system – PeterT Nov 25 '11 at 04:04
-
1@user1032369: As the docs say, "You can use them as part of a project that uses Premake, or you can use them in a project that directly uses native build systems." If you don't normally work with Premake4 (and therefore aren't very familiar with it), then you should skip to the section that talks about how to natively add the libraries to your project. – Nicol Bolas Nov 25 '11 at 04:07
-
Yes I know, I have tried the second option in the instructions, after several hours of trying to figure out how to do these things, I finally did all the things it said, and that did not work. Besides, it would take a long time anyway to do that on each project, I would like to learn it the premake way. – user1032369 Nov 25 '11 at 04:14
-
@PeterT I know how to call it with the vs2010 parameter, but dont I need to put some files in the folder first? And after Ive done the premake thing do I have to alter the Lua code? – user1032369 Nov 25 '11 at 04:16
-
@user1032369: "after several hours of trying to figure out how to do these things, I finally did all the things it said, and that did not work." *What* didn't work? What did you try to do, and what errors did you get? Are you familiar at all with configuring a Visual Studio build project? I could help you fix those problems, but you have to tell us what those problems are. Your current question is the exceedingly broad, "How do I use Premake4?" Which is a question that is probably best answered by [Premake4's documentation](http://industriousone.com/what-premake). – Nicol Bolas Nov 25 '11 at 04:29
-
I am sorry I am being vague, but frankly the directions on how to do these things were exceptionally vague as well and I am too tired to give every specific. When I tried to run an opengl application, it couldn't find the files from my #include statements. I never asked "How do I use Premake4?", So i have no idea why you quoted that, I simply need to know this: If I have the SDK elements properly installed, how can I create a new project, from start to finish, using premake 4 and which will allow me to use the opengl libraries provided in the sdk. – user1032369 Nov 25 '11 at 04:34
-
@user1032369: I quoted that because that's what your question *translates* to. You don't know how to use Premake4 to set up a project. Therefore, if you intend to use Premake4 to set up a project with the SDK, you need to know how to use Premake4 to set up a project, of any kind. Once you know that, then you can follow the steps for how to use Premake4 to set up a project with the SDK. And the instructions aren't vague; they simply assume that you already know how to set up a project. It tells you what you need to do specifically for the SDK. It's not a "my first project" step-by-step guide. – Nicol Bolas Nov 25 '11 at 05:06
-
But it is vague! The premake tutorial is very difficult to understand, just look in the comments: "Right here, you need to say what file this actually goes into. In fact, I've read about 10 pages and not once do you mention the file anything goes in. It's just all disconnected blobs of lua floating on a web page." I understand it wasnt for first time beginners, but the fact is there is not enough information on how to make these projects on either the premake or the Opengl page. I simply need to know what I need to do, and i can not find anywhere that gives a real, step-by-step tutorial. – user1032369 Nov 25 '11 at 05:13
1 Answers
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 project
s. 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
.

- 449,505
- 63
- 781
- 982
-
Im getting random errors when I build when I dont think there should be. I am really to tired for now, so Im giving up for the night. I think ive annoyed you enough already with my questions, so I wont bother asking you about the ones I have because I know your probably sick of hearing from me. Might just give this whole venture up, I have followed every single step word for word a million times with OpenGL, and every time I get some error that no matter how hard I research I cant find crap about. -.- (Just so you know the errors are on step 2, there little errors I have never seen before.) – user1032369 Nov 25 '11 at 06:31
-
@user1032369: Sadly, the Force has not given me clairvoyance enough to know what your errors are unless you tell me. I cannot help you unless you tell me what problems you're actually having. Perhaps you could put this in another Premake-specific question, rather than doing it in comments here (this isn't a forum). If you do, please state exactly what you're doing, with all relevant files, and exactly what errors you get when you try to build. The more information you give, the more likely we are to be able to help you. – Nicol Bolas Nov 25 '11 at 06:36
-
I posted that comment last night because I simply could not get step 2 working and It was 1:30 AM so I was not going to slave over my errors. I will post a new question with my problems now. I know this isn't a forum, you were the one that kept replying to my comments. – user1032369 Nov 25 '11 at 16:25
-
The new [question](http://stackoverflow.com/questions/8272102/creating-static-library-and-linking-to-it-with-premake). – user1032369 Nov 25 '11 at 17:34