rendered paste bodyusing System;
using System.Collections.Generic;
using System.Text;
using Tao.Sdl;
using System.Runtime.InteropServices;
namespace LazyFooTut2
{
class Tutorial2
{
//Screen sizes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;
System.IntPtr message;
System.IntPtr background;
System.IntPtr screen;
Sdl.SDL_Event evt;
public System.IntPtr load_image( string filename )
{
System.IntPtr loadedImage;
System.IntPtr optimizedImage = IntPtr.Zero;
//load the image
loadedImage = SdlImage.IMG_Load(filename);
if (loadedImage != IntPtr.Zero )
{
optimizedImage = Sdl.SDL_DisplayFormat(loadedImage);
Sdl.SDL_FreeSurface(loadedImage);
}
return optimizedImage;
}
public void applySurface(short x, short y, System.IntPtr source, System.IntPtr destination)
{
Sdl.SDL_Rect offset = new Sdl.SDL_Rect();
Sdl.SDL_Rect original = new Sdl.SDL_Rect();
original.x = 0;
original.y = 0;
original.w = (short)((Sdl.SDL_Surface)Marshal.PtrToStructure(source, typeof(Sdl.SDL_Surface))).w;
original.h = (short)((Sdl.SDL_Surface)Marshal.PtrToStructure(source, typeof(Sdl.SDL_Surface))).h;
offset.x = x;
offset.y = y;
Sdl.SDL_BlitSurface(source, ref original, destination, ref offset);
}
void run()
{
bool quit = false;
if (Sdl.SDL_Init( Sdl.SDL_INIT_EVERYTHING ) == -1 )
return;
screen = Sdl.SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, Sdl.SDL_SWSURFACE );
if ( screen == IntPtr.Zero )
return;
Sdl.SDL_WM_SetCaption("Hello World", null);
message = load_image("hello_world.bmp");
background = load_image("background.bmp");
applySurface(0, 0, background, screen);
applySurface(180, 140, message, screen);
if (Sdl.SDL_Flip( screen ) == -1 )
return;
while (!quit)
{
while (Sdl.SDL_PollEvent(out evt) != 0)
{
if (evt.type == Sdl.SDL_QUIT)
{
quit = true;
}
}
}
Sdl.SDL_FreeSurface(message);
Sdl.SDL_FreeSurface(background);
Sdl.SDL_Quit();
}
static void Main(string[] args)
{
Tutorial2 tut2 = new Tutorial2();
tut2.run();
}
}
}