Jump to content
  • Advertisement
Sign in to follow this  
Catkill

Sdl

This topic is 3408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So im gonna learn a bit of SDL got a game to make (nothing complicated infact its just pairs basicly - with a slight twist as its gotta be educational :) for the children) So how would i go about installing SDL for either codeblocks or visual studio express 2008 i hear about synaptic what is that and how does that work? SDL and all additional libraries would be nice, or i could go straight to directX ? i have a book on that cheers Catkill

Share this post


Link to post
Share on other sites
Advertisement
This guide will help you installing SDL.

DirectX allows you do do stuff much more complex than SDL, but it's harder to learn, and considering the fact that you are don't have too much time, if you don't really need 3D or realtime sprite rotating/scaling, I suggest you just stick to SDL for now. You can learn DX after the competition if you want.

Share this post


Link to post
Share on other sites
Catkill, have you considered Googling and doing any investigation on your own? If you're going to program, you have to learn to investigate by yourself. It's not like the information is hidden in some secret vault that only we have access to.

Quote:
So how would i go about installing SDL for either codeblocks or visual studio express 2008
Google or read documentation. SDL documentation is pretty clear about what to do. Google will net you a number of tutorials that tell you how to setup SDL. A search of this forum would help too.

Quote:
i hear about synaptic what is that and how does that work?
That's a package manager useful for certain linux distros. I'm not sure why you ask about that along with SDL.

Quote:
SDL and all additional libraries would be nice, or i could go straight to directX ?
It doesn't matter. Well, you ask about Synaptic, so it sounds like you are on Linux? In which case DirectX is not even an option for you.

Share this post


Link to post
Share on other sites
I got it set up for codeblocks , typed my code - doing lazyfoo's tutorials suppose thats as good a palce as any to start, click compile no errors up pops my window (and a console for some reason) and wow a blackscreen????? why arent my graphics showing any ideas

Share this post


Link to post
Share on other sites
You have to post code or we won't know what's going on. If it's a black screen it probably didn't load your resources.

Share this post


Link to post
Share on other sites
O yeah sorry , was a bit rushed lol

#include "SDL/SDL.h"
#include <string>

//screen attributes

const int SCREEN_HEIGHT = 640;
const int SCREEN_WIDTH = 480;
const int SCREEN_BPP = 32;

//Set up surfaces

SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;

//Load image function

SDL_Surface *LoadImage(std::string filename)
{
SDL_Surface *LoadedImage = NULL;
SDL_Surface *OptimizedImage = NULL;

LoadedImage = SDL_LoadBMP(filename.c_str());

if (LoadedImage!=NULL)
{
OptimizedImage = SDL_DisplayFormat(LoadedImage);

SDL_FreeSurface (LoadedImage);
}

return OptimizedImage;
}

//Blitting surface function

void ApplySurface(int x, int y, SDL_Surface *Source , SDL_Surface *Destination)
{
SDL_Rect offset;

offset.x = x;
offset.y = y;

SDL_BlitSurface(Source, NULL, Destination, &offset);
}

int main (int argc, char* args[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 1;
}

screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE);

if (screen == NULL)
{
return 1;
}

SDL_WM_SetCaption("Hello world",NULL);

message = LoadImage("hello_world.bmp");
background = LoadImage ("background.bmp");

ApplySurface(0,0,background,screen);
ApplySurface(180,140,message,screen);

if (SDL_Flip(screen) == -1)
{
return 1;
}

SDL_Delay(7000);

SDL_FreeSurface (message);
SDL_FreeSurface (background);

SDL_Quit();

return 0;
}

Share this post


Link to post
Share on other sites
Do you have the resources in the correct folder? Or did you designate the correct path? If you put it in a different folder you have to write the path. For example "/images/hello_world.bmp"

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!