Sign in to follow this  
Just Chris

X too big in getPixel

Recommended Posts

I've worked with SDL a bunch of times before, but I'm having problems adding in the SDL functions to a console app, since I'm trying to change the output from text to graphical. All I have right now is this simple code to display a blue window. But it just displays black, and produces stdout.txt with "x too big in GetPixel!" What does the X attribute refer to?
#include <iostream>
#include <string>
#include <time.h>

#include <SDL/sdl.h>
#include <BFont.c>

using namespace std;

void gameScene( void )
{
    SDL_FillRect(screen,NULL,0x112233);
}

int main(int argc, char *argv[])
{
  Uint8* keys;

  if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
  {
    printf("Unable to init SDL: %s\n", SDL_GetError());
    exit(1);
  }
  InitImages();
  atexit(SDL_Quit);

//SDL_DOUBLEBUF
  screen=SDL_SetVideoMode(800,600,32,SDL_SWSURFACE|SDL_HWPALETTE);
  if ( screen == NULL )
  {
    printf("Unable to set 800x600 video: %s\n", SDL_GetError());
    exit(1);
  }

  int done=0;

  while(done == 0)
  {
    SDL_Event event;
    SDL_PollEvent(&event);

      if ( event.type == SDL_QUIT )  {  done = 1;  }
      if ( event.type == SDL_KEYDOWN )
      {
        if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
      }
    keys = SDL_GetKeyState(NULL);

    gameScene();
  }
  return 0;
}

Share this post


Link to post
Share on other sites
Just a random guess..
Try calling the InitImages function AFTER setting the display mode. Bitmap loaders generally attempt to use the native pixel format, which simply isn't available yet.

Share this post


Link to post
Share on other sites
InitImages is a placeholder for when I choose the graphics I want to load. It has nothing in it right now. I ran the program without the function but that doesn't change anything.

Share this post


Link to post
Share on other sites
You're never actually displaying the updated back buffer, call SDL_Flip or SDL_UpdateRect in the main loop.
It still doesn't explain the GetPixel warning though..

Share this post


Link to post
Share on other sites
Quote:
Original post by doynax
You're never actually displaying the updated back buffer, call SDL_Flip or SDL_UpdateRect in the main loop.
It still doesn't explain the GetPixel warning though..


Oh thanks, I forgot to call SDL_Flip. It works great now!

Share this post


Link to post
Share on other sites
Also, in your function GameScene, you want to change the surface screen, but that function doesn't know any surface named screen.

The solution for this is:

- Make your SDL_Surface *screen; global (above your function)
- Or make sure your function GameScene requires the parameter for a SDL_Surface screen.

Share this post


Link to post
Share on other sites
Quote:
Original post by Spippo
Also, in your function GameScene, you want to change the surface screen, but that function doesn't know any surface named screen.

The solution for this is:

- Make your SDL_Surface *screen; global (above your function)
- Or make sure your function GameScene requires the parameter for a SDL_Surface screen.


Or the way i think is easier: Get rid of the screen surface, and use SDL_GetVideoSurface().

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just some questions out of curiousity:

1) Where was 'screen' declared again? I seem to have missed it...
2) Why are you including a '.c' file? Can't you just add it to a project?

C++

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this