Beispiel #1
0
Game::Game()
{
    gui.reset(loadGUIFile("gui/app.xml"));
    gui->resize(SDL_GetVideoSurface()->w, SDL_GetVideoSurface()->h);

    Button* gameMenu = getButton( *gui, "GameMenuButton" );
    gameMenu->clicked.connect( makeCallback(*this, &Game::gameButtonClicked ));

    Button* helpButton = getButton( *gui, "HelpButton" );
    helpButton->clicked.connect( makeCallback(*this, &Game::gameButtonClicked ));

    Button* statButton = getButton( *gui, "StatButton" );
    statButton->clicked.connect( makeCallback(*this, &Game::gameButtonClicked ));

    Desktop* desktop = dynamic_cast<Desktop*> (gui.get());
    if(desktop == 0)
        throw std::runtime_error("Game UI is not a Desktop Component");
    helpWindow.reset(new HelpWindow(desktop));
    gameptr = this;
}
Beispiel #2
0
	surface& surface::get_video_surface() {
		bool init=false;
		try {
			main_surface.get_low();
		} catch (sdlw::exception_sdl&) {
			init=true;
		}
		if(init)
			main_surface.build(SDL_GetVideoSurface(),false);
		return main_surface;
	}
Beispiel #3
0
void SetPalette()
{
SDL_Color clColor;
for (int i=0;i<16;i++)
  {
  clColor.r=(ColorMap[i]&0xFF0000)>>16;
  clColor.g=(ColorMap[i]&0xFF00)>>8;
  clColor.b=ColorMap[i]&0xFF;
  SDL_SetColors(SDL_GetVideoSurface(), &clColor, i, 1);
  }
}
void HUD_Lua_Class::end_draw(void)
{
	m_drawing = false;
	
#ifdef HAVE_OPENGL
	if (m_opengl)
	{
        glMatrixMode(GL_MODELVIEW);
        glPopMatrix();
		glPopAttrib();
	}
	else
#endif
	if (m_surface)
	{
//		SDL_BlitSurface(m_surface, NULL, SDL_GetVideoSurface(), NULL);
		SDL_SetAlpha(SDL_GetVideoSurface(), 0, 0xff);
		SDL_SetClipRect(SDL_GetVideoSurface(), 0);
	}
}
Beispiel #5
0
//--------------------------------------------------------------------------------------------
SDL_bool SDLX_Get_Screen_Info( SDLX_screen_info_t * psi, SDL_bool make_report )
{
    Uint32 init_flags = 0;
    SDL_Surface * ps;
    const SDL_VideoInfo * pvi;

    memset( psi, 0, sizeof( *psi ) );

    init_flags = SDL_WasInit( SDL_INIT_EVERYTHING );
    if ( 0 == init_flags )
    {
        if ( make_report ) fprintf( LOCAL_STDOUT, "ERROR: SDLX_Get_Screen_Info() called before initializing SDL\n" );
        return SDL_FALSE;
    }
    else if ( HAS_NO_BITS( init_flags, SDL_INIT_VIDEO ) )
    {
        if ( make_report ) fprintf( LOCAL_STDOUT, "ERROR: SDLX_Get_Screen_Info() called before initializing SDL video driver\n" );
        return SDL_FALSE;
    }

    ps  = SDL_GetVideoSurface();
    pvi = SDL_GetVideoInfo();

    // store the screen info for everyone to use
    psi->pscreen = ps;
    psi->d = ps->format->BitsPerPixel;
    psi->x = ps->w;
    psi->y = ps->h;

    // Grab all the available video modes
    psi->video_mode_list = SDL_ListModes( ps->format, ps->flags | SDL_FULLSCREEN );

    // log the video driver info
    SDL_VideoDriverName( psi->szDriver, sizeof( psi->szDriver ) );

    // grab all SDL_GL_* attributes
    SDLX_read_sdl_gl_attrib( &( psi->gl_att ) );

    // translate the surface flags into the bitfield
    SDLX_download_sdl_video_flags( ps->flags, &( psi->flags ) );

    psi->hw_available = pvi->hw_available;
    psi->wm_available = pvi->wm_available;
    psi->blit_hw      = pvi->blit_hw;
    psi->blit_hw_CC   = pvi->blit_hw_CC;
    psi->blit_hw_A    = pvi->blit_hw_A;
    psi->blit_sw      = pvi->blit_sw;
    psi->blit_sw_CC   = pvi->blit_sw_CC;
    psi->blit_sw_A    = pvi->blit_sw_A;

    if ( make_report ) SDLX_Report_Screen_Info( psi );

    return SDL_TRUE;
}
Beispiel #6
0
static void			OPTIONS_Draw				(const char* aDescription, OPTIONS_Draw_GetString aCallback, uint32_t aSelected)
{
	SDL_Surface* text;
	int32_t index = 0;
	SDL_Color c_active = {0xFF, 0xFF, 0xFF, 0xFF}, c_inactive = {0x50, 0x50, 0x50, 0xFF}, bg = {0, 32, 64, 0};
	SDL_Rect DrawPosition = {10, 50, 0, 0};

	/* Clear the screen */
	SDL_FillRect(SDL_GetVideoSurface(), 0, SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 32, 64));

	/* Draw the description */
	if(aDescription)
	{
		SDL_Rect descposition = {10, 10, 0, 0};
		text = STRING_Render(aDescription, c_active, bg);
		SDL_BlitSurface(text, 0, SDL_GetVideoSurface(), &descposition);
		SDL_FreeSurface(text);
	}

	/* Draw the strings */
	while(1)
	{
		const char* string = aCallback(index);

		if(string)
		{
			text = STRING_Render(string, (index == aSelected) ? c_active : c_inactive, bg);
			SDL_BlitSurface(text, 0, SDL_GetVideoSurface(), &DrawPosition);
			DrawPosition.y += text->h;
			SDL_FreeSurface(text);
		}
		else
		{
			break;
		}

		index ++;
	}

	SDL_Flip(SDL_GetVideoSurface());
}
Beispiel #7
0
	void prepare_raster()
	{
		//	int real_w, real_h;
		//	bool rotated;
		
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
		//	real_w = 320;
		//	real_h = 480;
		//	rotated = true;
#else
		const SDL_Surface* fb = SDL_GetVideoSurface();
		if(fb == NULL) {
			std::cerr << "Framebuffer was null in prepare_raster\n";
			return;
		}
		//	real_w = fb->w;
		//	real_h = fb->h;
		//	rotated = false;
#endif
		
		glViewport(0, 0, preferences::actual_screen_width(), preferences::actual_screen_height());
//		glClearColor(0.0, 0.0, 0.0, 0.0);
//		glClear(GL_COLOR_BUFFER_BIT);
		glShadeModel(GL_FLAT);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		
		if(preferences::screen_rotated()) {
			//		glOrtho(0, 640, 960, 0, -1.0, 1.0);
			glOrtho(0, screen_height(), screen_width(), 0, -1.0, 1.0);
		} else {
			glOrtho(0, screen_width(), screen_height(), 0, -1.0, 1.0);
		}
		
		//glOrtho(0, real_w, real_h, 0, -1.0, 1.0);
		if(preferences::screen_rotated()) {
			// Rotate 90 degrees ccw, then move real_h pixels down
			// This has to be in opposite order since A(); B(); means A(B(x))
			glTranslatef(screen_height(), 0.0f, 0.0f);
			glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
			//glTranslatef(0.0f, 0.5f, 0.0f);
			//glScalef(0.5f, 0.5f, 1.0f);
		}
		
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_LIGHTING);
		glDisable(GL_LIGHT0);
		
		glColor4f(1.0, 1.0, 1.0, 1.0);
	}
Beispiel #8
0
void
scrnmng_menudraw(const RECT_T *rct)
{
	DRAWRECT dr;
	SDL_Surface *surface;
	const BYTE *p;
	const BYTE *q;
	BYTE *r;
	BYTE *a;
	int salign;
	int dalign;
	int x;

	if ((!scrnmng.enable) && (menuvram == NULL))
		return;

	surface = SDL_GetVideoSurface();
	if (surface == NULL)
		return;

	SDL_LockSurface(surface);
	if (calcdrawrect(surface, &dr, menuvram, rct) == SUCCESS) {
		if (scrnmng.sm.bpp == 16) {
			p = scrnmng.vram->ptr + (dr.srcpos * 2);
			q = menuvram->ptr + (dr.srcpos * 2);
			r = (BYTE *)surface->pixels + dr.dstpos;
			a = menuvram->alpha + dr.srcpos;
			salign = menuvram->width;
			dalign = dr.yalign - (dr.width * dr.xalign);
			do {
				x = 0;
				do {
					if (a[x]) {
						if (a[x] & 2) {
							*(UINT16 *)r = *(UINT16 *)(q + (x * 2));
						}
						else {
							a[x] = 0;
							*(UINT16 *)r = *(UINT16 *)(p + (x * 2));
						}
					}
					r += dr.xalign;
				} while (++x < dr.width);
				p += salign * 2;
				q += salign * 2;
				r += dalign;
				a += salign;
			} while (--dr.height);
		}
	}
	SDL_UnlockSurface(surface);
	SDL_Flip(surface);
}
Beispiel #9
0
void Map::render()
{
    SDL_Surface * screen = SDL_GetVideoSurface();
    SDL_Rect rect = Camera::getInstance()->getRect();
    SDL_BlitSurface( m_pSurface.get(), &rect, screen, NULL );

    //Rendering Entities
    std::for_each( m_Bullets.begin(), m_Bullets.end(), std::mem_fun_ref( &Bullet::render ));
    std::for_each( m_Shields.begin(), m_Shields.end(), std::mem_fun_ref( &Shield::render ));
    std::for_each( m_Stars.begin(), m_Stars.end(), std::mem_fun_ref( &Star::render ));
    std::for_each( m_Obstacles.begin(), m_Obstacles.end(), std::mem_fun_ref( &Obstacle::render ));
}
Beispiel #10
0
void render_list(struct game *game)
{
	SDL_Surface *message = NULL, *screen = NULL;
	SDL_Color color_norm = {0,0,0};
	SDL_Color color_high = {255,255,255};
	int i, j, tmp;
	
	for(i=0; i<game->num_buttonlist; i++)
	{
		message = TTF_RenderText_Blended(game->font_yo_frankie, game->buttonlist[i].label, color_norm);
		screen = SDL_GetVideoSurface();
		tmp = game->buttonlist[i].selected;
		if(	game->mouse.x_input >= game->buttonlist[i].x - game->button_l->w && game->mouse.x_input <= game->buttonlist[i].x + message->w + game->button_r->w &&
				game->mouse.y_input >= game->buttonlist[i].y && game->mouse.y_input <= game->buttonlist[i].y + game->button_c->h)
		{
			SDL_FreeSurface(message);
			message = TTF_RenderText_Blended(game->font_yo_frankie, game->buttonlist[i].label, color_high);
			game->buttonlist[i].selected = 1;
		}
		else
			game->buttonlist[i].selected = 0;
			
		if(tmp != game->buttonlist[i].selected && game->buttonlist[i].menu == game->menu)
			game->update = 1;
			
		game->buttonlist[i].w = message->w + game->button_l->w + game->button_r->w;
		if(message->h > game->button_c->h)
			game->buttonlist[i].h = message->h;
		else
			game->buttonlist[i].h = game->button_c->h;

		if(game->buttonlist[i].menu == game->menu)
		{
			if(game->buttonlist[i].selected)
			{
				for(j=0; j<message->w; j+=game->button_ch->w)
					apply_surface(game->buttonlist[i].x+j, game->buttonlist[i].y, game->button_ch, screen, NULL);
				apply_surface(game->buttonlist[i].x - game->button_lh->w, game->buttonlist[i].y, game->button_lh, screen, NULL);
				apply_surface(game->buttonlist[i].x + j, game->buttonlist[i].y, game->button_rh, screen, NULL);
			}
			else
			{
				for(j=0; j<message->w; j+=game->button_c->w)
					apply_surface(game->buttonlist[i].x+j, game->buttonlist[i].y, game->button_c, screen, NULL);
				apply_surface(game->buttonlist[i].x - game->button_l->w, game->buttonlist[i].y, game->button_l, screen, NULL);
				apply_surface(game->buttonlist[i].x + j, game->buttonlist[i].y, game->button_r, screen, NULL);
			}
	
			apply_surface(game->buttonlist[i].x, game->buttonlist[i].y + (game->button_c->h - message->h) / 2, message, screen, NULL);
		}
		SDL_FreeSurface(message);
	}
}
Beispiel #11
0
void HotKey_ToggleFullScreen(void)
{
	SDL_Surface *screen;

	screen = SDL_GetVideoSurface();
	if ( SDL_WM_ToggleFullScreen(screen) ) {
		printf("Toggled fullscreen mode - now %s\n",
		    (screen->flags&SDL_FULLSCREEN) ? "fullscreen" : "windowed");
	} else {
		printf("Unable to toggle fullscreen mode\n");
	}
}
Beispiel #12
0
// Отмена интерактьивного режима
// После вызова этой функции можно вызывать CheckKeys()
void LeaveInteractiveMode()
{
// SDL_WM_SetCaption("Not Interactive",0);
bInteractive=0;
SDL_EnableKeyRepeat(0, 0);
SDL_EnableUNICODE(0);
bBlinkCursor=1;
StartSound();
FlushKeys();
if (vmVideoMode==vmGraph512)
  SDL_FillRect(SDL_GetVideoSurface(),0,0);
//............
}
Beispiel #13
0
void mSDLSWDeinit(struct mSDLRenderer* renderer) {
	if (renderer->ratio > 1) {
		free(renderer->outputBuffer);
	}
#if !SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_Surface* surface = SDL_GetVideoSurface();
	SDL_UnlockSurface(surface);
#ifdef USE_PIXMAN
	pixman_image_unref(renderer->pix);
	pixman_image_unref(renderer->screenpix);
#endif
#endif
}
Beispiel #14
0
bool Sprite::draw(int x, int y) {

    rect.x = x;
    rect.y = y;

    if(SDL_BlitSurface(image, NULL, SDL_GetVideoSurface(), &rect) < 0) { // attempt to draw sprite
        cout<<"BlitSurface error" << SDL_GetError() <<"\n";
        return false;
    }
    else {
        return true;
    }
} // end draw
Beispiel #15
0
  IntSize getScreenSize()
  {
    __gfx__assert_open();

    SDL_Surface *screen;

    screen = SDL_GetVideoSurface();

    if(screen != NULL)
      return IntSize(screen->w, screen->h);
    else
      return IntSize(0, 0);
  }
