• Advertisement
Sign in to follow this  

SDL Tutorials in C++

This topic is 4793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've taken a look at the SDL tutorials at Cone3d and they are in C. Sadly I dont know much C. So is there any tutorials out there written for SDL in C++?

Share this post


Link to post
Share on other sites
Advertisement
I am starting to do some tutorials on my site that will use no C output and input functions at all. The link is in my sig. Actually there is only one on there right now but I am doing another right now.

Share this post


Link to post
Share on other sites
The Cone3D tutorials are C++ - some of the later tutorials use classes and such but they are written in a C fashion for the most part. For some other tutorials beside those listed is this one.

Share this post


Link to post
Share on other sites
Just replace printf with cout. You should be able to understand it anyways, he uses some c functions but you should get the SDL part fine.

Share this post


Link to post
Share on other sites
Okay, the compilier is telling me there is a syntax error in the header file.
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\HP_Owner\Desktop\C++\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\HP_Owner\Desktop\C++\Makefile.win" all
g++.exe -c SDL.cpp -o SDL.o -I"C:/Dev-Cpp/include/c++/3.3.1" -I"C:/Dev-Cpp/include/c++/3.3.1/mingw32" -I"C:/Dev-Cpp/include/c++/3.3.1/backward" -I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include" -I"C:/Dev-Cpp/include"

In file included from C:/Dev-Cpp/include/SDL/SDL.h:39,
from SDL.cpp:4:
C:/Dev-Cpp/include/SDL/SDL_audio.h:97: error: syntax error before `[' token

SDL.cpp:14:2: warning: no newline at end of file

make.exe: *** [SDL.o] Error 1

Execution terminated

Theres what it looks like.

Adam


edit: Also, why is it always giving me a warning about no newline at end of file?

Share this post


Link to post
Share on other sites
What do you mean where did I get the code from, and what do you mean by Just hit enter after this }?

If you are asking what I think you are, I got the code from Rob Loach's website, but it's giving me syntax error IN the header file, the syntax error is in SDL_audio.h.

Share this post


Link to post
Share on other sites
Sometimes you get that after doing a copy paste from another source like a web page. A small suggestion is make a directory in the root of C or which ever drive instead of using files deep in your desktop. What I do is make a c:\Source directory and then make directories inside that.

Also are you using DevCpp? if so have you install the SDL package. Also if you have you need to specify #include "SDL/SDL.h"

Let us know if any of that helps.

=)
Fud

Share this post


Link to post
Share on other sites
I use Dev CPP, and downloaded the SDL package, and typed in stuff all my self, because I dont fell like copy pasting, and then having to delete out all the text in between so for the first time ever, I typed it myself =) I also included SDL/SDL.h

Share this post


Link to post
Share on other sites
OK that sounds good so far, can you leave me the link or IM me and I'd be more than happy to help.

Fud

Share this post


Link to post
Share on other sites
http://robloach.net/projects/tutorials/sdl/initializesdl/

the source i got is:
[source lang = "cpp"]
#include <iostream>
#include <SDL/SDL.h>
using namespace std;
int main() {
if(SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) < 0) {
cout<<"Unable to initialize SDL."<<endl;
SDL_GetError();
}
atexit(SDL_Quit);
return 0;
}


Share this post


Link to post
Share on other sites
Chnage your main to:

int main(int argc, char** argv)

instead of int main.

That Should do and have SDL.DLL so you can run it.

Hope that works for you

Fud.

Share this post


Link to post
Share on other sites
It works for me, when you pick a new project do you select Multimedia SDL?

Fud

We should take this offline, people don't need to see every response. =)

Fud

Share this post


Link to post
Share on other sites
Meta Adams, I assume you are using SDL 1.2.8? If so, the bug apparently lies in the GCC parser.

In SDL_Audio.h, remove SDLCALL (which is what is tripping up GCC - double click the error report and you should be taken to the concerned line) from the lines generating the error.

Recompile and link. Hopefully, that should do the trick.

If all else fails, revert back to 1.2.7.

Share this post


Link to post
Share on other sites
Error fixed, I had to update SDL again from Dev C++ for some reason, but its fixed now, and thanks for the help =)

Share this post


Link to post
Share on other sites
Well poop, now I am getting a linker error undefined reference to SDL_main in function console_main. Even though I started an SDL project, and after that went and readded it to the linker... after i got the error, and am now still getting it.

Share this post


Link to post
Share on other sites
I know this is going to be annoying if I post this, but I can't hold out any longer. Can anyone help me with this linker error, because I have tried so many things to make it go away, and it just won't?

Share this post


Link to post
Share on other sites
Nevermind, problem fixed, I did int main(), by habit and it was int main(int argc, char* argv[])

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement