diff options
| author | pixel <pixel> | 2004-07-04 11:56:18 +0000 | 
|---|---|---|
| committer | pixel <pixel> | 2004-07-04 11:56:18 +0000 | 
| commit | 5cc874802b0b8c4462e7e873654e6daa54be00de (patch) | |
| tree | d97bfbfe26998b1ee9cf01d830ba446e61094a86 | |
| parent | bf452e7f6a3fa0e41964fc8e2c57e1e577cd1682 (diff) | |
SOL Demo
| -rw-r--r-- | include/base.h | 5 | ||||
| -rw-r--r-- | include/engine.h | 10 | ||||
| -rw-r--r-- | include/glbase.h | 4 | ||||
| -rw-r--r-- | include/texture.h | 6 | ||||
| -rw-r--r-- | lib/base.cc | 51 | ||||
| -rw-r--r-- | lib/engine.cc | 15 | ||||
| -rw-r--r-- | lib/font.cc | 2 | ||||
| -rw-r--r-- | lib/glbase.cc | 86 | ||||
| -rw-r--r-- | lib/texture.cc | 50 | ||||
| -rw-r--r-- | src/test.cc | 557 | 
10 files changed, 733 insertions, 53 deletions
diff --git a/include/base.h b/include/base.h index 66e3172..0aecf8c 100644 --- a/include/base.h +++ b/include/base.h @@ -3,6 +3,7 @@  #include <SDL.h>  #include <Exceptions.h> +#include <texture.h>  namespace mogltk {      struct rect { @@ -14,13 +15,15 @@ namespace mogltk {  	  virtual ~base();          int GetWidth(void);          int GetHeight(void); -	virtual void Flip(void); +	virtual void Flip(bool clear = true);  	SDL_Surface * getsurface();  	virtual void Enter2DMode();  	virtual void Leave2DMode();  	virtual bool is2D();  	virtual void changeviewport(int x = 0, int y = 0, unsigned int w = 0, unsigned int h = 0);          void ToggleFullscreen(); +        virtual texture * GrabTexture(); +        virtual SDL_Surface * GrabSurface();        protected:            base(int, int, int, int);  	void setsurface(SDL_Surface *) throw (GeneralException); diff --git a/include/engine.h b/include/engine.h index 6a88154..6dbd990 100644 --- a/include/engine.h +++ b/include/engine.h @@ -15,20 +15,18 @@ namespace mogltk {  	  public:                keyevent();                virtual ~keyevent(); -	    virtual void down(SDL_keysym); -	    virtual void up(SDL_keysym); +	    virtual void down(SDL_keysym) = 0; +	    virtual void up(SDL_keysym) = 0;            protected: -            void passdown(SDL_keysym);              keyevent * old_handler, * new_handler;  	};          class mouseevent : public Base {            public:                mouseevent();                virtual ~mouseevent(); -            virtual void move(SDL_MouseMotionEvent); -            virtual void action(SDL_MouseButtonEvent); +            virtual void move(SDL_MouseMotionEvent) = 0; +            virtual void action(SDL_MouseButtonEvent) = 0;            protected: -            void passdown(SDL_MouseMotionEvent);              mouseevent * old_handler, * new_handler;          };          static int setup() throw(GeneralException); diff --git a/include/glbase.h b/include/glbase.h index 7e6d454..9069d69 100644 --- a/include/glbase.h +++ b/include/glbase.h @@ -13,7 +13,7 @@ namespace mogltk {  	  virtual ~glbase();  	virtual void Enter2DMode(void);  	virtual void Leave2DMode(void); -	virtual void Flip(void); +	virtual void Flip(bool clear = true);  	virtual bool is2D(void);  	virtual void changeviewport(int x = 0, int y = 0, unsigned int w = 0, unsigned int h = 0);  	void changefovy(GLdouble); @@ -21,6 +21,8 @@ namespace mogltk {  	static void glVertex(GLint, GLint, GLint = 0, GLint = 1);  	static void glVertex(GLfloat, GLfloat, GLfloat = 0.0, GLfloat = 1.0);  	static void glVertex(GLdouble, GLdouble, GLdouble = 0.0, GLdouble = 1.0); +        virtual texture * GrabTexture(); +        virtual SDL_Surface * GrabSurface();        private:          int twoD;  	GLdouble ratio, fovy; diff --git a/include/texture.h b/include/texture.h index 3b60e5b..44e2efe 100644 --- a/include/texture.h +++ b/include/texture.h @@ -10,8 +10,9 @@  namespace mogltk {      class texture : public Base {        public: -          texture(int = 256, int = 256, bool = false) throw (GeneralException); +          texture(int, int, bool = false) throw (GeneralException);  	  texture(Handle *, bool = false) throw (GeneralException); +          texture(int, int, int, int);  	  virtual ~texture();  	SDL_Surface * GetSurface();  	Uint32 * GetPixels(); @@ -24,11 +25,12 @@ namespace mogltk {  	static void Unbind(void);  	void Taint(void);          static void Taintall(void); +        void DumpBMP(const String &);        private:          GLuint width, height, tex;  	bool texture_allocated;  	SDL_Surface * surface; -	bool planar, tainted; +	bool planar, tainted, taintable;  	static texture * header;  	static texture * footer;  	texture * next, * prev; diff --git a/lib/base.cc b/lib/base.cc index acfc654..fd5c1da 100644 --- a/lib/base.cc +++ b/lib/base.cc @@ -46,10 +46,11 @@ int mogltk::base::GetHeight(void) {      return height;  } -void mogltk::base::Flip() { +void mogltk::base::Flip(bool clear) {      mogltk::engine::pollevents();      SDL_Flip(surface); -    SDL_FillRect(surface, NULL, 0); +    if (clear) +        SDL_FillRect(surface, NULL, 0);  }  mogltk::base::base(int w, int h, int flags, int) : surface(0) { @@ -108,3 +109,49 @@ void mogltk::base::ToggleFullscreen() {      surface = SDL_SetVideoMode(surface->w, surface->h, surface->format->BitsPerPixel,          SDL_HWSURFACE | newflags);  } + +inline static unsigned int nextpower(unsigned int n) { +    unsigned int i; + +    if (!n) +        return n; + +    if (ISPOT(n)) +        return n; + +    for (i = 31; i >= 0; i--) { +        if ((n >> i) & 1) { +            return 1 << (i + 1); +        } +    } +} + +mogltk::texture * mogltk::base::GrabTexture() { +    int w = nextpower(GetWidth()); +    int h = nextpower(GetHeight()); +    texture * r = new texture(w, h); + +    SDL_BlitSurface(getsurface(), NULL, r->GetSurface(), NULL); + +    return r; +} + +SDL_Surface * mogltk::base::GrabSurface() { +    SDL_Surface * r = SDL_CreateRGBSurface(SDL_SWSURFACE, GetWidth(), GetHeight(), 24, +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +	0xff000000, +	0x00ff0000, +	0x0000ff00, +	0x00000000 +#else +	0x000000ff, +	0x0000ff00, +	0x00ff0000, +	0x00000000 +#endif +        ); + +    SDL_BlitSurface(getsurface(), NULL, r, NULL); + +    return r; +} diff --git a/lib/engine.cc b/lib/engine.cc index 3a2aaa0..34317b1 100644 --- a/lib/engine.cc +++ b/lib/engine.cc @@ -49,6 +49,21 @@ void mogltk::engine::keyevent::down(SDL_keysym) {      printm(M_INFO, "Generic keyevent::down called\n");  } +class keyhandler_t : public mogltk::engine::keyevent { +    virtual void down(SDL_keysym keysym) { +        if (keysym.sym == SDLK_ESCAPE) +            mogltk::engine::quit(); +        else if ((keysym.sym == SDLK_RETURN) && (keysym.mod & KMOD_ALT)) +            mogltk::engine::base_o->ToggleFullscreen(); +        else if (old_handler) +            old_handler->down(keysym); +    } +    virtual void up(SDL_keysym keysym) { +        if (old_handler) +            old_handler->up(keysym); +    } +} basic_keyhandler; +  mogltk::engine::mouseevent::mouseevent() {      new_handler = 0;      old_handler = getmouseevent(); diff --git a/lib/font.cc b/lib/font.cc index 4062c37..5534cfc 100644 --- a/lib/font.cc +++ b/lib/font.cc @@ -516,7 +516,7 @@ mogltk::rect mogltk::font::printtotex(texture * t, const char * p, ...) {      return r;  } -inline unsigned int nextpower(unsigned int n) { +inline static unsigned int nextpower(unsigned int n) {      unsigned int i;      if (!n) diff --git a/lib/glbase.cc b/lib/glbase.cc index 3d89644..9c33c54 100644 --- a/lib/glbase.cc +++ b/lib/glbase.cc @@ -1,6 +1,8 @@  #include <stdio.h>  #include <SDL.h>  #include <SDL_opengl.h> +#include <Output.h> +#include <Handle.h>  #include "glbase.h"  #include "engine.h"  #include "generic.h" @@ -10,12 +12,24 @@  mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : mogltk::base(w, h, flags, 0), twoD(0), fovy(60.0) {      SDL_Surface * surface; +    GLint bits;      mogltk::engine::setup();      if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {          throw GeneralException(String("Couldn't initialise Video SubSystem: ") + SDL_GetError());      } +#if 1 +    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); +    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); +    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); +//    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32); +    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); +    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); +    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8); +    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8); +    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8); +#endif        if (!(surface = SDL_SetVideoMode(w, h, 0, flags | SDL_OPENGL | SDL_HWSURFACE))) {          throw GeneralException(String("Couldn't set GL mode: ") + SDL_GetError());      } @@ -25,6 +39,8 @@ mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : moglt      ratio = (GLdouble) surface->w / surface->h; +    glGetIntegerv(GL_STENCIL_BITS, &bits); +      printm(M_INFO, "Video resolution: %dx%dx%d (ratio = %3.2f)\n", surface->w, surface->h, surface->format->BitsPerPixel, ratio);      printm(M_INFO, "\n");      printm(M_INFO, "OpenGL infos\n"); @@ -34,6 +50,9 @@ mogltk::glbase::glbase(int w, int h, int flags) throw (GeneralException) : moglt      printm(M_INFO, String("Version   : ") + (char *) glGetString(GL_VERSION) + "\n");      printm(M_INFO, String("Extensions: ") + (char *) glGetString(GL_EXTENSIONS) + "\n"); +    Output e("ext.txt"); +    e.write(glGetString(GL_EXTENSIONS), strlen((char *) glGetString(GL_EXTENSIONS))); +      glViewport(0, 0, surface->w, surface->h);      glCullFace(GL_BACK); @@ -106,10 +125,11 @@ void mogltk::glbase::Leave2DMode(void) {      twoD = 0;  } -void mogltk::glbase::Flip() { +void mogltk::glbase::Flip(bool clear) {      mogltk::engine::pollevents();      SDL_GL_SwapBuffers(); -    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +    if (clear) +        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  }  bool mogltk::glbase::is2D() { @@ -161,3 +181,65 @@ void mogltk::glbase::changefovy(GLdouble nfoyv) {      if (!engine::base_o->is2D())  	gluPerspective(fovy, ratio, 1.0, 1024.0);  } + +inline static unsigned int nextpower(unsigned int n) { +    unsigned int i; + +    if (!n) +        return n; + +    if (ISPOT(n)) +        return n; + +    for (i = 31; i >= 0; i--) { +        if ((n >> i) & 1) { +            return 1 << (i + 1); +        } +    } +} + +mogltk::texture * mogltk::glbase::GrabTexture() { +    int w = nextpower(GetWidth()); +    int h = nextpower(GetHeight()); +    texture * r = new texture(w, h); +    SDL_Surface * t; + +    t = GrabSurface(); +    SDL_BlitSurface(t, NULL, r->GetSurface(), NULL); +    SDL_FreeSurface(t); + +    return r; +} + +SDL_Surface * mogltk::glbase::GrabSurface() { +    int i; +    SDL_Surface * r; +    Uint8 * pixels = (Uint8 *) malloc(GetWidth() * GetHeight() * 3); +    Uint8 * s, * d; + +    glReadPixels(0, 0, GetWidth(), GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, pixels); + +    r = SDL_CreateRGBSurface(SDL_SWSURFACE, GetWidth(), GetHeight(), 24, +#if SDL_BYTEORDER == SDL_BIG_ENDIAN +	0xff000000, +	0x00ff0000, +	0x0000ff00, +	0x00000000 +#else +	0x000000ff, +	0x0000ff00, +	0x00ff0000, +	0x00000000 +#endif +        ); + +    for (i = 0; i < GetHeight(); i++) { +        s = pixels + i * GetWidth() * 3; +        d = ((Uint8 *) r->pixels) + (GetHeight() - i - 1) * GetWidth() * 3; +        memcpy(d, s, GetWidth() * 3); +    } + +    free(pixels); + +    return r; +} diff --git a/lib/texture.cc b/lib/texture.cc index a8036bc..42c8f3f 100644 --- a/lib/texture.cc +++ b/lib/texture.cc @@ -17,7 +17,7 @@ mogltk::texture * mogltk::texture::footer = 0;  mogltk::texture * mogltk::texture::active = 0;  mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : width(w), height(h), -    texture_allocated(false), planar(plane), tainted(true) { +    texture_allocated(false), planar(plane), tainted(true), taintable(true) {      if ((!ISPOT(w)) || (!ISPOT(h)))  	throw GeneralException(_("Size of the texture not a power of 2!")); @@ -51,7 +51,7 @@ mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : wi  }  mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) : -    texture_allocated(false), planar(plane), tainted(true) { +    texture_allocated(false), planar(plane), tainted(true), taintable(true) {      SDL_Surface * temp; @@ -114,6 +114,34 @@ mogltk::texture::texture(Handle * h, bool plane) throw (GeneralException) :      }  } +inline static unsigned int nextpower(unsigned int n) { +    unsigned int i; + +    if (!n) +        return n; + +    if (ISPOT(n)) +        return n; + +    for (i = 31; i >= 0; i--) { +        if ((n >> i) & 1) { +            return 1 << (i + 1); +        } +    } +} + +mogltk::texture::texture(int x, int y, int w, int h) throw (GeneralException) : width(nextpower(w)), height(nextpower(h)), +    texture_allocated(true), planar(false), tainted(false), taintable(false) { +    glGenTextures(1, &tex); +    glBindTexture(GL_TEXTURE_2D, tex); +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); +    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); +    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, x, y, w, h); +} +  mogltk::texture::~texture() {      if (surface) {  	SDL_FreeSurface(surface); @@ -141,7 +169,10 @@ mogltk::texture::~texture() {  }  Uint32 * mogltk::texture::GetPixels() { -    return (Uint32 *) surface->pixels; +    if (surface) +        return (Uint32 *) surface->pixels; +    else +        return 0;  }  SDL_Surface * mogltk::texture::GetSurface() { @@ -149,7 +180,10 @@ SDL_Surface * mogltk::texture::GetSurface() {  }  SDL_PixelFormat * mogltk::texture::GetFormat() { -    return surface->format; +    if (surface) +        return surface->format; +    else +        return 0;  }  void mogltk::texture::Generate() { @@ -245,7 +279,8 @@ void mogltk::texture::Unbind(void) {  }  void mogltk::texture::Taint(void) { -    tainted = true; +    if (taintable) +        tainted = true;  }  void mogltk::texture::Taintall(void) { @@ -298,3 +333,8 @@ SDL_Surface * mogltk::texture::LoadNTEX(Handle * h) throw (GeneralException) {      return r;  } + +void mogltk::texture::DumpBMP(const String & n) { +    if (surface) +        SDL_SaveBMP(surface, n.to_charp()); +} diff --git a/src/test.cc b/src/test.cc index 6884790..d19b5d8 100644 --- a/src/test.cc +++ b/src/test.cc @@ -28,19 +28,9 @@  #include "glshape.h"  #include "glwidgets.h" -class keyhandler_t : public mogltk::engine::keyevent { -    virtual void down(SDL_keysym keysym) { -        if (keysym.sym == SDLK_ESCAPE) -            mogltk::engine::quit(); -        if ((keysym.sym == SDLK_RETURN) && (keysym.mod & KMOD_ALT)) -            mogltk::engine::base_o->ToggleFullscreen(); -    } -    virtual void up(SDL_keysym keysym) { -    } -} keyhandler; -  #if 1 +#define TRTIME 1500  #define SPIN .50  #define TILT .20 @@ -521,15 +511,89 @@ void incrementstars(double nt) {  #endif  } +class testkey_t : public mogltk::engine::keyevent { +  public: +    virtual void down(SDL_keysym keysym) { +        if (keysym.sym == SDLK_SPACE && !start_transit) { +            start_transit = true; +            transit_time = SDL_GetTicks(); +        } else if (old_handler) +            old_handler->down(keysym); +    } +    virtual void up(SDL_keysym keysym) { +        if (old_handler) +            old_handler->up(keysym); +    } +    bool start_transit; +    Uint32 transit_time; +} * testkey; + +void affiche_grille(mogltk::shape * sh, mogltk::texture * tex, int grille[41][31][2]) { +    int x, y, tx1, tx2, ty1, ty2; +    static mogltk::ColorP w = WHITE; + +    w.Bind(); +    tex->Bind(); +     +//    sh->box(0, 0, 640, 480, BLACK); +    for (y = 0; y < 30; y++) { +        for (x = 0; x < 40; x++) { +            tx1 = x * 20; +            ty1 = y * 20; +            tx2 = x * 20 + 20; +            ty2 = y * 20 + 20; + +#if 1 +            glBegin(GL_TRIANGLE_STRIP); +            glTexCoord2i(tx1, ty1); glVertex2i(grille[x    ][y    ][0], grille[x    ][y    ][1]); +            glTexCoord2i(tx2, ty1); glVertex2i(grille[x + 1][y    ][0], grille[x + 1][y    ][1]); +            glTexCoord2i(tx1, ty2); glVertex2i(grille[x    ][y + 1][0], grille[x    ][y + 1][1]); +            glTexCoord2i(tx2, ty2); glVertex2i(grille[x + 1][y + 1][0], grille[x + 1][y + 1][1]); +            glEnd(); +#else +            sh->line(grille[x    ][y    ][0], grille[x    ][y    ][1], +                     grille[x + 1][y    ][0], grille[x + 1][y    ][1]); +            sh->line(grille[x + 1][y    ][0], grille[x + 1][y    ][1], +                     grille[x + 1][y + 1][0], grille[x + 1][y + 1][1]); +            sh->line(grille[x + 1][y + 1][0], grille[x + 1][y + 1][1], +                     grille[x    ][y + 1][0], grille[x    ][y + 1][1]); +            sh->line(grille[x    ][y + 1][0], grille[x    ][y + 1][1], +                     grille[x    ][y    ][0], grille[x    ][y    ][1]); +#endif +        } +    } +} +  virtual int startup() throw (GeneralException) { -    int sx1, sx2, sy1, sy2; +    bool flag = false, flag2 = false; +    mogltk::texture * sshot = 0, * plastex = new mogltk::texture(1024, 512); +    int x, y, sx1, sx2, sy1, sy2, lastframe, curframe, px, py, lasttick = 0, curtick = 0, oldblend, seconds = 0, newseconds = 0;      double t = 0; -    verbosity = M_INFO; +    verbosity = M_ERROR;      String str; +    bool got_transit = false; +    Uint8 * plasma = (Uint8 *) malloc(640 * 480), * pplasma; +    int grille[41][31][2]; +    double seeds[41][31]; +    double speeds[41][31]; + +#if 0 +    srand(25); +    for (y = 0; y < 31; y++) { +        for (x = 0; x < 41; x++) { +            seeds[x][y] = 1.2 * (double) (rand() % 10000) / 10000; +            speeds[x][y] = 2.6 * (double) (rand() % 10000) / 10000; +        } +    } +#endif + +    testkey = new testkey_t();      mogltk::engine::setmouseZ(50);  #if 0 + +#if 0      Lua * l = new Lua();      LuaInput::pushconstruct(l);      LuaOutput::pushconstruct(l); @@ -547,18 +611,39 @@ virtual int startup() throw (GeneralException) {      delete l;  #endif -    new Archive("datas.paq");  //    bdlload("cl.bdl"); +#endif + +    Input pl("plasma.raw"); +    pl.read(plasma, 640 * 480); + +    pplasma = (Uint8 *) plastex->GetPixels(); + +    for (y = 0; y < 480; y++) { +        for (x = 0; x < 640; x++) { +            pplasma[((y * 1024) + x) * 4 + 3] = 255 - plasma[(y * 640) + x]; +        } +    } + +    new Archive("datas.paq"); +  #if 1      mogltk::base * gl = new mogltk::glbase();      mogltk::shape * sh = new mogltk::glshape();      mogltk::font * font = new mogltk::glfont(&Input("font-2.bin"));      mogltk::glSprite * s = new mogltk::glSprite(&Input("cursor.rgba"), 25, 25); +    mogltk::texture * sol = new mogltk::texture(&Input("sol.tex")); +    mogltk::glSprite * logo = new mogltk::glSprite(&Input("logo.raw"), 165, 124); +#if 0      mogltk::Sprite * p = new mogltk::glSprite(&Input("particule.rgba"), 16, 16); -//    mogltk::glSprite * spr = new mogltk::glSprite(&Input("015_Over-Mind.raw"), 347, 328); -    mogltk::glSprite * spr = new mogltk::glSprite(&Input("test.raw"), 200, 200); +    mogltk::glSprite * spr = new mogltk::glSprite(&Input("015_Over-Mind.raw"), 347, 328); +    mogltk::glSprite * eD1 = new mogltk::glSprite(&Input("elkyaD1.raw"), 53, 100); +    mogltk::glSprite * eG1 = new mogltk::glSprite(&Input("elkyaG1.raw"), 53, 100); +    mogltk::glSprite * eM1 = new mogltk::glSprite(&Input("elkyaM1.raw"), 53, 100); +//    mogltk::glSprite * spr = new mogltk::glSprite(&Input("test.raw"), 200, 200);      mogltk::widget * w = new mogltk::Root(sh); +#endif  #else      mogltk::base * gl = new mogltk::base();      mogltk::shape * sh = new mogltk::shape(); @@ -569,9 +654,11 @@ virtual int startup() throw (GeneralException) {      mogltk::widget * w = new mogltk::Root(sh);  #endif -#if 1 +    mogltk::texture * ttex = 0; +      font->setcolor(WHITE); -    font->setshadow(1); +    font->setshadow(2); +#if 0      mogltk::rect textrect;      mogltk::texture * text = font->printtex(&textrect,           "PixelPawa!\n" @@ -586,8 +673,7 @@ virtual int startup() throw (GeneralException) {      mogltk::engine::setcursorvisible(true);      mogltk::engine::setappactive(true); -    mogltk::engine::setkeyevent(&keyhandler); -     +#if 0      mogltk::texture * mytex = new mogltk::texture(&Input("pattern6.tex"), true);      Color AlphaBlue(AQUA); @@ -596,15 +682,27 @@ virtual int startup() throw (GeneralException) {      mogltk::fill * f = sh->fcircle(320, 240, 50);      initstars(); -     + +    px = 200; +    py = 350; +#endif +      while (!mogltk::engine::quitrequested()) { -	sx1 = 320 + 320 * sin(0.983 * t + 3.15); +#if 0 +        sx1 = 320 + 320 * sin(0.983 * t + 3.15);  	sx2 = 320 + 320 * sin(0.537 * t + 5.32);  	sy1 = 240 + 240 * sin(0.692 * t + 8.21);  	sy2 = 240 + 240 * sin(1.029 * t + 2.42); +#endif  	gl->Enter2DMode(); +#if 1 +        if (got_transit) +            goto do_transit; +#endif + +#if 0  	w->fulldraw();  	sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); @@ -639,7 +737,37 @@ virtual int startup() throw (GeneralException) {  	sh->fdraw(f, BLUE);  	sh->sdraw(f); -        spr->drawrotate(500, 400, sx1); +        eM1->drawrotate(500, 400, sx1); + +        curtick = (SDL_GetTicks() / 250) % 4; + +        if (curtick != lasttick) { +            px -= 10; +            py += 5; + +            if (px < -53) +                px = 640; +            if (px > 640) +                px = -53; +            if (py > 480) +                py = -100; +            lasttick = curtick; +        } + +        switch(curtick) { +        case 0: +            eM1->draw(px, py, WHITE, 1, 1); +            break; +        case 1: +            eD1->draw(px, py, WHITE, 1, 1); +            break; +        case 2: +            eM1->draw(px, py, WHITE, 1, 1); +            break; +        case 3: +            eG1->draw(px, py, WHITE, 1, 1); +            break; +        }  	sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue);  	mogltk::ColorP::Min.A = 200; @@ -656,23 +784,335 @@ virtual int startup() throw (GeneralException) {  	displaystars(p);  	incrementstars(t); -	font->putcursor(550, 400); +	sh->box(0, 0, 640, 480, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + +#endif +//	sh->box(0, 0, 640, 480, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); + +        int x, y; + +#if 0 +        for (y = 0; y < 31; y++) { +            for (x = 0; x < 41; x++) { +                grille[x][y][0] = x * 16 + 8 * sin(t * 6 + (x + y) / 2.0); +                grille[x][y][1] = y * 16 + 8 * cos(t * 6 + (x + y) / 2.0); +            } +        } +#endif +        double dis, xdis, ydis, xpos, ypos, norm, tt, tt1; + +        t += 48; + +        tt = t - (((int) t) / 58) * 58; + +        if (tt <= 20) { +            flag = flag2 = false; +            for (y = 0; y < 31; y++) { +                for (x = 0; x < 41; x++) { +                    xpos = x - 20.5; +                    ypos = y - 15.5; +                    norm = sqrt(xpos * xpos + ypos * ypos); +                    xpos /= norm; +                    ypos /= norm; +                    dis = sin(t * 6 - norm); +                    xdis = dis * sin(xpos); +                    ydis = dis * sin(ypos); +                    grille[x][y][0] = (((x * 16 + 16 * xdis) - 320) * 1.08) + 320; +                    grille[x][y][1] = (((y * 16 + 16 * ydis) - 240) * 1.08) + 240; +                } +            } + +            affiche_grille(sh, sol, grille); +            if (tt < 4) +                sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * ((4 - tt) / 4))); +            else if (tt > 16) +                sh->box(0, 0, 640, 480, Color(0, 0, 0, 255 * ((tt - 16) / 4))); +        } else if (tt <= 23) { +            tt -= 20; +            sh->box(0, 0, 640, 480, BLACK); +            for (y = 0; y < 31; y++) { +                for (x = 0; x < 41; x++) { +                    grille[x][y][0] = ((((x * 16 + 8 * sin(t * 6 + (x + y) / 2.0)) - 320) * 1.08) + 320) * tt / 3; +                    grille[x][y][1] = ((((y * 16 + 8 * cos(t * 6 + (x + y) / 2.0)) - 200) * 1.08) + 200) * tt / 3; +                } +            } +            affiche_grille(sh, sol, grille); +        } else if (tt <= 36) { +            for (y = 0; y < 31; y++) { +                for (x = 0; x < 41; x++) { +                    grille[x][y][0] = (((x * 16 + 8 * sin(t * 6 + (x + y) / 2.0)) - 320) * 1.08) + 320; +                    grille[x][y][1] = (((y * 16 + 8 * cos(t * 6 + (x + y) / 2.0)) - 200) * 1.08) + 200; +                } +            } +            affiche_grille(sh, sol, grille); +        } else if (tt <= 38) { +            tt -= 36; +            if (!flag2) { +                sshot = gl->GrabTexture(); +                flag2 = true; +            } +	    sh->tbox(sshot, 0, 0, 640, 480); +            if (tt <= 0.1) { +                sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * (tt / 0.1))); +            } else if (tt < 0.5) { +                tt -= 0.1; +                sh->box(0, 0, 640, 480, Color(255, 255, 255, 255 * ((0.4 - tt) / 0.4))); +                sh->box(0, 0, 640, 480, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127 * (tt / 0.4))); +            } else { +                sh->box(0, 0, 640, 480, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127)); +            } +            for (y = 0; y < 15; y++) { +                for (x = 0; x < 20; x++) { +                    sh->obox(x * 32, y * 32, x * 32 + 32, y * 32 + 32, WHITE); +                } +            } +        } else if (tt <= 42) { +            int xx, yy, tyy; +            double ttt; +            tt -= 38; +            sh->box(0, 0, 640, 480, BLACK); +            for (y = 14; y >= 0; y--) { +                for (x = 19; x >= 0; x--) { +                    double d = (33.0 - x - y) / 16.5; +                    xx = x * 32; +                    tyy = y * 32; +                    if (tt <= d) { +                        yy = y * 32; +                    } else { +                        ttt = tt - d; +                        yy = y * 32 + ttt * ttt * ttt * 60; +                    } +                    sh->tbox(sshot, xx, yy, xx + 32, yy + 32, xx, tyy, xx + 32, tyy + 32); +                    sh->box(xx, yy, xx + 32, yy + 32, Color(0.3 * 255, 0.2 * 255, 0.3 * 255, 127)); +                    sh->obox(xx, yy, xx + 32, yy + 32, WHITE); +                } +            } +        } else if (tt <= 43) { +            sh->box(0, 0, 640, 480, BLACK); +        } else if (tt <= 48) { +            tt -= 43; +            sh->tbox(sol, 0, 0, 640, 480, 0, 0, 800, 600); +            glDisable(GL_BLEND); +            glEnable(GL_ALPHA_TEST); +            glAlphaFunc(GL_GREATER, tt / 5); +            sh->tbox(plastex, 0, 0, 640, 480); +            glDisable(GL_ALPHA_TEST); +            glEnable(GL_BLEND); +        } else if (tt <= 56) { +            sh->tbox(sol, 0, 0, 640, 480, 0, 0, 800, 600); +        } else if (tt <= 58) { +            if (!flag) { +                if (sshot) +                    delete sshot; +                testkey->start_transit = true; +                testkey->transit_time = SDL_GetTicks(); +                flag = true; +            } else { +                glBlendFunc(GL_SRC_ALPHA, GL_ONE); +                sh->box(0, 0, 640, 480, Color(255, 255, 255, 1)); +                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +            } +        } + +        logo->draw(10, 10, Color(255, 255, 255, 100)); + + +	font->putcursor(530, 460);  	font->printf("FPS: %.2f\n", mogltk::engine::FPS()); -	font->printf("mx: %i\n", mogltk::engine::mouseX()); -	font->printf("my: %i\n", mogltk::engine::mouseY()); -	font->printf("t: %.2fs\n", SDL_GetTicks() / 1000.0); -        mogltk::ColorP::Max.A = 50; -	s->draw(mogltk::engine::mouseX() - 6, mogltk::engine::mouseY() - 3, BLACK); +//	font->printf("mx: %i\n", mogltk::engine::mouseX()); +//	font->printf("my: %i\n", mogltk::engine::mouseY()); +//	font->printf("t: %.2fs\n", SDL_GetTicks() / 1000.0); +//        mogltk::ColorP::Max.A = 50; +//	s->draw(mogltk::engine::mouseX() - 6, mogltk::engine::mouseY() - 3, BLACK); +//        mogltk::ColorP::Max.A = 255; +//	s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6); + +do_transit: +        mogltk::ColorP::Min.A = 0;          mogltk::ColorP::Max.A = 255; -	s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6); +        if (testkey->start_transit) { +            double t; +            int x, y; +            Uint8 * pixels; +            if (!got_transit) { +                lastframe = 0; +                got_transit = true; +                ttex = gl->GrabTexture(); +                pixels = (Uint8 *) ttex->GetPixels(); +                oldblend = 20; +#if 1 +                for (y = 0; y < 480; y++) { +                    for (x = 0; x < 640; x++) { +#if 0 +                        pixels[(y * 1024 + x) * 4 + 0] ^= 255; +                        pixels[(y * 1024 + x) * 4 + 1] ^= 255; +                        pixels[(y * 1024 + x) * 4 + 2] ^= 255; +#endif +#if 0 +                        pixels[(y * 1024 + x) * 4 + 3] = plasma[y * 640 + x]; +#endif +#if 1 +                        pixels[(y * 1024 + x) * 4 + 3] = 30; +#endif +#if 0 +                        pixels[(y * 1024 + x) * 4 + 3] = 7; +#endif +#if 0 +                        pixels[(y * 1024 + x) * 4 + 3] = 1; +#endif +                    } +                } +#endif +            } +            pixels = (Uint8 *) ttex->GetPixels(); +            t = (double) (SDL_GetTicks() - testkey->transit_time) / TRTIME; +            curframe = 45 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; +            if (t >= 1.0) { +                testkey->start_transit = false; +            } +#if 0 +            mogltk::ColorP::Max.A = 255 * (TRTIME - SDL_GetTicks() + testkey->transit_time) / TRTIME; +            mogltk::ColorP::Min.R = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; +            mogltk::ColorP::Min.G = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; +            mogltk::ColorP::Min.B = 255 * (SDL_GetTicks() - testkey->transit_time) / TRTIME; +	    sh->tbox(ttex, 0, 0, 640, 480); +            mogltk::ColorP::Max.A = 255; +            mogltk::ColorP::Min.R = 0; +            mogltk::ColorP::Min.G = 0; +            mogltk::ColorP::Min.B = 0; +#endif +#if 0 +            for (y = 0; y < 10; y++) { +                for (x = 0; x < 10; x++) { +                    int cx, cy, tx1, ty1, tx2, ty2; +                    cx  = x * 64 + 32; +                    cy  = y * 48 + 24; +                    tx1 = x * 64; +                    ty1 = y * 48; +                    tx2 = x * 64 + 64; +                    ty2 = y * 48 + 48; +                    glMatrixMode(GL_MODELVIEW); +                    glPushMatrix(); +                    glTranslated(cx, cy, 0); +                    glScaled((1 - t), (1 - t), 1); +                    glRotated((t + ((x + y) / 30)) * 400, 0, 0, 1); +                    sh->tbox(ttex, -32, -24, 32, 24, tx1, ty1, tx2, ty2); +                    glPopMatrix(); +                } +            } +#endif +#if 0 +            glDisable(GL_BLEND); +            glEnable(GL_ALPHA_TEST); +            glAlphaFunc(GL_GREATER, t); +            sh->tbox(ttex, 0, 0, 640, 480); +            glDisable(GL_ALPHA_TEST); +            glEnable(GL_BLEND); +#endif +#if 1 +            if (curframe > lastframe) { +#if 1 +                sh->box(0, 0, 640, 480, Color(40, 40, 40, 12)); +                glBlendFunc(GL_SRC_ALPHA, GL_ONE); +                glPushMatrix(); +                glTranslated(320, 240, 0); +                glScaled(1 + 2 * t, 1 + 2 * t, 1); +                glRotated(t * 100, 0, 0, 1); +                sh->tbox(ttex, -320, -240, 320, 240); +                glPopMatrix(); +                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif +#if 0 +                sh->box(0, 0, 640, 480, Color(25, 25, 25, 20)); +                glBlendFunc(GL_SRC_ALPHA, GL_ONE); +                glPushMatrix(); +                glTranslated(320, 240, 0); +                glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); +                glTranslated(0, curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); +                glTranslated(-curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); +                glTranslated(-curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); +                glTranslated(0, -curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); +                glTranslated(0, -curframe, 0); sh->tbox(ttex, -320, -240, 320, 240); +                glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); +                glTranslated(curframe, 0, 0); sh->tbox(ttex, -320, -240, 320, 240); +                glPopMatrix(); +                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif +#if 0 +                int x0 = 320, y0 = 240; +                int x = 0; +                int y = t * 15 - 1; +                int d = 3 - 2 * t * 15; +                int dI = 10 - 4 * t * 15; +                int rI = 6; +     +                sh->box(0, 0, 640, 480, Color(25, 25, 25, oldblend)); +                glBlendFunc(GL_SRC_ALPHA, GL_ONE); +                oldblend = 0; +                while (x <= y) { +                    oldblend += 16; +                    glPushMatrix(); glTranslated(x0 + x, y0 + y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); +                    glPushMatrix(); glTranslated(x0 - x, y0 + y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); +                    glPushMatrix(); glTranslated(x0 + x, y0 - y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); +                    glPushMatrix(); glTranslated(x0 - x, y0 - y, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); +                    glPushMatrix(); glTranslated(x0 + y, y0 + x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); +                    glPushMatrix(); glTranslated(x0 - y, y0 + x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); +                    glPushMatrix(); glTranslated(x0 + y, y0 - x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); +                    glPushMatrix(); glTranslated(x0 - y, y0 - x, 0); sh->tbox(ttex, -320, -240, 320, 240); glPopMatrix(); +	            if (d >= 0) { +	                d += dI; +	                dI += 8; +	                y -= 1; +	            } else { +	                d += rI; +	                dI += 4; +	            } +	            rI += 4; +	            x += 1; +                } +                printm(M_INFO, "blends = %i\n", oldblend / 2); +                oldblend += 10; +                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif +#if 0 +                sh->box(0, 0, 640, 480, Color(40, 40, 40, 12)); +                glBlendFunc(GL_SRC_ALPHA, GL_ONE); +                glPushMatrix(); +                glTranslated(320, 240, 0); +                glRotated(t * 25, 0, 0, 1); +                sh->tbox(ttex, -320, -240, 320, 240); +                glPopMatrix(); +                glPushMatrix(); +                glTranslated(320, 240, 0); +                glRotated(-t * 25, 0, 0, 1); +                sh->tbox(ttex, -320, -240, 320, 240); +                glPopMatrix(); +                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif +                lastframe = curframe; +            } +#endif +        } +        if (!testkey->start_transit && ttex) { +            delete ttex; +            ttex = 0; +            got_transit = false; +        }  	gl->Leave2DMode(); -	gl->Flip(); +        //gl->Flip(got_transit ? false : true); +        gl->Flip(false);  	t = (double) SDL_GetTicks() / 1000.0; +        newseconds = t; + +        if (newseconds != seconds) { +	    printm(M_INFO, "FPS: %.2f\n", mogltk::engine::FPS()); +            seconds = newseconds; +        }      } -    delete mytex; +//    delete mytex;      return 0;  } @@ -680,6 +1120,7 @@ CODE_ENDS  #else +#if 0  CODE_BEGINS  virtual int startup() throw (GeneralException) {      unsigned char palette[256][3], * pixels, c; @@ -733,5 +1174,55 @@ virtual int startup() throw (GeneralException) {  }  CODE_ENDS +#else +CODE_BEGINS +virtual int startup() throw (GeneralException) { +    unsigned char * pixels, c; +    char outname[256]; +    int width, height, x, y; + +    if (argc != 2) +        exit(-1); +    Input i(argv[1]); +    SDL_Init(SDL_INIT_VIDEO); +    atexit(SDL_Quit); +    i.seek(4, SEEK_SET); +    i.read(&width, 4); +    i.read(&height, 4); +    i.seek(4, SEEK_CUR); +    SDL_Surface * _s = SDL_SetVideoMode(width, height, 32, 0); +    SDL_Surface * s = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, +        0x000000ff, +        0x0000ff00, +        0x00ff0000, +        0xff000000); + +    pixels = (unsigned char *) s->pixels; +    *strchr(argv[1], '.') = 0; + +    i.read(pixels, width * height * 4); + +    sprintf(outname, "%s.bmp", argv[1]); + +    SDL_SaveBMP(s, outname); +    SDL_BlitSurface(s, 0, _s, 0); + +    SDL_Flip(_s); -#endif
\ No newline at end of file +    SDL_Event event; +     +    while(true) { +        SDL_PollEvent(&event); +        switch (event.type) { +        case SDL_QUIT: +            exit(0); +        } +    } + +    return 0; +} +CODE_ENDS + +#endif + +#endif  | 