void BlackHole::drawUnit(View &view) {
	SDL_Surface *surface = SDL_GetVideoSurface();

	SDL_Rect rect;
	rect.x = (x - view.x)*view.zoom;
	rect.y = (y - view.y)*view.zoom;
	rect.w = w*view.zoom;
	rect.h = h*view.zoom;

	Uint32 color = SDL_MapRGB(surface->format,0,0,0);

	SDL_FillRect(surface,&rect,color);
}
Beispiel #17
0
void Module::onUpdate(Graphics *graphics)
{
	graphics->clear(0x115588);

	SDL_Rect temp;
	temp.x = pos_x-16;
	temp.y = pos_y-16;
	temp.w = 32;
	temp.h = 32;
	graphics->draw(temp, SDL_MapRGB(SDL_GetVideoSurface()->format, rand()%255, rand()%255, rand()%255));
	graphics->draw(l);
	graphics->update();
}
Beispiel #18
0
void mSDLSWRunloop(struct mSDLRenderer* renderer, void* user) {
	struct mCoreThread* context = user;
	SDL_Event event;
#if !SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_Surface* surface = SDL_GetVideoSurface();
#endif

	while (mCoreThreadIsActive(context)) {
		while (SDL_PollEvent(&event)) {
			mSDLHandleEvent(context, &renderer->player, &event);
		}

		if (mCoreSyncWaitFrameStart(&context->impl->sync)) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
			SDL_UnlockTexture(renderer->sdlTex);
			SDL_RenderCopy(renderer->sdlRenderer, renderer->sdlTex, 0, 0);
			SDL_RenderPresent(renderer->sdlRenderer);
			int stride;
			SDL_LockTexture(renderer->sdlTex, 0, (void**) &renderer->outputBuffer, &stride);
			renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, stride / BYTES_PER_PIXEL);
#else
#ifdef USE_PIXMAN
			if (renderer->ratio > 1) {
				pixman_image_composite32(PIXMAN_OP_SRC, renderer->pix, 0, renderer->screenpix,
				    0, 0, 0, 0, 0, 0,
				    renderer->viewportWidth, renderer->viewportHeight);
			}
#else
			switch (renderer->ratio) {
#if defined(__ARM_NEON) && COLOR_16_BIT
			case 2:
				_neon2x(surface->pixels, renderer->outputBuffer, width, height);
				break;
			case 4:
				_neon4x(surface->pixels, renderer->outputBuffer, width, height);
				break;
#endif
			case 1:
				break;
			default:
				abort();
			}
#endif
			SDL_UnlockSurface(surface);
			SDL_Flip(surface);
			SDL_LockSurface(surface);
#endif
		}
		mCoreSyncWaitFrameEnd(&context->impl->sync);
	}
}
void
main_loop (void)
{
  SDL_Surface *screen;
  Uint32 color;
  unsigned c_shift, run;

  fprintf (stderr, "Type 'q' or Escape to exit\n");

  screen = SDL_GetVideoSurface ();
  run = 1;
  color = 0x000000;
  c_shift = 1;
  while (run) {
    SDL_Event event;

    while (SDL_PollEvent (&event)) {
      switch (event.type) {
      case SDL_QUIT:
        run = 0;
        break;

      case SDL_KEYDOWN:
        switch (event.key.keysym.sym) {
        case SDLK_q:
        case SDLK_ESCAPE:
          run = 0;
          break;
        default:
          break;
        }
        break;

      default:
        break;
      }
    }

    SDL_FillRect (screen, NULL, color);
    SDL_Flip (screen);
    color |= 0x1 << c_shift;
    c_shift ++;

    if (c_shift >= 32) {
      c_shift = 0;
      color = 0;
    }

    SDL_Delay (20);
  }
}
Beispiel #20
0
void Menu::reconfigureDisplay()
{
		painted = true;
		
		glViewport(0, 0, SDL_GetVideoSurface()->w, SDL_GetVideoSurface()->h);
	
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluOrtho2D(0, SDL_GetVideoSurface()->w, 0, SDL_GetVideoSurface()->h);
		glScalef(1, -1, 1);
		glTranslatef(0, -SDL_GetVideoSurface()->h, -1);
// No Windows, eh necessario recarregar as texturas
#ifdef _WIN32
		this->init();

		vector<sItem> copia(iteminfo);
		MenuItem *mi;
		int tex;
		sItem si;

		for (i = 0; i < items.size(); i++) {
			mi = items[i];
			tex = mi->getImage();
			glDeleteTextures(1, (GLuint *)&tex);
			tex = mi->getHoverImage();
			glDeleteTextures(1, (GLuint *)&tex);
			delete mi;
		}

		items.clear();
		iteminfo.clear();
		
		for (i = 0; i < copia.size(); i++) {
			si = copia[i];
			this->addItem(si.id, si.image, si.hover_image, si.x, si.y, si.al);
		}
#endif
}
Beispiel #21
0
void render_array(double map[LENGTH][HEIGHT])
{
  SDL_Surface* dest = SDL_GetVideoSurface();
  int i, j; 
  for (i = 0; i < LENGTH; i++)
    for (j = 0; j < HEIGHT; j++)
      {
        SDL_Rect pix = {i, j, 1, 1};
        int darkness = CAP_TO_1(fabs(map[i][j])) * 0xff;
        SDL_FillRect(dest, &pix,
          SDL_MapRGB(dest->format, darkness, darkness, darkness));
      }
  return;
}
Beispiel #22
0
static void draw() {
    int sel;

    SDL_Surface *screen = SDL_GetVideoSurface();

    SDL_FillRect(screen, NULL, 0);
    menu_blit_word_string(dialog->prompt, screen->w/2, screen->h/3);

    for(sel = 0; sel < dialog->active_selections; sel++) {
        menu_blit_label(dialog->selections[sel], ALIGN_CENTER, selection == sel ? 1 : 0, screen->w/(dialog->active_selections+1) * (sel+1), screen->h*2/3);
    }

    SDL_Flip(screen);
}
Beispiel #23
0
/*
===============
GLimp_EndFrame

Responsible for doing a swapbuffers
===============
*/
void GLimp_EndFrame( void )
{
	#ifdef HAVE_GLES
	EGL_SwapBuffers();
	#else
	// don't flip if drawing to front buffer
	if ( Q_stricmp( r_drawBuffer->string, "GL_FRONT" ) != 0 )
	{
		SDL_GL_SwapBuffers();
	}
	#endif

	if( r_fullscreen->modified )
	{
		qboolean    fullscreen;
		qboolean    needToToggle = qtrue;
		qboolean    sdlToggled = qfalse;
		SDL_Surface *s = SDL_GetVideoSurface( );

		if( s )
		{
			// Find out the current state
			fullscreen = !!( s->flags & SDL_FULLSCREEN );
				
			if( r_fullscreen->integer && Cvar_VariableIntegerValue( "in_nograb" ) )
			{
				ri.Printf( PRINT_ALL, "Fullscreen not allowed with in_nograb 1\n");
				ri.Cvar_Set( "r_fullscreen", "0" );
				r_fullscreen->modified = qfalse;
			}

			// Is the state we want different from the current state?
			needToToggle = !!r_fullscreen->integer != fullscreen;

			if( needToToggle )
				sdlToggled = SDL_WM_ToggleFullScreen( s );
		}

		if( needToToggle )
		{
			// SDL_WM_ToggleFullScreen didn't work, so do it the slow way
			if( !sdlToggled )
				Cbuf_AddText( "vid_restart" );

			IN_Restart( );
		}

		r_fullscreen->modified = qfalse;
	}
}
Beispiel #24
0
void cEnemy::Show(SDL_Rect camera)
{
    frame ++;
    if(frame >= 2)
    frame = 0;
    SDL_SetColorKey(image,SDL_SRCCOLORKEY,SDL_MapRGB(image->format,0,255,255));
    SDL_Rect rect;
    rect.x = box.x - camera.x;
    rect.y = box.y - camera.y;
    SDL_Rect clip[2];
    clip[0] = {0,0,40,40};
    clip[1] = {40,0,40,40};
    SDL_BlitSurface(image,&clip[frame],SDL_GetVideoSurface(),&rect);
}
Beispiel #25
0
//------------------------------------------------------------------------------
static inline void AlertDisableVideo(AlertWinState& state)
{

   state.fullScreen = Video::isFullScreen();
   state.cursorHidden = (SDL_ShowCursor(SDL_QUERY) == SDL_DISABLE);
   state.inputGrabbed = (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON);

   if (state.fullScreen)
      SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
   if (state.cursorHidden)
      SDL_ShowCursor(SDL_ENABLE);
   if (state.inputGrabbed)
      SDL_WM_GrabInput(SDL_GRAB_OFF);
}
Beispiel #26
0
SDL_Surface*	SDL_CreateSurface(int width, int height)
{
	SDL_Surface* result = NULL;
	SDL_Surface* video = SDL_GetVideoSurface();
	
	result = SDL_CreateRGBSurface(	video->flags, width, height,
									video->format->BitsPerPixel, 
									video->format->Rmask, 
									video->format->Gmask, 
									video->format->Bmask, 
									video->format->Amask);
									
	return result;
}
Beispiel #27
0
void vid_lock()
{

	SDL_Surface *surface;
	surface = SDL_GetVideoSurface();
	assert(surface);
	
	if (SDL_LockSurface(surface) != 0)
	{
		printf("vid_lock(): Unable to lock video surface: %s\n", SDL_GetError());
		agi_exit();
	}

}
Beispiel #28
0
void Sprite::render(const b2Vec2 & pos)
{
    if( m_Sprites.empty() )
        return;

    SDL_Surface * screen = SDL_GetVideoSurface();
    SDL_Surface * image = m_Sprites[m_iFrameNo].get();

    SDL_Rect rect;
	rect.x = pos.x - image->w/2;
	rect.y = pos.y - image->h/2;

    SDL_BlitSurface( image , NULL, screen, &rect);
}
Beispiel #29
0
	// Returns a pointer on success, NULL on an error
	SDL_Surface *initiateSDL(int x, int y)
	{
		SDL_Surface *screen = NULL;
		SDL_Surface *vid_init;
		int init;//, ttf_ret;
	
		// Initiate SDL and check
		init = SDL_Init(SDL_INIT_VIDEO);
		if(init < 0)
		{
			fprintf(stderr, "Unable to initiate SDL: %s\n", SDL_GetError());
			return NULL;
		}

		
		// Set video and check
		vid_init = SDL_SetVideoMode(x, y, 32, SDL_SWSURFACE);
		if(vid_init == 0)
		{
		    fprintf(stderr, "Video initialization failed: %s", SDL_GetError());
		    return NULL;
		}


		// Get video surface and check
		screen = SDL_GetVideoSurface();
		if(screen == NULL)
		{
		    fprintf(stderr, "Failed to get video surface: %s", SDL_GetError());
		    return NULL;
		}

		// Set window title
		SDL_WM_SetCaption(WINDOW_TITLE " " VERSION, 0);

		/*
		// Initialize SDL_ttf and check
		ttf_ret = TTF_Init();
		if(ttf_ret == -1)
		{
		    fprintf(stderr, "True Type Font initialization failed: %s", SDL_GetError());
		    return NULL;
		}
		*/
		
		SDL_FreeSurface(vid_init);

		// Success
		return screen;
	}
