diff options
author | pixel <pixel> | 2003-04-04 15:06:29 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-04-04 15:06:29 +0000 |
commit | feba563611f39efe4f71cf09347d5aa9cd13ada6 (patch) | |
tree | 8081c7ba2946b255e23d82bb69221bc54f0f6381 | |
parent | 986a589d45841832e3655892f65b773193e277af (diff) |
Finished filling
-rw-r--r-- | include/glshape.h | 3 | ||||
-rw-r--r-- | include/shape.h | 26 | ||||
-rw-r--r-- | include/texture.h | 1 | ||||
-rw-r--r-- | lib/glshape.cc | 54 | ||||
-rw-r--r-- | lib/shape.cc | 105 | ||||
-rw-r--r-- | lib/texture.cc | 6 | ||||
-rw-r--r-- | src/test.cc | 17 |
7 files changed, 148 insertions, 64 deletions
diff --git a/include/glshape.h b/include/glshape.h index bb0bdb3..c2e8b59 100644 --- a/include/glshape.h +++ b/include/glshape.h @@ -11,10 +11,10 @@ namespace mogltk { class glshape : public shape { public: virtual void pixel(int x, int y, ColorP = WHITE); - virtual void fdraw(fill *, ColorP = WHITE); virtual void box(int x1, int y1, int x2, int y2, ColorP = WHITE); virtual void box3d(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, int = 2, bool = false); virtual void box(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP); + virtual void obox(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE); virtual void obox(int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP); virtual void hline(int x1, int x2, int y, ColorP, ColorP); virtual void vline(int x, int y1, int y2, ColorP, ColorP); @@ -22,6 +22,7 @@ namespace mogltk { virtual void tbox(texture *, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP = WHITE); virtual void tbox(texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx = 0, int ty = 0, double = 1.0); virtual void tbox(texture *, int x1, int y1, int x2, int y2, ColorP, ColorP, ColorP, ColorP, int tx1, int ty1, int tx2, int ty2); + virtual void fdraw(fill * f, ColorP = WHITE, int sx = 0, int sy = 0); private: bool Enter(bool); virtual bool Enter(); diff --git a/include/shape.h b/include/shape.h index e06115e..6bbf94e 100644 --- a/include/shape.h +++ b/include/shape.h @@ -24,10 +24,13 @@ namespace mogltk { virtual ~fill(); void walk(fillwalker *); void insert(int, int); - int GetMinX(); - int GetMinY(); - int GetMaxX(); - int GetMaxY(); + int GetMinX() const; + int GetMinY() const; + int GetMaxX() const; + int GetMaxY() const; + texture * GetTexture(); + texture * Talloc(); + Color last; private: class sline : public Base { public: @@ -59,6 +62,7 @@ namespace mogltk { friend class point; }; int minX, minY, maxX, maxY; + texture * cached; protected: sline * header; friend class sline; @@ -69,7 +73,7 @@ namespace mogltk { virtual void circle(int x, int y, int r, ColorP = WHITE); virtual void pcircle(int x, int y, int r, ColorP = WHITE); virtual fill * fcircle(int x, int y, int r); - virtual void fdraw(fill *, ColorP = WHITE); + virtual void fdraw(fill *, ColorP = WHITE, int sx = 0, int sy = 0); virtual void arc(int x, int y, int r, double a1, double a2, ColorP = DOS_WHITE); virtual void arc(int x, int y, int r, int x1, int y1, int x2, int y2, ColorP = DOS_WHITE); virtual void box(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE); @@ -109,6 +113,18 @@ namespace mogltk { virtual bool Enter(); virtual void Leave(bool); }; + + class filldrawer : public fillwalker { + public: + filldrawer(fill *, texture *, ColorP = DOS_WHITE); + virtual ~filldrawer(); + virtual void step(int x, int y); + private: + fill * f; + texture * t; + ColorP c; + int oldx, oldy; + }; }; #endif diff --git a/include/texture.h b/include/texture.h index 4f14ba4..b558694 100644 --- a/include/texture.h +++ b/include/texture.h @@ -15,6 +15,7 @@ namespace mogltk { virtual ~texture(); SDL_Surface * GetSurface(); Uint32 * GetPixels(); + SDL_PixelFormat * GetFormat(); static SDL_Surface * LoadNTEX(Handle * h) throw (GeneralException) ; void Generate(); void Bind(bool = true); diff --git a/lib/glshape.cc b/lib/glshape.cc index 5572e4d..9257257 100644 --- a/lib/glshape.cc +++ b/lib/glshape.cc @@ -48,6 +48,12 @@ void mogltk::glshape::pixel(int x, int y, ColorP c) { box(x, y, x, y, c); } +void mogltk::glshape::obox(int x1, int y1, int x2, int y2, ColorP c) { + ENTER; + shape::obox(x1, y1, x2, y2, c); + LEAVE; +} + void mogltk::glshape::obox(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) { ENTER; @@ -155,32 +161,30 @@ void mogltk::glshape::Leave(bool was2D) { mogltk::engine::glbase_o->Leave2DMode(); } -class filldrawer : public mogltk::fillwalker { - public: - filldrawer(mogltk::shape * _s, mogltk::ColorP _c = DOS_WHITE) : s(_s), c(_c), oldx(-1), oldy(-1) { } - virtual ~filldrawer() { } - virtual void step(int x, int y) { - if (oldy != y) - oldx = -1; - if (oldx == -1) { - oldx = x; - } else { - s->hline(oldx, x, y, c); - oldx = -1; - } - oldy = y; +void mogltk::glshape::fdraw(fill * f, ColorP c, int sx, int sy) { + ENTERT; + + texture * t = f->GetTexture(); + + if (!t) { + filldrawer * w = new filldrawer(f, t = f->Talloc(), c); + f->walk(w); + delete w; } - private: - mogltk::shape * s; - mogltk::ColorP c; - int oldx, oldy; -}; -void mogltk::glshape::fdraw(fill * f, ColorP c) { - ENTER; - filldrawer * w = new filldrawer(this, c); - f->walk(w); - delete w; + c.Bind(); + t->Bind(); + int w = t->GetWidth(); + int h = t->GetHeight(); + int x = f->GetMinX() + sx; + int y = f->GetMinY() + sy; + + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2i(0, 0); glVertex2i(x , y ); + glTexCoord2i(w, 0); glVertex2i(x + w, y ); + glTexCoord2i(0, h); glVertex2i(x , y + h); + glTexCoord2i(w, h); glVertex2i(x + w, y + h); + glEnd(); + LEAVE; } -
\ No newline at end of file diff --git a/lib/shape.cc b/lib/shape.cc index 54e552b..45280f5 100644 --- a/lib/shape.cc +++ b/lib/shape.cc @@ -19,12 +19,15 @@ mogltk::fillwalker::~fillwalker() { void mogltk::fillwalker::step(int x, int y) { } -mogltk::fill::fill() : minX(INT_MAX), minY(INT_MAX), maxX(INT_MIN), maxY(INT_MIN), header(0) { +mogltk::fill::fill() : minX(INT_MAX), minY(INT_MAX), maxX(INT_MIN), maxY(INT_MIN), cached(0), header(0) { } mogltk::fill::~fill() { if (header) delete header; + + if (cached) + delete cached; } void mogltk::fill::walk(fillwalker * w) { @@ -32,6 +35,11 @@ void mogltk::fill::walk(fillwalker * w) { } void mogltk::fill::insert(int x, int y) { + if (cached) { + delete cached; + cached = 0; + } + if (!header) { new sline(y, this); } @@ -50,22 +58,39 @@ void mogltk::fill::insert(int x, int y) { minY = y; } -int mogltk::fill::GetMaxX() { +int mogltk::fill::GetMaxX() const { return maxX; } -int mogltk::fill::GetMaxY() { +int mogltk::fill::GetMaxY() const { return maxY; } -int mogltk::fill::GetMinX() { +int mogltk::fill::GetMinX() const { return minX; } -int mogltk::fill::GetMinY() { +int mogltk::fill::GetMinY() const { return minY; } +mogltk::texture * mogltk::fill::GetTexture() { + return cached; +} + +mogltk::texture * mogltk::fill::Talloc() { + if (cached) + return cached; + + int x; int y; + + for (x = 1; x < (maxX - minX); x <<= 1); + for (y = 1; y < (maxY - minY); y <<= 1); + + cached = new texture(x, y, true); + return cached; +} + mogltk::fill::sline::sline(int _y, fill * _header) : y(_y), header(_header), pheader(0) { if (!header->header) { header->header = this; @@ -351,32 +376,58 @@ void mogltk::shape::pcircle(int x, int y, int r, ColorP c) { delete f; } -class filldrawer : public mogltk::fillwalker { - public: - filldrawer(mogltk::shape * _s, mogltk::ColorP _c = DOS_WHITE) : s(_s), c(_c), oldx(-1), oldy(-1) { } - virtual ~filldrawer() { } - virtual void step(int x, int y) { - if (oldy != y) - oldx = -1; - if (oldx == -1) { - oldx = x; - } else { - s->hline(oldx, x, y, c); - oldx = -1; +mogltk::filldrawer::filldrawer(fill * _f, texture * _t, ColorP _c) : f(_f), t(_t), c(_c), oldx(-1), oldy(-1) { +} + +mogltk::filldrawer::~filldrawer() { +} + +void mogltk::filldrawer::step(int x, int y) { + if (oldy != y) { + oldx = -1; + } + if (oldx == -1) { + oldx = x; + } else { +// s->hline(oldx, x, y, c); + Uint32 * p = t->GetPixels(); + int i, + first = t->GetWidth() * (y - f->GetMinY()) + oldx - f->GetMinX(), + last = first - oldx + x; + SDL_PixelFormat * format = t->GetFormat(); + + for (i = first; i <= last; i++) { + p[i] = c.toSDL(format); } - oldy = y; + + oldx = -1; } - private: - mogltk::shape * s; - mogltk::ColorP c; - int oldx, oldy; -}; + oldy = y; +} -void mogltk::shape::fdraw(fill * f, ColorP c) { +void mogltk::shape::fdraw(fill * f, ColorP c, int sx, int sy) { ENTER; - filldrawer * w = new filldrawer(this, c); - f->walk(w); - delete w; + if (!f->GetTexture()) { + filldrawer * w = new filldrawer(f, f->Talloc(), c); + f->walk(w); + delete w; + f->last = c.c; + } + SDL_PixelFormat * format = f->GetTexture()->GetFormat(); + + if (f->last == c.c) { + Uint32 * p = f->GetTexture()->GetPixels(); + int i, n = f->GetTexture()->GetWidth() * f->GetTexture()->GetHeight(); + for (i = 0; i < n; i++) + if (p[i] & 0xff000000) + p[i] = c.toSDL(format); + } + SDL_Rect r; + r.x = f->GetMinX() + sx; + r.y = f->GetMinY() + sy; + SDL_BlitSurface(f->GetTexture()->GetSurface(), 0, mogltk::engine::base_o->getsurface(), &r); + + f->last = c.c; LEAVE; } diff --git a/lib/texture.cc b/lib/texture.cc index 80853ca..bea33a4 100644 --- a/lib/texture.cc +++ b/lib/texture.cc @@ -39,6 +39,8 @@ mogltk::texture::texture(int w, int h, bool plane) throw (GeneralException) : wi throw GeneralException(_("Can't create RGB Surface")); } + SDL_FillRect(surface, 0, 0); + #ifdef TRACE_TEXTURES next = 0; prev = footer; @@ -154,6 +156,10 @@ SDL_Surface * mogltk::texture::GetSurface() { return surface; } +SDL_PixelFormat * mogltk::texture::GetFormat() { + return surface->format; +} + void mogltk::texture::Generate() { if (texture_allocated) { glDeleteTextures(1, &tex); diff --git a/src/test.cc b/src/test.cc index 2d42107..729c972 100644 --- a/src/test.cc +++ b/src/test.cc @@ -23,9 +23,11 @@ virtual int startup() throw (GeneralException) { mogltk::glbase * gl = new mogltk::glbase(); mogltk::glshape * sh = new mogltk::glshape(); mogltk::glfont * font = new mogltk::glfont(&Input("font-2.bin")); + // mogltk::base * gl = new mogltk::base(); // mogltk::shape * sh = new mogltk::shape(); // mogltk::font * font = new mogltk::font(&Input("font-2.bin")); + mogltk::Sprite * s = new mogltk::Sprite(&Input("cursor.rgba"), 25, 25); mogltk::engine::setcursorvisible(true); @@ -35,6 +37,8 @@ virtual int startup() throw (GeneralException) { Color AlphaBlue(AQUA); AlphaBlue.A = 50; + + mogltk::fill * f = sh->fcircle(320, 240, 50); while (!mogltk::engine::quitrequested()) { sx1 = 320 + 320 * sin(0.983 * t + 3.15); @@ -42,12 +46,12 @@ virtual int startup() throw (GeneralException) { sy1 = 240 + 240 * sin(0.692 * t + 8.21); sy2 = 240 + 240 * sin(1.029 * t + 2.42); - gl->Enter2DMode(); +// gl->Enter2DMode(); - sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); - sh->box(400, 100, 450, 150, BLACK, RED, LIME, BLUE); +// sh->tbox(mytex, 50, 50, 561, 561, BLACK, RED, LIME, BLUE); +// sh->box(400, 100, 450, 150, BLACK, RED, LIME, BLUE); - sh->box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); +// sh->box(5, 5, 150, 80, CORNFLOWERBLUE, DEEPSKYBLUE, MIDNIGHTBLUE, NAVY); font->setshadow(1); font->putcursor(10, 30); font->setcolor(WHITE); @@ -64,11 +68,12 @@ virtual int startup() throw (GeneralException) { sh->button(200, 150, 300, 200, "Bouton"); // for (int j = 0; j < 100; j++) { - sh->pcircle(320, 240, 50); + sh->fdraw(f); // } // sh->arc(320, 240, 50, 0, 0); sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); + sh->obox(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); font->putcursor(550, 400); font->printf("FPS: %.2f\n", mogltk::engine::FPS()); @@ -78,7 +83,7 @@ virtual int startup() throw (GeneralException) { s->draw(mogltk::engine::mouseX() - 8, mogltk::engine::mouseY() - 6); - gl->Leave2DMode(); +// gl->Leave2DMode(); gl->Flip(); |