Search code examples
c++openglvisual-studio-2013sdlfreeglut

Using SDL to make a simple game, struggling with linking everything together


I would like to attempt to make a simple game in c++.

So I found really cool series about how to make a game but the creator didn't include how to install different libraries etc.

So, in the tutorials, he gives us this code:

http://gynvael.vexillium.org/ext/vc/game.cpp

As a basic framework to make the game.

From now on I will list for you what I found out and what I think is the problem:

The problem is that when you just try to compile and run it, it will throw tons of errors at you etc.

I needed to link my project to SDL first, which I did and I think it works because there is no major errors or underlined code.

But then, there was a problem with the gl.h file.

So I have figured out that I need to install OpenGL libraries and link them to my visual studio project. I found out that I need FreeGlut and GLEW to run the piece of code from the link above.

So I have linked GLEW fairly easily with my project but there is a problem with GLUT.

Apparently, for unknown for me reason you have to compile the .lib file yourself. And that brought me to a whole new level of problems. So the newest version of GLUT (3.0) doesn't have the visual studio folder in it (In the tar file) so I cannot compile the newest version.

On the other hand, all the older versions have that visual studio folder which allows me to compile the freeglut.lib file and add it to my program's dependencies.

But when I do that, it comes up with an error: LNK1104: cannot open file 'freeglut.lib'

I have no idea why's that because I did everything exactly like in tutorials, multiple times.

I think that it could be because I got the newest version of GLEW, but old (from 2013 I think) version of GLUT, because the newest one doesn't have a folder with visual studio project to compile.

All I need is to make the code (from the link) work.

@EDIT~~~~~~~~~~~~~~~~~~~~~~~~

I have found out that my dependencies folder was in the wrong place and I moved it, instead of the problem with the freeglut.lib file, which seems like has been sorted out (I think I fixed it :D) I get like 5 new errors:

Screenshoot of the error log: http://puu.sh/hD6x5/d5fc1e1be6.png

but none of this rings the bell. Nothing happens either if I doubleclick it.


Solution

  • That error means that you need to link with these three additional libraries:

    • Glu32.lib
    • SDLmain.lib
    • SDL_Image library

    You may need to download and build SDL_Image, but the other two should already be part of Windows SDK and SDL respectively.

    Oh, and you need to not define a main() function in your own code. It's either the framework code you are using, or even SDL (IIRC) that is doing that for you.