X too big in getPixel

Started by
7 comments, last by GameDev.net 18 years, 4 months ago
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;
}
Advertisement
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.
what does the code in InitImages() look like...

im guessing the x stands for x co-ordinate, but i dont see any calls to a getPixel function in your code...
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.
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..
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!

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.
Spippo is magic,is magic!!!!!Oh ho hoo!!!!Spippo is magic
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().
I program in my sleep,but when I sleep I use the partition in my head that doesnt have g++ or the .net library, so im kinda screwed.
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++

This topic is closed to new replies.

Advertisement