#ifndef SCREEN_H
#define SCREEN_H
#include<string>
#include "SDL/SDL.h"
class Screen
{
private:
Uint32 flags;
int width, hight,bpp;
std::string windowsname;
static int num;
SDL_Surface * screen;
public:
Screen(){width=320;hight=640;bpp=32;windowsname=" ";num++;screen=0;}
Screen(int w,int h,std::string & setname,Uint32 f);
~Screen();
SDL_Surface * showpoint();
void flip();
};
#endif
#include"screen.h"
int Screen::num=0;
Screen::Screen(int w,int h,std::string & setname,Uint32 f)
{
if (num==1)
throw "Screen can't be created more than one";
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
throw "SDL_INIT wrong";
if ((screen=SDL_SetVideoMode(w,h,32,f))!=0)
throw "screen can't be creen";
width=w;
hight=h;
bpp=32;
flags=f;
SDL_WM_SetCaption(setname.c_str(),NULL);
windowsname=setname;
}
Screen::~Screen()
{
SDL_Quit();
}
SDL_Surface * Screen::showpoint()
{
return screen;
}
void Screen::flip()
{
if ((SDL_Flip(screen))==-1)
throw "flip wrong";
}
#include"screen.h"
#include<string>
#include<iostream>
int main()
{std::string ms="hello";
try
{
Screen sc(640,320,ms,SDL_SWSURFACE);
}
catch (char*m)
{
std::cout<<m;
}
std::cout<<"successfully operated";
return 0;
}
不知道为什么无法编译~另外求新手求师傅一枚~
#define SCREEN_H
#include<string>
#include "SDL/SDL.h"
class Screen
{
private:
Uint32 flags;
int width, hight,bpp;
std::string windowsname;
static int num;
SDL_Surface * screen;
public:
Screen(){width=320;hight=640;bpp=32;windowsname=" ";num++;screen=0;}
Screen(int w,int h,std::string & setname,Uint32 f);
~Screen();
SDL_Surface * showpoint();
void flip();
};
#endif
#include"screen.h"
int Screen::num=0;
Screen::Screen(int w,int h,std::string & setname,Uint32 f)
{
if (num==1)
throw "Screen can't be created more than one";
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
throw "SDL_INIT wrong";
if ((screen=SDL_SetVideoMode(w,h,32,f))!=0)
throw "screen can't be creen";
width=w;
hight=h;
bpp=32;
flags=f;
SDL_WM_SetCaption(setname.c_str(),NULL);
windowsname=setname;
}
Screen::~Screen()
{
SDL_Quit();
}
SDL_Surface * Screen::showpoint()
{
return screen;
}
void Screen::flip()
{
if ((SDL_Flip(screen))==-1)
throw "flip wrong";
}
#include"screen.h"
#include<string>
#include<iostream>
int main()
{std::string ms="hello";
try
{
Screen sc(640,320,ms,SDL_SWSURFACE);
}
catch (char*m)
{
std::cout<<m;
}
std::cout<<"successfully operated";
return 0;
}
不知道为什么无法编译~另外求新手求师傅一枚~