Page 1 of 1

Trouble displaying images

Posted: Sun Sep 20, 2009 5:25 pm
by Jaxerhaxer
I am kinda new to sdl, and kind of new to C++ in general, but i got lots of books on it, anyways..
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;
}


Re: Trouble displaying images

Posted: Sun Sep 20, 2009 5:29 pm
by RyanPridgeon
Can you explain what is your exact problem?

You know how to set the coordinates to display the image at, right?

Re: Trouble displaying images

Posted: Sun Sep 20, 2009 5:32 pm
by Jaxerhaxer
The full image does not show no matter what i change, the width, height, y,x,.
I can change where it shows, but it never shows the full thing!
Please help.

Re: Trouble displaying images

Posted: Sun Sep 20, 2009 5:35 pm
by Bakkon
That's because your SDL_Rect source is only a 50x50 box.

http://www.lazyfoo.net read all of this

Code: Select all

SDL_BlitSurface(bitmap, NULL, screen, &destination);
This will display the full image.

Re: Trouble displaying images

Posted: Sun Sep 20, 2009 5:38 pm
by Jaxerhaxer
Thanks so much

Re: Trouble displaying images

Posted: Sun Sep 20, 2009 11:51 pm
by Joeyotrevor
Jaxerhaxer wrote:

Code: Select all

   if(5+5 == 10)
  rename("output.txt", "edit.txt");
What is this I don't even

Re: Trouble displaying images

Posted: Mon Sep 21, 2009 3:57 am
by RyanPridgeon
Joeyotrevor wrote:
Jaxerhaxer wrote:

Code: Select all

   if(5+5 == 10)
  rename("output.txt", "edit.txt");
What is this I don't even
^ LOL! LOL! LOL!

Stay in school kids.

Re: Trouble displaying images

Posted: Mon Sep 21, 2009 9:10 am
by dandymcgee
Joeyotrevor wrote:
Jaxerhaxer wrote:

Code: Select all

   if(5+5 == 10)
  rename("output.txt", "edit.txt");
What is this I don't even
:lol:

Re: Trouble displaying images

Posted: Wed Sep 23, 2009 4:32 pm
by Jaxerhaxer
It renames the file "edit.txt" to somthing else.
Don't make fun of my code :(

Re: Trouble displaying images

Posted: Wed Sep 23, 2009 5:17 pm
by Moosader
Joeyotrevor wrote:
Jaxerhaxer wrote:

Code: Select all

   if(5+5 == 10)
  rename("output.txt", "edit.txt");
What is this I don't even
... x_X

Why is there an if statement for something that's always true? Get rid of that top line. *whacks you with a stick*

Re: Trouble displaying images

Posted: Wed Sep 23, 2009 7:45 pm
by Jaxerhaxer
I like math so i put that :)