Zaki Mirza’s Blog

Icon

… About software and beyond!

Setting up SDL-OPENGL in Visual Studio


And this CG assignment’s been giving some people pain in the gut so i thought okay why not share this with others. hopefully they’ll learn from it. So here goes.

Well the problem lies in the fact that people cant setup SDL and OpenGL together in Visual Studio (6,7,8).

Here are the steps you can follow to make it all work:

Downloading and setting up SDL:

1. For the Easiest way to do this, (on your home PC) download the sdl libraries and headers from www.libsdl.org . extract the file (in my case its: SDL_devel-1.2.11-VC6.zip). hunt the folder where you installled the visual studio. Find the folder (VC98 on VC6… VC7 on .net 2003 and vc8 on .net 2005).

2. in the include folder, create a folder called “sdl” and copy the contents of the “sdl_devel-1.2.11/include” folder ( where you jus extracted the sdl headers). These will be many header files. in other words copy *.* from sdl_devel-1.2.11/include to vc6/include. 🙂

3. in the lib folder (of visual studio) copy *.lib of the “lib” folder in sdl_devel-1.2.11 folder.

4. copy the sdl.dll file in the sdl_devel-1.2.11/lib folder to your windows/system32 folder.
Creating The SDL-OPENGL Project:

1. fireup Visual Studio of your choice.

2. Create a new Windows 32 Console Application. Name it .. i_suck :p

3. Click finish. The visual studio will create a default cpp file with the main() function declared in it.

4. In VC6 goto Project>Settings, in VC7 and VC8 right click the project in the solution explorer and click properties.

5. Under Linker>Input option: include the following libraries:
opengl32.lib glu32.lib sdl.lib sdlmain.lib

6. (OPTIONAL STEP) in the Linker>System option (im not sure if this is in VC6, but it is in VC7. This step is optional. Only if you do not want to show the console window with the graphics window) Set the subsystem to windows (or add /SUBSYSTEM:WINDOWS to the commandline option in the linker). in the linker>advanced option, set the entry point to “mainCRTStartup” or add “/ENTRY:mainCRTStartup” to commandline option of linker.

7. In c/C++ > Code Generation option, set the Runtime Library option to MULTI-THREADED DEBUG DLL.

8. Click ok and the project is setup for opengl and sdl.

The Code:

1. In you code, include the following files:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <sdl/sdl.h>

Note that the ordering of the file should be right. because gl.h file requires that windows.h be included beforehand.

2. build your code. it should be successful. if it isnt, reconsider the above steps.
The Coding Part:
Do it yourself :p. Read the SDL Documentation that came with the SDL libraries and headers. Its right there in the doc folder :p. And ah yes, it will be very comfy once you switch to Visual Studio .net 2003 (and even more to .net 2005, but .net 2003 is more stable. Thats from my experience and mishi and umar manzoor recommend that as well). I have tested these steps on .Net 2003. ( dunno about VC6, i left using it ages ago). Any problems you find drop in a comment. Yes i do take donations as well :p
 

Advertisements

Filed under: opengl, sdl, Troubleshooter, visual studio