Beispiel #30
0
void main()
{
    SDL_Surface *window =init(800,600);
    int          running = 1;
    SDL_Rect     rect1,rect2;
    Uint32       deb;
    int          b[4]={0,0,0,0};
    int          fps=60;

    SDL_Surface *tux       = SDL_DisplayFormat(SDL_LoadBMP("img/tux.bmp"));
    SDL_Surface *gnu       = SDL_DisplayFormat(SDL_LoadBMP("img/gnu.bmp"));
    SDL_Surface *wallpaper = SDL_DisplayFormat(SDL_LoadBMP("img/linux.bmp"));

    SDL_SetColorKey(tux,SDL_SRCCOLORKEY,SDL_MapRGB(window->format,255,0,0));
    SDL_SetColorKey(gnu,SDL_SRCCOLORKEY,SDL_MapRGB(window->format,255,255,255));

    rect1.x=10;                         rect1.y=200;
    rect2.x=SDL_GetVideoSurface()->w/2; rect2.y=SDL_GetVideoSurface()->h/2;

    while(running)
    {
        deb=SDL_GetTicks();

        GetEvent(&running,b);
        MoveObjects(b,&rect1,&rect2);
        SetChanges(window,wallpaper,gnu,tux,&rect1,&rect2);

        if(1000/fps > SDL_GetTicks() - deb)
            SDL_Delay(1000/fps - SDL_GetTicks() + deb);

        SDL_Flip(window);

    }

    SDL_Quit();

}