Trouble displaying images

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Jaxerhaxer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 14
Joined: Fri Sep 04, 2009 7:39 pm

Trouble displaying images

Post 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;
}

User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: Trouble displaying images

Post by RyanPridgeon »

Can you explain what is your exact problem?

You know how to set the coordinates to display the image at, right?
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
Jaxerhaxer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 14
Joined: Fri Sep 04, 2009 7:39 pm

Re: Trouble displaying images

Post 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.
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Trouble displaying images

Post 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.
Jaxerhaxer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 14
Joined: Fri Sep 04, 2009 7:39 pm

Re: Trouble displaying images

Post by Jaxerhaxer »

Thanks so much
User avatar
Joeyotrevor
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 62
Joined: Thu Jan 22, 2009 6:24 pm
Programming Language of Choice: C++

Re: Trouble displaying images

Post by Joeyotrevor »

Jaxerhaxer wrote:

Code: Select all

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

Code: Select all

eb 0c 48 65 6c 6c 6f 20 77 6f 72 6c 64 21 31 d2 8e c2 30 ff b3 0a bd 02 7c b9 0b 00 b8 00 13 cd 10 eb fe
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: Trouble displaying images

Post 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.
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Trouble displaying images

Post 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:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Jaxerhaxer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 14
Joined: Fri Sep 04, 2009 7:39 pm

Re: Trouble displaying images

Post by Jaxerhaxer »

It renames the file "edit.txt" to somthing else.
Don't make fun of my code :(
User avatar
Moosader
Game Developer
Game Developer
Posts: 1081
Joined: Wed May 07, 2008 12:29 am
Current Project: Find out at: http://www.youtube.com/coderrach
Favorite Gaming Platforms: PC, NES, SNES, PS2, PS1, DS, PSP, X360, WII
Programming Language of Choice: C++
Location: Kansas City
Contact:

Re: Trouble displaying images

Post 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*
Jaxerhaxer
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 14
Joined: Fri Sep 04, 2009 7:39 pm

Re: Trouble displaying images

Post by Jaxerhaxer »

I like math so i put that :)
Post Reply