I've just recently started fooling with SDL, yet I'm having troubles.
Some Info:
- compiling under mingw32
- using C::B and DevC++ as my IDE of choice
- 32-bit Vista, newest service pack updated
- nVidia GT 130M Graphic Card, newest drivers updated
First of all, whenever i try to compile my code under, DevCPP I'm getting a BSoD, however C::B doesnt seem to have this problem. Anyone know or heard what might be the issue?
Second, this is a basic code that is suppose to blink 3 times an image on the screen, when i compile and run the code however, i just get black screen. Ideas?
Code:
#include <stdio.h>
#include <stdlib.h>
#include "SDL/SDL.h"
#define TRUE 0
#define FALSE 1
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 32
SDL_Surface *image = NULL;
SDL_Surface *screen = NULL;
signed int initEngine();
void quitEngine();
void updateScreen();
SDL_Surface* loadImage(char* filename);
void applySurface(int x, int y, SDL_Surface* source, SDL_Surface* destination);
int main (int argc, char* args[])
{
initEngine();
image = loadImage("1.bmp");
applySurface(40, 40, image, screen);
applySurface(100, 100, image, screen);
applySurface(200, 200, image, screen);
updateScreen();
SDL_Delay(2000);
quitEngine();
return TRUE;
}
signed int initEngine()
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return FALSE;
}
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
if(screen == NULL)
{
return FALSE;
}
SDL_WM_SetCaption("Engine", NULL);
return TRUE;
}
void quitEngine()
{
SDL_FreeSurface(image);
SDL_FreeSurface(screen);
SDL_Quit();
}
void updateScreen()
{
SDL_Flip(screen);
}
SDL_Surface* loadImage(char* filename)
{
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = SDL_LoadBMP(&filename);
if(loadedImage != NULL)
{
optimizedImage = SDL_DisplayFormat(loadedImage);
SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}
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);
}
Cheers,