Thread: C and SDL for a beginner

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    204

    C and SDL for a beginner

    Hi,

    I have been programming in C for a while now as an Mech eng student, so its all been calculations and stuff up to now, but I have recently wanted to be able to add basic graphics. I have installed FINALLY after a lot of hell the SDL libraries and it all works in Codeblocks - the editor i am using.

    I am struggling to find a way to draw to the screen for instance just a box around Hello World! would get me on my way, the graphics dont need to be animated, but i cant find a decent tutorial for C anywhere. Please can someone help me with a basic tamplate c file that will draw a box say 2 pixels thick around a printf statement, just to get it to look a bit nicer.

    P.S is C dieing out because everytime i do a search for C SDL tutorials, they seem to all really be in C++???

    Thanks

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    P.S is C dieing out because everytime i do a search for C SDL tutorials, they seem to all really be in C++???
    searching for c anything is hard because it's a bad keyword. c++ gives more results and a lot of c++ stuff can be used or translated to c without a problem. c isn't dying out, it's still going strong. the c++ cabal just wants you to think it is so you'll join the dark side.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    204
    cheers, can you help with my other question?

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    no, that's why i didn't answer it.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    google for "simple SDL example" gives this:
    http://friedspace.com/SDLTest.c

    I don't know if that's helpful or not.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    204
    Cheers but he uses C++ there i think...

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    25,692
    Quote Originally Posted by a.mlw.walker
    Cheers but he uses C++ there i think...
    It looks like perfectly valid C to me.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    It looks like perfectly valid C to me.
    Not only do I agree, but "gcc -Wall -Wextra -ansi -pedantic sdl.c" compiles fine - which means that gcc thinks it's ANSI C too. [ok, two warnings for argc and argv not being used - but that's not a "this is not ANSI" warnings].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391
    Quote Originally Posted by a.mlw.walker View Post
    I have installed FINALLY after a lot of hell the SDL libraries and it all works in Codeblocks - the editor i am using.
    I've never heard of SDL before, but if it can do graphics and sound, I am interested.

    I am going to install SDL, but can you tell me what problems you had with that?

    Thanks in advance.

    EDIT: I am using Win XP
    OS: Linux Mint 13(Maya) LTS 64 bit.

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    204
    Basically (also using xp) i installed codeblocks with mingw and then followed this tutorial for SDL:

    http://lazyfoo.net/SDL_tutorials/lesson01/index.php

    the rest of the tutorials are for c++ but that one is very good.

    its not too bad SDL been having a look

Popular pages Recent additions subscribe to a feed