11 Responses

  1. SenSeika says:

    I want to make one specification. In Windows (at least in MSVC 5,6,7) function main must be defined with command prompt parameters as

    int main(int argc, char* argv[])

    If it will be defined just like
    int main(), compiler will give an error!

  2. Elliot says:

    Hey! I just wanted to say thanks for making this guide. :] I was worried I would never get this dreadful stuff set up again on this new comp, but it worked on the first try. ^^

  3. Idetrorce says:

    very interesting, but I don’t agree with you
    Idetrorce

  4. Maximus says:

    I would like to see a continuation of the topic

  5. mevdev says:

    Wow, that got me going. Thanks. I was having trouble finding a tutorial for the visual studio 9 ms is just giving away.

    I love sdl !!

  6. I have been scouring the internet, and the gamedev.net forums for hours trying to solve my linker errors, and your little tutorial here solved my problem. I was following the LazyFoo setup guide and he left out the step:

    “in the linker>advanced option, set the entry point to “mainCRTStartup” or add “/ENTRY:mainCRTStartup” to commandline option of linker.”

    Great job, thanks a bunch!

  7. Quakeboy says:

    Thanks … it saved me time

  8. vasu says:

    Nice tutorial, but i keep getting some errors pls help…….

    1>—— Build started: Project: w32, Configuration: Debug Win32 ——
    1>Compiling…
    1>main.cpp
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3538) : warning C4103: ‘c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h’ : alignment changed after including header, may be due to missing #pragma pack(pop)
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3839) : warning C4103: ‘c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h’ : alignment changed after including header, may be due to missing #pragma pack(pop)
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3937) : warning C4068: unknown pragma
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3943) : warning C4068: unknown pragma
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3950) : warning C4068: unknown pragma
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1328) : error C2144: syntax error : ‘void’ should be preceded by ‘;’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1328) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1329) : error C2144: syntax error : ‘void’ should be preceded by ‘;’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1329) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1329) : error C2086: ‘int DECLSPEC_NORETURN’ : redefinition
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1328) : see declaration of ‘DECLSPEC_NORETURN’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1389) : error C2144: syntax error : ‘void’ should be preceded by ‘;’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1389) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1389) : error C2086: ‘int DECLSPEC_NORETURN’ : redefinition
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1328) : see declaration of ‘DECLSPEC_NORETURN’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\rpcdce.h(369) : error C2144: syntax error : ‘void’ should be preceded by ‘;’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\rpcdce.h(369) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\rpcdce.h(369) : error C2086: ‘int DECLSPEC_NORETURN’ : redefinition
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winbase.h(1328) : see declaration of ‘DECLSPEC_NORETURN’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\rpcdcep.h(89) : error C3646: ‘I_RpcAllocate’ : unknown override specifier
    1>c:\program files\microsoft sdks\windows\v6.0a\include\rpcdcep.h(89) : error C2091: function returns function
    1>c:\program files\microsoft sdks\windows\v6.0a\include\rpcdcep.h(89) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\shellapi.h(147) : warning C4103: ‘c:\program files\microsoft sdks\windows\v6.0a\include\shellapi.h’ : alignment changed after including header, may be due to missing #pragma pack(pop)
    1>c:\program files\microsoft sdks\windows\v6.0a\include\shellapi.h(289) : warning C4103: ‘c:\program files\microsoft sdks\windows\v6.0a\include\shellapi.h’ : alignment changed after including header, may be due to missing #pragma pack(pop)
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(545) : error C3646: ‘inet_ntoa’ : unknown override specifier
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(545) : error C2091: function returns function
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(545) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(545) : error C2733: second C linkage of overloaded function ‘DECLARE_STDCALL_P’ not allowed
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(545) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(554) : error C3646: ‘gethostbyaddr’ : unknown override specifier
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(554) : error C2091: function returns function
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(554) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(554) : error C2733: second C linkage of overloaded function ‘DECLARE_STDCALL_P’ not allowed
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(554) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(555) : error C3646: ‘gethostbyname’ : unknown override specifier
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(555) : error C2091: function returns function
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(555) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(555) : error C2556: ‘int (__cdecl *DECLARE_STDCALL_P(hostent *))(const char *)’ : overloaded function differs only by return type from ‘int (__cdecl *DECLARE_STDCALL_P(hostent *))(const char *,int,int)’
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(554) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(555) : error C2371: ‘DECLARE_STDCALL_P’ : redefinition; different basic types
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(554) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(556) : error C3646: ‘getservbyport’ : unknown override specifier
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(556) : error C2091: function returns function
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(556) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(556) : error C2733: second C linkage of overloaded function ‘DECLARE_STDCALL_P’ not allowed
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(556) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(557) : error C3646: ‘getservbyname’ : unknown override specifier
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(557) : error C2091: function returns function
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(557) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(557) : error C2556: ‘int (__cdecl *DECLARE_STDCALL_P(servent *))(const char *,const char *)’ : overloaded function differs only by return type from ‘int (__cdecl *DECLARE_STDCALL_P(servent *))(int,const char *)’
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(556) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(557) : error C2371: ‘DECLARE_STDCALL_P’ : redefinition; different basic types
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(556) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(558) : error C3646: ‘getprotobynumber’ : unknown override specifier
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(558) : error C2091: function returns function
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(558) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(558) : error C2733: second C linkage of overloaded function ‘DECLARE_STDCALL_P’ not allowed
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(558) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(559) : error C3646: ‘getprotobyname’ : unknown override specifier
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(559) : error C2091: function returns function
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(559) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(559) : error C2556: ‘int (__cdecl *DECLARE_STDCALL_P(protoent *))(const char *)’ : overloaded function differs only by return type from ‘int (__cdecl *DECLARE_STDCALL_P(protoent *))(int)’
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(558) : see declaration of ‘DECLARE_STDCALL_P’
    1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(559) : error C2371: ‘DECLARE_STDCALL_P’ : redefinition; different basic types
    1> c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(558) : see declaration of ‘DECLARE_STDCALL_P’
    1>Build log was saved at “file://c:\Vasu\Visual C++ 2008\w32\w32\Debug\BuildLog.htm”
    1>w32 – 45 error(s), 7 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  9. This is one of the better blogs that I have seen.
    I can not wait to hear more.

  10. blogspot.com says:

    I appreciate the way you express things. It makes me think,
    but much more importantly it makes me feel and I cherish
    it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

RSS Google Shared Items

  • An error has occurred; the feed is probably down. Try again later.

RSS Google Reader Starred Items

  • An error has occurred; the feed is probably down. Try again later.

Top Clicks

  • None
%d bloggers like this: