Trying to get SDL to work

This is a discussion on Trying to get SDL to work within the C++ Programming forums, part of the General Programming Boards category; Not sure how much of this is relevant but hey... I'm running Win2000, and I'm using Dev-c++ with the Mingw32 ...

  1. #1
    Registered User Rider's Avatar
    Join Date
    Nov 2005
    Posts
    28

    Exclamation Trying to get SDL to work

    Not sure how much of this is relevant but hey...

    I'm running Win2000, and I'm using Dev-c++ with the Mingw32 compiler.

    I've copied the libraries from the SDL installation into their respective folders, as described HERE
    I've added the Lib and Include directories inside my Dev-c++ dir to the Directories tab.
    I've added the "-lmingw32 -lSDLmain -lSDL" to the parameters tab.

    But when I try to compile the example code (wichever) Dev-c++ tells me that I need to define a "host application" and after that it won't compile but simply states "nothing to be done for "all""

    I'm really annoyed that I can't find what's wrong, and as such I turn to yee forumers.

    What could be the matter??

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Post the code you're trying to compile. You may need to use a Windows project (I have to on my older Dev-C++).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User Rider's Avatar
    Join Date
    Nov 2005
    Posts
    28
    Surely, here's the code, as ripped from the link provided in my first post.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #include <SDL/SDL.h>
    
    void Slock(SDL_Surface *screen)
    {
      if ( SDL_MUSTLOCK(screen) )
      {
    	if ( SDL_LockSurface(screen) < 0 )
    	{
    	  return;
    	}
      }
    }
    
    void Sulock(SDL_Surface *screen)
    {
      if ( SDL_MUSTLOCK(screen) )
      {
    	SDL_UnlockSurface(screen);
      }
    }
    
    void DrawPixel(SDL_Surface *screen, int x, int y,
    								    Uint8 R, Uint8 G, Uint8 B)
    {
      Uint32 color = SDL_MapRGB(screen->format, R, G, B);
      switch (screen->format->BytesPerPixel)
      {
    	case 1: // Assuming 8-bpp
    	  {
    		Uint8 *bufp;
    		bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
    		*bufp = color;
    	  }
    	  break;
    	case 2: // Probably 15-bpp or 16-bpp
    	  {
    		Uint16 *bufp;
    		bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
    		*bufp = color;
    	  }
    	  break;
    	case 3: // Slow 24-bpp mode, usually not used
    	  {
    		Uint8 *bufp;
    		bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
    		if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
    		{
    		  bufp[0] = color;
    		  bufp[1] = color >> 8;
    		  bufp[2] = color >> 16;
    		} else {
    		  bufp[2] = color;
    		  bufp[1] = color >> 8;
    		  bufp[0] = color >> 16;
    		}
    	  }
    	  break;
    	case 4: // Probably 32-bpp
    	  {
    		Uint32 *bufp;
    		bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
    		*bufp = color;
    	  }
    	  break;
      }
    }
    
    void DrawScene(SDL_Surface *screen)
    {
      Slock(screen);
      for(int x=0;x<640;x++)
      {
    	for(int y=0;y<480;y++)
    	{
    	  DrawPixel(screen, x,y,y/2,y/2,x/3);
    	}
      }
      Sulock(screen);
      SDL_Flip(screen);
    }
    
    int main(int argc, char *argv[])
    {
    
      if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
      {
    	printf("Unable to init SDL: %s\n", SDL_GetError());
    	exit(1);
      }
      atexit(SDL_Quit);
    
      SDL_Surface *screen;
      screen=SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
      if ( screen == NULL )
      {
    	printf("Unable to set 640x480 video: %s\n", SDL_GetError());
    	exit(1);
      }
      int done=0;
    
      while(done == 0)
      {
    	SDL_Event event;
    
    	while ( SDL_PollEvent(&event) )
    	{
    	  if ( event.type == SDL_QUIT )  {  done = 1;  }
    
    	  if ( event.type == SDL_KEYDOWN )
    	  {
    		if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
    	  }
    	}
    
    	DrawScene(screen);
      }
    
      return 0;
    }
    Though I suspect it's not the code that is wrong, because I get the same error with different example programs...

    Maybe irrelevant, but here's the Debug log:
    Code:
    Compiler: Default compiler
    Building Makefile: "C:\Documents and Settings\Administrator\My Documents\Code and such\Tutorials\Tstprj\Makefile.win"
    Executing  make...
    mingw32-make -f "C:\Documents and Settings\Administrator\My Documents\Code and such\Tutorials\Tstprj\Makefile.win" all
    mingw32-make: Nothing to be done for `all'.
    
    Execution terminated

  4. #4
    Registered User Rider's Avatar
    Join Date
    Nov 2005
    Posts
    28
    *bump*

    I'd just like to get started on making games.

    If anyone can help, please do, and if the question is stupid, please tell me.
    I'm just here to learn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL Window Closes...
    By FlyingIsFun1217 in forum Game Programming
    Replies: 11
    Last Post: 11-22-2007, 10:41 AM
  2. SDL or Allegro
    By fungus_mungus in forum Game Programming
    Replies: 7
    Last Post: 04-02-2005, 12:18 PM
  3. problem with sdl and vectors
    By r0bbb in forum C++ Programming
    Replies: 4
    Last Post: 03-20-2005, 05:11 AM
  4. If you are employed as a programmer, please look
    By Flood Fighter in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 09-28-2004, 02:35 AM
  5. sdl in c++
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-07-2002, 07:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21