Thread: errors in project using SDL (Lode's Computer Graphics Tutorial)

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    235

    Question errors in project using SDL (Lode's Computer Graphics Tutorial)

    I successfully installed SDL in Codeblocks (discussed here How install SDL 5.0 to BlockCodes (origi - C++ Forum ) but I have problem to make the project working because there are some errors

    All project files are here: Lode's Computer Graphics Tutorial
    Now the errors are in file: quickcg.cpp
    downloadable here
    http://lodev.org/cgtutor/files/quickcg/quickcg.cpp
    Code:
    scr = SDL_SetVideoMode(width, height, colorDepth, SDL_SWSURFACE | SDL_FULLSCREEN);
    quickcg.cpp||In function 'void QuickCG::screen(int, int, bool, const string&)':|
    quickcg.cpp|115|error: 'SDL_FULLSCREEN' was not declared in this scope|

    there are more errors like that one.

    The other ones:
    if ((event.key.keysym.unicode & 0xFF80) == 0)
    quickcg.cpp|1033|error: 'SDL_Keysym' has no member named 'unicode'|

    Warnings:
    Code:
    void setBitOfReversedStream(size_t& bitp, unsigned char* bits, unsigned long bit) { bits[bitp >> 3] |=  (bit << (7 - bitp & 0x7)); bitp++; }
    quickcg.cpp|1033|error: 'SDL_Keysym' has no member named 'unicode'|


    Code:
    else if(colorType == 3) if(!(bd == 1 || bd == 2 || bd == 4 || bd == 8            )) return 37;
    warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]|

    Any suggestion how to correct the errors? Does somebody have experiences with it?

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Post the full rebuild log and likely someone will spot the problem.

    FAQ-Compiling (errors) - CodeBlocks

    If the full build log is too big post the first error and all the warnings before the first error.

    Tim S.
    Last edited by stahta01; 01-22-2015 at 04:42 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Did you confirm the sample code works with the version of SDL you downloaded?
    If not, I suggest doing so.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    What i can see, your code is C++.
    You are here in the C corner
    Other have classes, we are class

  5. #5
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    Sorry, somebody can move it to C++, I did not notice.

    When I tried the sample code from here:
    Lazy Foo' Productions
    (You should be able to download my testing project from here: http://sourceforge.net/projects/auto...t.zip/download
    you can check if it is OK.
    The source:
    Code:
    #include "SDL.h"
    // #include "SDL/SDL.h"
    int main( int argc, char* args[] ) {
        //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );
    //Quit SDL
    SDL_Quit();
    return 0;
    }
    )

    -------------- Clean: Debug in sdl-test (compiler: GNU GCC Compiler)---------------

    Cleaned "sdl-test - Debug"

    -------------- Build: Debug in sdl-test (compiler: GNU GCC Compiler)---------------

    Linking stage skipped (build target has no object files to link)
    Nothing to be done (all items are up-to-date).



    Full log of the Lode's CG Tutorial:
    ||=== Build: Debug in FT (compiler: GNU GCC Compiler) ===|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp||In function 'void QuickCG::screen(int, int, bool, const string&)':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|115|error: 'SDL_FULLSCREEN' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|115|error: 'SDL_SetVideoMode' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|120|error: 'SDL_HWSURFACE' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|120|error: 'SDL_HWPALETTE' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|120|error: 'SDL_SetVideoMode' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|128|error: 'SDL_WM_SetCaption' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|130|error: 'SDL_EnableUNICODE' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp||In function 'void QuickCG::redraw()':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|152|error: 'SDL_UpdateRect' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp||In function 'void QuickCG::waitFrame(double, double)':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|254|error: 'SDL_GetKeyState' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp||In function 'void QuickCG::readKeys()':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|285|error: 'SDL_GetKeyState' was not declared in this scope|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp||In function 'Uint8 QuickCG::getInputCharacter()':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|1033|error: 'SDL_Keysym' has no member named 'unicode'|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|1037|error: 'SDL_Keysym' has no member named 'unicode'|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|1573|warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp||In member function 'void QuickCG::decodePNG(std::vector<unsigned char>&, long unsigned int&, long unsigned int&, const unsigned char*, long unsigned int)::PNG::setBitOfReversedStream(size_t&, unsigned char*, long unsigned int)':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|1580|warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp||In member function 'int QuickCG::decodePNG(std::vector<unsigned char>&, long unsigned int&, long unsigned int&, const unsigned char*, long unsigned int)::PNG::checkColorValidity(long unsigned int, long unsigned int)':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|1586|warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|1585|warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp|1584|warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]|
    ||=== Build failed: 12 error(s), 5 warning(s) (0 minute(s), 2 second(s)) ===|
    Last edited by barracuda; 01-22-2015 at 06:36 PM.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    FYI: the "Message log" you posted is NOT the "build log" requested.
    Edit2: I suggest read the FAQ; try doing a rebuild after turning on the Full build log option.

    Edit3: The obvious part of the FAQ you failed to do correctly.
    Things to remember:

    Look at the "Build Log" NOT the "Build Message" tab
    Do a re-build instead of build in order to get a full build log.

    Hint on the problem it does appear to be a compile error.
    So, likely you are missing an include or your sample code is not compatible with the SDL library you downloaded. Without a full build log no one can help you.

    Tim S.
    Last edited by stahta01; 01-22-2015 at 06:35 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    Full log enabled and Rebuilt.

    Full build log:



    -------------- Clean: Debug in FT (compiler: GNU GCC Compiler)---------------

    Cleaned "FT - Debug"

    -------------- Build: Debug in FT (compiler: GNU GCC Compiler)---------------

    mingw32-g++.exe -Wall -fexceptions -g -IP:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include -IP:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include -c "R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\fourier1d.cpp" -o obj\Debug\fourier1d.o
    mingw32-g++.exe -Wall -fexceptions -g -IP:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include -IP:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include -c "R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\fourier2d.cpp" -o obj\Debug\fourier2d.o
    mingw32-g++.exe -Wall -fexceptions -g -IP:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include -IP:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include -c "R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\main.cpp" -o obj\Debug\main.o
    mingw32-g++.exe -Wall -fexceptions -g -IP:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include -IP:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include -c "R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp" -o obj\Debug\quickcg.o
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp: In function 'void QuickCG::screen(int, int, bool, const string&)':
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:115:71: error: 'SDL_FULLSCREEN' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:115:85: error: 'SDL_SetVideoMode' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:120:55: error: 'SDL_HWSURFACE' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:120:71: error: 'SDL_HWPALETTE' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:120:84: error: 'SDL_SetVideoMode' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:128:39: error: 'SDL_WM_SetCaption' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:130:22: error: 'SDL_EnableUNICODE' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp: In function 'void QuickCG::redraw()':
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:152:33: error: 'SDL_UpdateRect' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp: In function 'void QuickCG::waitFrame(double, double)':
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:254:34: error: 'SDL_GetKeyState' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp: In function 'void QuickCG::readKeys()':
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:285:32: error: 'SDL_GetKeyState' was not declared in this scope
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp: In function 'Uint8 QuickCG::getInputCharacter()':
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:1033:25: error: 'SDL_Keysym' has no member named 'unicode'
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:1037:32: error: 'SDL_Keysym' has no member named 'unicode'
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp: In static member function 'static long unsigned int QuickCG::decodePNG(std::vector<unsigned char>&, long unsigned int&, long unsigned int&, const unsigned char*, long unsigned int)::PNG::readBitFromReversedStream(size_t&, const unsigned char*)':
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:1573:150: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp: In member function 'void QuickCG::decodePNG(std::vector<unsigned char>&, long unsigned int&, long unsigned int&, const unsigned char*, long unsigned int)::PNG::setBitOfReversedStream(size_t&, unsigned char*, long unsigned int)':
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:1580:129: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp: In member function 'int QuickCG::decodePNG(std::vector<unsigned char>&, long unsigned int&, long unsigned int&, const unsigned char*, long unsigned int)::PNG::checkColorValidity(long unsigned int, long unsigned int)':
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:1586:14: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:1585:14: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks\quickcg.cpp:1584:9: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
    Process terminated with status 1 (0 minute(s), 1 second(s))
    12 error(s), 5 warning(s) (0 minute(s), 1 second(s))
    Last edited by barracuda; 01-23-2015 at 03:59 AM.

  8. #8
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    The testing program was created from empty project and there are no subdirectories in the project directory. "Linking stage skipped (build target has no object files to link)" probably does not have relation to SDL.
    http://sourceforge.net/projects/auto...t.zip/download

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Search the SDL headers for SDL_FULLSCREEN.

    If you find it; add that header to the source file; if you do NOT find it then your sample code is NOT compatible with the SDL version you have installed.
    (It is also possible you installed the SDL wrong or are using the wrong search path "P:\PROGRAMY\programming\SDL-2.0.3-lib-MinGW\include")

    Edit: Link to someone else with same or similar problem http://forums.libsdl.org/viewtopic.p...3dde0d1fecef4a

    Edit2: The flags were likely renamed based on this URL https://wiki.libsdl.org/SDL_WindowFlags

    Edit3: In other words your sample code DOES NOT work with SDL 2.

    Tim S.
    Last edited by stahta01; 01-23-2015 at 12:09 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  10. #10
    Registered User
    Join Date
    Sep 2014
    Posts
    235
    I use both versions and the lower version does the same thing even that the syntax should be OK:
    SDL_SetVideoMode

    EDIT:
    I checked once again what is contained in the included path "include" directory and found SDL directory. So I changed the path to:
    P:\PROGRAMY\programming\SDL-1.2.15-lib-MiGW32\include\SDL

    and now I got this:
    ||=== Build: Debug in FT (compiler: GNU GCC Compiler) ===|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp||In member function 'void QuickCG::decodePNG(std::vector<unsigned char>&, long unsigned int&, long unsigned int&, const unsigned char*, long unsigned int)::PNG::decode(std::vector<unsigned char>&, const unsigned char*, long unsigned int)':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp|1404|warning: variable 'known_type' set but not used [-Wunused-but-set-variable]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp|1573|warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp||In member function 'void QuickCG::decodePNG(std::vector<unsigned char>&, long unsigned int&, long unsigned int&, const unsigned char*, long unsigned int)::PNG::setBitOfReversedStream(size_t&, unsigned char*, long unsigned int)':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp|1580|warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp||In member function 'int QuickCG::decodePNG(std::vector<unsigned char>&, long unsigned int&, long unsigned int&, const unsigned char*, long unsigned int)::PNG::checkColorValidity(long unsigned int, long unsigned int)':|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp|1586|warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp|1585|warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]|
    R:\PROGRAMS\C++\Fourier Transform\FT-codeblocks-SDL1.2.15\quickcg.cpp|1584|warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]|
    ||=== Build finished: 0 error(s), 6 warning(s) (0 minute(s), 2 second(s)) ===|


    I think it works now :-), thanks.
    Last edited by barracuda; 01-23-2015 at 01:29 PM.

  11. #11
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You need to read up on the difference between a compiler error and a compiler warning.

    Then, you should fix the warning that need fixed and comment the ones that do NOT need fixed.

    I would ignore this one "Wunused-but-set-variable" till you learn more and I would likely fix the others.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by barracuda View Post
    EDIT:
    I checked once again what is contained in the included path "include" directory and found SDL directory. So I changed the path to:
    P:\PROGRAMY\programming\SDL-1.2.15-lib-MiGW32\include\SDL
    I must of missed seeing this edit before my last reply.
    I have no idea if adding the trailing "/SDL" is correct. Sometimes, I have seen instead the add a leading SDL/ or sdl/ in the header include statement.
    I have never took the time to figure out which is the more correct or the more often used method.

    IIRC, The Windows samples did tend to be one way while the Linux samples tended to be the other way.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Graphics tutorial
    By ssjnamek in forum C++ Programming
    Replies: 1
    Last Post: 08-15-2005, 02:13 AM
  2. Tutorial for making better computer graphics?
    By supertoad in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 05-02-2005, 12:19 AM
  3. About the graphics tutorial hosted here..
    By Cobras2 in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2002, 12:40 PM
  4. Graphics && Tutorial
    By GaPe in forum C Programming
    Replies: 2
    Last Post: 03-06-2002, 11:57 AM
  5. A Tutorial For Graphics In C!!!
    By SupremeOmnipotence in forum C Programming
    Replies: 4
    Last Post: 01-17-2002, 06:04 PM