@Jackson9797 Hey there-- I'm going to be working on new beginner tutorials that are clearer and easier to follow. Because you find this tutorial confusing, you could be of immense help to me in ensuring that the new tutorial is NOT confusing.
Could you explain to me what you're having difficulty with?
my window opens and then stays open for a few seconds with a white screen rather than black and will then close by itself a few seconds later, iv gone over the code and have the same thing word for word... any ideas?
when I build it it just ses "pikcin - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...
is it just me or is this really really laggy? cos i try dragging the window around and it just freezes up. i'm thinking it's probably to do with having SDL_Flip in the loop. i'm using the g++ compiler on ubuntu
I don't know why the code given in the tutorial works for you, but I had to make a few tweaks. First, If I don't initialize the event before the loop (with the poll event function), the program will fail to run properly (maybe just cause i use visual studio, but idk). Second, after fixing that, leaving everything else as is, the program pops up as a full screen. to counter this, you can change your if statement to check for a true variable instead of a false one. Hope this helps :p.
You may want to check out the new Allegro 5. It is a HUGE leap forward from the Allegro 4 series and is an entirely new beast. It's a really nice library now. I liked it before, but now it is SO much better and modern, event driven and not as much of a CPU hog, has support for native interfaces, 3D acceleration, you name it... I like it MUCH better than SDL. It's just as portable as SDL as well, only it has sound, music, JPG, PNG, OGG etc... support built in.
Is it legitimate to use a function to free the SDL surfaces and to quit SDL, at the end of main? for example: void sdlCleanup() { SDL_FreeSurface(buffer); SDL_FreeSurface(screen); SDL_Quit(); } Also, the memory leaks you mention in one of your videos. Is the memory still allocated after you restart your OS? or would it then be freed? If i create an array of structures (for example: mystruct myarray[10][5];) would this memory need freeing? most greatfull for any help. great tutorial
@4Teddybears If the surfaces are in-scope when the function is called, then yes. However, if you're not passing the surfaces to the function, it won't know where it is (unless the surfaces are global, which is a really bad idea).
What I do is I have an "ImageManager" class, which stores an array of surfaces inside. When the class hits the destructor, it destroys all the surfaces.
amazing toturial this just explains everything, but hey, is c++ one of the best langauges to start with, cause java and flash are great for gaming too?, so is c++ best?
@razorbunny555 C++ is still used to make professional games today, but it is by no means the best language to learn for hobbyist programming. As a computer-science major in college, it's what we used, and what I had been learning for years.
@razorbunny555 They have a lot of similarities; the syntax is similar and they're both object oriented. So in a way, yes. But C++, Java, and C# all have their differences.
@razorbunny555 It depends on what you want to do. If you wish to create web based games you may prefer Java (or even learning to use Flash), but for PC games, C++ is common. If you learn C++ you can easily pick up C#, Java and many others. C# and Java are a lot like C++ and based on it so it's the best place to start and commercial games generally do use C++.
@NeilRoy65 i'm a great java programmer,, though i am getting 14 years old soon and i am learning java's for 2 years now, soo yeah, i might do java's for my work later on. it's the only thing i like. (other coding languages like c++ too!)
A good book to buy to get started is "Beginning C++ Through Game Programming". I picked this up through Amazon.ca, but I already have a good grasp of C programming (and I am still hesitant to use classes! lol) but this book made classes especially a lot easier to comprehend. You don't need to use them for allegro programming though, I've created a full game (Deluxe Pacman) with Allegro and mostly just C code with a little C++ flexibility. Just not classes. ;)
Is anyone using Visual Studio 2010? I get a runtime error when i create the SDL_Event variable and the compiler will complain that i am using an unitialized variable and i am copying it from the tutorial. I tried setting it eqaul to NULL but then its a compiler error. how do i initialize the event variable or is there another way to do this?
I have done The allegro version but im getting a [Build Error] [example.exe ] Error 1 please help!! :) I thing it has somthing to do with missing Dll file becuse I dont have enyone in my folder :( I want to run my exe!! :P
I think there is an error in the else particularly the SDL_SetVideoMove. I got a compiler error but when I changed it to SDL_SetVideoMode it worked fine. Thanks for the tutorial btw. I really wanna be a game programmer and this is a big help for me to start.
at 1:42 u have fullscreen set to false and you made it so that it will go to fullscreen mode when fullscreen is false and windowed mode when fullscreen is true.
i think this should explain why people are just seeing black screens and not a window like it is in the video
again I'm watching these videos to learn so you might know something that i don't and you did that on purpose :P
Wait, when I compile, it's just a big black screen with only my cursor, is that supposed to happen? Like I don't have a head bar like you do, it's just a black screen and all I could do is move my cursor. I have to hit the windows key to exit the program. Also is it a necessity to memorize all that code :P
@Soap360 Yes, at this point it's supposed to be a blank window.
No, you don't generally memorize the code. This is the point of Object-Oriented Programming. Put it in a class for you to reuse in all of your programs.
@ThePearI I think my comment was a bit vague there... What I mean is "What is the advantage of having a class for initializing?" I just have a function.
So this has been bugging me for a while but i have to ask; why do some console projects use int main (int argc, char *args[]) while other console apps just use void main(), what's the difference?
@Grenadiac111 The argc/args stuff is a throwback to when we used to boot programs from the prompt, and would throw it flags (or, arguments). They're not really used much anymore, and I don't really like using them in my prompt programs either.
Many IDEs require main to not be void, though, and some libraries (SDL...) require having the args/argv in main's header.
As console program typing in the stuff after SDL_Event makes the program run as a unresposive blackscreen without any X. Tried running as a win32 app instead but it just gave me a bunch of 'unresolved external symbol' errors
Getting comfortable with classes will make everything much clearer, but yes you can change it to anything you want as long as you remember what you changed it to.
having some trouble here, got to the end and have this error message "Error 1 fatal error C1083: Cannot open include file: 'SDL/SDL.h': No such file or directory..." any ideas on how to fix this?
Looks like you don't have the SDL library set up correctly. Make sure all the files are in the Include and Lib folders, and make sure the linker is set up.
it should be, you set it to fullscreen if the bool was false. if( fullscreen == false ) { buffer = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );} else { buffer = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE | SDL_FULLSCREEN );}
I am not actually a SDL expert, but i believe if you use:
SDL_Init(SDL_INIT_EVERYTHING);
atexit(SDL_QUIT);
//the code goes here
it would be better than:
SDL_Init(SDL_INIT_EVERYTHING);
// the code goes here
SDL_Quit();
because, there's a benefit of doing it this way, because if you detect an error somewhere, you can use the exit function and not worry about cleaning SDL, as the program will do it for you.
when ever I go to build my code (compile) I'm using codeblocks by the way... iI click build and it gives me a box saying yould you like to build this project since it has not been built yet.. I clikc "Yes" and the box pops up again! it also gives me an error saying "Linking Stage Skippied (build target has no objective fiels to link) Nothing to be done. Any idea what I forgot to do?
In Code::Blocks you have to add the files to the project, if you didn't already. In case you did, right-click the C++ file(s) and select 'Properties'. Then click on the 'Build' tab and check 'Compile file' and 'Link file'. Normally, this is done automatically once you add the file to the project.
Not nessecerally if your going to distribute your game youll need the DLL's in the game folder to distribute - worst thing ever when youve jsut installed a game and then BANG missing DLL :(
On Linux you're still able to use Code::Blocks, although there are other IDEs like Anjuta and KDevelop. The hardcore option, which is also available on Windows through MinGW, is to use Makefiles.
Just check lazyfoo for information about how to install SDL for Linux.
Confusing!
Jackson9797 2 weeks ago
@Jackson9797 Hey there-- I'm going to be working on new beginner tutorials that are clearer and easier to follow. Because you find this tutorial confusing, you could be of immense help to me in ensuring that the new tutorial is NOT confusing.
Could you explain to me what you're having difficulty with?
LusikkaMage 2 weeks ago
The opening theme to this tutorial is now stuck in my head >.< apart from that, I love your tutorial series far too much.
TheSturdge 2 weeks ago in playlist Beginner's/Game Programming 1
my window opens and then stays open for a few seconds with a white screen rather than black and will then close by itself a few seconds later, iv gone over the code and have the same thing word for word... any ideas?
crazycrookes 2 months ago
I get a few errors...
`SDL_INIT_EVERYTHING' undeclared (first use this function),
SDL/SDL.h: No such file or directory, and more.
14 errors. Help?
CaptainOlimar1 2 months ago
Comment removed
CaptainOlimar1 2 months ago
Btw, nice tutorials.. It's really user friendly :) (Y)
axby 3 months ago
3:30, or put it in the %homedir%/Windows/System32 and/or %homedir%/Windows/SysWOW64 folder
axby 3 months ago
@3:18 Unless you have Linux :3
krye97 4 months ago in playlist More videos from LusikkaMage
So, I have a System.h file that has exactly what you put on screen at 3:00.
For whatever reason, g++ (compiling from netbeans btw) gives me an undefined reference error. It seems to be caused by these, called in main.cpp:
System system;
system.Setup();
help?
videogamefanatic89 4 months ago
Comment removed
videogamefanatic89 4 months ago
Comment removed
videogamefanatic89 4 months ago
@videogamefanatic89 Now I get a segmentation fault caused by SDL_Flip(buffer);. any ideas?
videogamefanatic89 4 months ago
i just get this error ld.exe||cannot find -lSDL_image|
||=== Build finished: 1 errors, 0 warnings ===|
TompanX 6 months ago
@TompanX Download the SDL_image lib..
libsdl(DOT)org/projects/SDL_image/release/SDL_image-1.2.10. zip
Remove spaces.
axby 3 months ago
when I build it it just ses "pikcin - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...
Nothing to be done." what should I do?
TompanX 6 months ago
@TompanX What IDE are you using? What Operating System?
LusikkaMage 6 months ago
@LusikkaMage Just fixed some guy Im subbed to just made a video about how to fix it XD
TompanX 6 months ago
is it just me or is this really really laggy? cos i try dragging the window around and it just freezes up. i'm thinking it's probably to do with having SDL_Flip in the loop. i'm using the g++ compiler on ubuntu
chaozuper 7 months ago
I don't know why the code given in the tutorial works for you, but I had to make a few tweaks. First, If I don't initialize the event before the loop (with the poll event function), the program will fail to run properly (maybe just cause i use visual studio, but idk). Second, after fixing that, leaving everything else as is, the program pops up as a full screen. to counter this, you can change your if statement to check for a true variable instead of a false one. Hope this helps :p.
hasards 8 months ago
does sdl do double buffering for you?
Deeharok 8 months ago
You may want to check out the new Allegro 5. It is a HUGE leap forward from the Allegro 4 series and is an entirely new beast. It's a really nice library now. I liked it before, but now it is SO much better and modern, event driven and not as much of a CPU hog, has support for native interfaces, 3D acceleration, you name it... I like it MUCH better than SDL. It's just as portable as SDL as well, only it has sound, music, JPG, PNG, OGG etc... support built in.
NeilRoy65 11 months ago
4Teddybears 1 year ago
@4Teddybears If the surfaces are in-scope when the function is called, then yes. However, if you're not passing the surfaces to the function, it won't know where it is (unless the surfaces are global, which is a really bad idea).
What I do is I have an "ImageManager" class, which stores an array of surfaces inside. When the class hits the destructor, it destroys all the surfaces.
Only dynamically allocated memory needs freeing.
LusikkaMage 1 year ago
@LusikkaMage
Thanks. My Surfaces are global. Why is this such a bad idea?
4Teddybears 1 year ago
@4Teddybears Google, "Why global variables are bad".
It's part of the design: It leads to spaghetti code and destroys structure.
LusikkaMage 1 year ago
amazing toturial this just explains everything, but hey, is c++ one of the best langauges to start with, cause java and flash are great for gaming too?, so is c++ best?
razorbunny555 1 year ago
@razorbunny555 C++ is still used to make professional games today, but it is by no means the best language to learn for hobbyist programming. As a computer-science major in college, it's what we used, and what I had been learning for years.
LusikkaMage 1 year ago
@LusikkaMage java looks alot like c++, is this true?
razorbunny555 1 year ago
@razorbunny555 They have a lot of similarities; the syntax is similar and they're both object oriented. So in a way, yes. But C++, Java, and C# all have their differences.
LusikkaMage 1 year ago
@LusikkaMage Thanks :).
razorbunny555 1 year ago
@razorbunny555
can't believe your eyes eh?
4Teddybears 1 year ago
@4Teddybears still wondering ;).
razorbunny555 1 year ago
@razorbunny555 It depends on what you want to do. If you wish to create web based games you may prefer Java (or even learning to use Flash), but for PC games, C++ is common. If you learn C++ you can easily pick up C#, Java and many others. C# and Java are a lot like C++ and based on it so it's the best place to start and commercial games generally do use C++.
NeilRoy65 1 year ago
@NeilRoy65 i'm a great java programmer,, though i am getting 14 years old soon and i am learning java's for 2 years now, soo yeah, i might do java's for my work later on. it's the only thing i like. (other coding languages like c++ too!)
razorbunny555 11 months ago
A good book to buy to get started is "Beginning C++ Through Game Programming". I picked this up through Amazon.ca, but I already have a good grasp of C programming (and I am still hesitant to use classes! lol) but this book made classes especially a lot easier to comprehend. You don't need to use them for allegro programming though, I've created a full game (Deluxe Pacman) with Allegro and mostly just C code with a little C++ flexibility. Just not classes. ;)
NeilRoy65 1 year ago
fffffuuuuuuuuuuuu-
HPrototype1 1 year ago
Is anyone using Visual Studio 2010? I get a runtime error when i create the SDL_Event variable and the compiler will complain that i am using an unitialized variable and i am copying it from the tutorial. I tried setting it eqaul to NULL but then its a compiler error. how do i initialize the event variable or is there another way to do this?
iam4eversmart88 1 year ago
gonna try and follow ur tutorials , find some good but they always stopped before i got to learn enough.
Necry3d 1 year ago
I have done The allegro version but im getting a [Build Error] [example.exe ] Error 1 please help!! :) I thing it has somthing to do with missing Dll file becuse I dont have enyone in my folder :( I want to run my exe!! :P
klattermus1 1 year ago
I think there is an error in the else particularly the SDL_SetVideoMove. I got a compiler error but when I changed it to SDL_SetVideoMode it worked fine. Thanks for the tutorial btw. I really wanna be a game programmer and this is a big help for me to start.
exile0228 1 year ago
i think you messed up on the code a bit :P
at 1:42 u have fullscreen set to false and you made it so that it will go to fullscreen mode when fullscreen is false and windowed mode when fullscreen is true.
i think this should explain why people are just seeing black screens and not a window like it is in the video
again I'm watching these videos to learn so you might know something that i don't and you did that on purpose :P
great lessons btw
Drathgore 1 year ago
Wait, when I compile, it's just a big black screen with only my cursor, is that supposed to happen? Like I don't have a head bar like you do, it's just a black screen and all I could do is move my cursor. I have to hit the windows key to exit the program. Also is it a necessity to memorize all that code :P
Soap360 1 year ago
@Soap360 Yes, at this point it's supposed to be a blank window.
No, you don't generally memorize the code. This is the point of Object-Oriented Programming. Put it in a class for you to reuse in all of your programs.
LusikkaMage 1 year ago
@Soap360 Yeah, You've probably figured it out by now, but for anyone else, It's the if statement which is reversed.
Obviously If fullscreen is false you dont want The SDL_FULLSCREEN part.
Cut that and put it after else instead.
4Teddybears 1 year ago
What's the advantage of using a class instead of a function? Except for that you can protect some values..?
ThePearI 1 year ago
@ThePearI I think my comment was a bit vague there... What I mean is "What is the advantage of having a class for initializing?" I just have a function.
ThePearI 1 year ago
So this has been bugging me for a while but i have to ask; why do some console projects use int main (int argc, char *args[]) while other console apps just use void main(), what's the difference?
Grenadiac111 1 year ago
@Grenadiac111 The argc/args stuff is a throwback to when we used to boot programs from the prompt, and would throw it flags (or, arguments). They're not really used much anymore, and I don't really like using them in my prompt programs either.
Many IDEs require main to not be void, though, and some libraries (SDL...) require having the args/argv in main's header.
LusikkaMage 1 year ago
@LusikkaMage Thanks alot that would explain why SDL wouldn't complie without it, but my engine would. P.s. Great vids.
Grenadiac111 1 year ago
I'm assuming that .Done() is a function we have to create ourselves? Otherwise wouldn't that give us an error if it's not a part of SDL that is..?
ThePearI 1 year ago
@ThePearI It is a function we write ourselves.
LusikkaMage 1 year ago
how come my SDL_Init( SDL_INIT_EVERYTHING) is getting an error... I did everything right ;_;
dabeatmaster123 1 year ago
@dabeatmaster123 What compile error are you getting?
LusikkaMage 1 year ago
@LusikkaMage It says 'SDL_Init' undeclared[first use this function]
dabeatmaster123 1 year ago
i had to use somethin different on linker options but i am on ubuntu
whiteninjastudios 1 year ago
@whiteninjastudios Are you just compiling via the command line?
LusikkaMage 1 year ago
@LusikkaMage no i am using codeblocks ide on my ubuntu and gentoo machine
whiteninjastudios 1 year ago
I deleted the else statement because it gave my compiler build errors.
main.cpp:16: error: SDL_SetVIdeoMode was not declared in this scope
So I deleted line 15 & 16 and got rid of the "| SDL_FULLSCREEN" and it worked inside of a window.
commodore256 1 year ago
This reminds me of metal gear solid 2 when you had to take pictures of metal gear.
commodore256 1 year ago
As console program typing in the stuff after SDL_Event makes the program run as a unresposive blackscreen without any X. Tried running as a win32 app instead but it just gave me a bunch of 'unresolved external symbol' errors
DIProgan 2 years ago
Nevermind the win32 stuff forgot to set dependencies, it now acts just like the console version, goes black and requires a process shutdown.
DIProgan 2 years ago
i've never seen a programming tutorial more fun or comprehensible than this serie
shaderx666 2 years ago
For some reason when i type
"SDL_Event event;"
"while (event.type != SDL_QUIT)" and,
"SDL_PollEvent (&event)"
the word "event" always apears in blue and i get an error.
does it mean this word is reserved for something els?, if so, which words should i leave as "event" and which should i change?
Smito0 2 years ago
Getting comfortable with classes will make everything much clearer, but yes you can change it to anything you want as long as you remember what you changed it to.
seepauliedie 2 years ago
having some trouble here, got to the end and have this error message "Error 1 fatal error C1083: Cannot open include file: 'SDL/SDL.h': No such file or directory..." any ideas on how to fix this?
NFG49 2 years ago
Looks like you don't have the SDL library set up correctly. Make sure all the files are in the Include and Lib folders, and make sure the linker is set up.
LusikkaMage 2 years ago
You had the full screen check backwards :p
it should be, you set it to fullscreen if the bool was false. if( fullscreen == false ) { buffer = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );} else { buffer = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE | SDL_FULLSCREEN );}
HomocidalCanineK9 2 years ago
While I was preaching about how you got it backwards I got something backwards...
"You set it to fullscreen if the bool was false, it should be:" is what I meant to say.
HomocidalCanineK9 2 years ago
At 1:48 in your else block,
'buffer = SDL_SetVideoMove( 640, 480, 32, SDL_SWSURFACE );'
Supposed to be SDL_SetVideoMode* right?
Fixed my compiler error.
ishniek123 2 years ago
Love the music!
ryancfcsas 2 years ago
I am not actually a SDL expert, but i believe if you use:
SDL_Init(SDL_INIT_EVERYTHING);
atexit(SDL_QUIT);
//the code goes here
it would be better than:
SDL_Init(SDL_INIT_EVERYTHING);
// the code goes here
SDL_Quit();
because, there's a benefit of doing it this way, because if you detect an error somewhere, you can use the exit function and not worry about cleaning SDL, as the program will do it for you.
Kenshin1666 2 years ago
In C you could do that, in C++ you'd just use a destructor instead.
int main(int argc, char *argv[])
{ Game objGame; // Initiates
} // Out of scope: destructor called.
StephanvanSchaik 2 years ago
when ever I go to build my code (compile) I'm using codeblocks by the way... iI click build and it gives me a box saying yould you like to build this project since it has not been built yet.. I clikc "Yes" and the box pops up again! it also gives me an error saying "Linking Stage Skippied (build target has no objective fiels to link) Nothing to be done. Any idea what I forgot to do?
soccergod561234 2 years ago
In Code::Blocks you have to add the files to the project, if you didn't already. In case you did, right-click the C++ file(s) and select 'Properties'. Then click on the 'Build' tab and check 'Compile file' and 'Link file'. Normally, this is done automatically once you add the file to the project.
StephanvanSchaik 2 years ago
Wow, I've never used Double Buffering, I was wondering how to fix that flickering too, thanks =D
XianForce 2 years ago
Are you using SDL and getting flickering? o.0
LusikkaMage 2 years ago
It's better to put your DLL's in the system32 folder.
jSaurabh 2 years ago
only if you're confident you'll only ever use that 1 version of SDL, otherwise later on it'll mess you up.
GP4Vid 2 years ago 2
Not nessecerally if your going to distribute your game youll need the DLL's in the game folder to distribute - worst thing ever when youve jsut installed a game and then BANG missing DLL :(
Catkill666 2 years ago
I always keep my dlls in the specific project's folder.
This way, I never forget to distribute them with the project. ^^;
Also, it checks the local folder before system 32, which would be good if the person had an outdated dll in their system folder.
LusikkaMage 2 years ago
some people use linux
Z3r0XoL 2 years ago
On Linux you're still able to use Code::Blocks, although there are other IDEs like Anjuta and KDevelop. The hardcore option, which is also available on Windows through MinGW, is to use Makefiles.
Just check lazyfoo for information about how to install SDL for Linux.
StephanvanSchaik 2 years ago
SDLdotDLL ... I like how fast you say that :)
robotwo 2 years ago
o.O
*sexily* SDL-dot-DLL ;o
LusikkaMage 2 years ago
Just what I needed thank you (=
MrOnix9009 2 years ago