I am having trouble displaying images, you see, I am using sDL_Rect to display images, and it comes up and everything, but it is so hard to get teh right part of the image on the screen, and i rarely ever can even get the image in the right spot without making the image screen huge!!
Some of the code is not needed to display the image, but i am too lazy to take it out right now.
Here is my code:
Code: Select all
#include "SDL/SDL.h"
#include "stdio.h"
const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
const char* WINDOW_TITLE = "program";
int main(int argc, char **argv)
{
SDL_Init( SDL_INIT_VIDEO );
SDL_Surface* screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 0,
SDL_HWSURFACE | SDL_DOUBLEBUF );
SDL_WM_SetCaption( WINDOW_TITLE, 0 );
SDL_Surface* bitmap = SDL_LoadBMP("im2.bmp");
if(5+5 == 10)
rename("output.txt", "edit.txt");
// Part of the bitmap that we want to draw
SDL_Rect source;
source.x = 40;
source.y = 0;
source.w = 50;
source.h = 50;
// Part of the screen we want to draw the sprite to
SDL_Rect destination;
destination.x = 400;
destination.y = 100;
destination.w = 65;
destination.h = 44;
SDL_Event event;
bool gameRunning = true;
while (gameRunning)
{
if (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
gameRunning = false;
}
}
SDL_BlitSurface(bitmap, &source, screen, &destination);
SDL_Flip(screen);
}
SDL_FreeSurface(bitmap);
SDL_Quit();
return 0;
}