From 3e2e4fe9e05d73ba1c1b5de93160bb1cdb7cb56e Mon Sep 17 00:00:00 2001 From: pixel Date: Fri, 28 Mar 2003 13:36:38 +0000 Subject: SDL backend mostly finished --- lib/shape.cc | 161 +++++++++++++++++------------------------------------------ 1 file changed, 46 insertions(+), 115 deletions(-) (limited to 'lib/shape.cc') diff --git a/lib/shape.cc b/lib/shape.cc index 9386e41..e586d6d 100644 --- a/lib/shape.cc +++ b/lib/shape.cc @@ -9,34 +9,14 @@ #define LEAVE Leave(flag) void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) { -#if 0 ENTER; - c.Bind(); - glBegin(GL_TRIANGLE_STRIP); - glVertex2i(x1, y1); - glVertex2i(x2 + 1, y1); - glVertex2i(x1, y2 + 1); - glVertex2i(x2 + 1, y2 + 1); - glEnd(); + SDL_Rect rect; - LEAVE; -#endif -} - -void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) { -#if 0 - ENTER; - - glBegin(GL_TRIANGLE_STRIP); - c1.Bind(); glVertex2i(x1, y1); - c2.Bind(); glVertex2i(x2 + 1, y1); - c3.Bind(); glVertex2i(x1, y2 + 1); - c4.Bind(); glVertex2i(x2 + 1, y2 + 1); - glEnd(); + rect.x = x1; rect.y = y1; rect.w = x2 - x1 + 1; rect.h = y2 - y1 + 1; + SDL_FillRect(mogltk::engine::base_o->getsurface(), &rect, c.toSDL()); LEAVE; -#endif } void mogltk::shape::hline(int x1, int x2, int y, ColorP c) { @@ -75,16 +55,41 @@ void mogltk::shape::vline3d(int x, int y1, int y2, ColorP shade1, ColorP shade2, LEAVE; } -void mogltk::shape::hline(int x1, int x2, int y, ColorP c1, ColorP c2) { - box(x1, y, x2, y, c1, c2, c1, c2); -} - -void mogltk::shape::vline(int x, int y1, int y2, ColorP c1, ColorP c2) { - box(x, y1, x, y2, c1, c1, c2, c2); -} - void mogltk::shape::pixel(int x, int y, ColorP c) { - box(x, y, x, y, c); + ENTER; + + SDL_Surface * surface = mogltk::engine::base_o->getsurface(); + int bpp = surface->format->BytesPerPixel; + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; + Uint32 pixel = c.toSDL(); + + switch(bpp) { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = pixel; + break; + + case 3: + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = pixel; + break; + } + + LEAVE; } void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c) { @@ -98,98 +103,24 @@ void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c) { LEAVE; } -void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4) { - ENTER; - - hline(x1, x2, y1, c1, c2); - hline(x1, x2, y2, c3, c4); - vline(x1, y1, y2, c1, c3); - vline(x2, y1, y2, c2, c4); - - LEAVE; -} - -void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) { - tbox(t, x1, y1, x2, y2, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f), c); -} - -void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx, int ty, double f) { - tbox(t, x1, y1, x2, y2, c1, c2, c3, c4, tx, ty, tx + (int) ((x2 - x1) * f), ty + (int) ((y2 - y1) * f)); -} - -void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, int tx1, int ty1, int tx2, int ty2, ColorP c) { -#if 0 - ENTERT; - - c.Bind(); - t->Bind(); - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2i(tx1, ty1); glVertex2i(x1, y1); - glTexCoord2i(tx2 + 1, ty1); glVertex2i(x2 + 1, y1); - glTexCoord2i(tx1, ty2 + 1); glVertex2i(x1, y2 + 1); - glTexCoord2i(tx2 + 1, ty2 + 1); glVertex2i(x2 + 1, y2 + 1); - glEnd(); - - LEAVE; -#endif -} - -void mogltk::shape::tbox(mogltk::texture * t, int x1, int y1, int x2, int y2, ColorP c1, ColorP c2, ColorP c3, ColorP c4, int tx1, int ty1, int tx2, int ty2) { -#if 0 - ENTERT; - - t->Bind(); - glBegin(GL_TRIANGLE_STRIP); - c1.Bind(); glTexCoord2i(tx1, ty1); glVertex2i(x1, y1); - c2.Bind(); glTexCoord2i(tx2 + 1, ty1); glVertex2i(x2 + 1, y1); - c3.Bind(); glTexCoord2i(tx1, ty2 + 1); glVertex2i(x1, y2 + 1); - c4.Bind(); glTexCoord2i(tx2 + 1, ty2 + 1); glVertex2i(x2 + 1, y2 + 1); - glEnd(); - - LEAVE; -#endif -} - void mogltk::shape::box3d(int x1, int y1, int x2, int y2, ColorP face, ColorP shade1, ColorP shade2, int depth, bool bevel) { -#if 0 ENTER; - if (!bevel) { - shade1.Bind(); - } else { - shade2.Bind(); + int i; + + for (i = 0; i < depth; i++) { + hline(x1 + i, x2 - i, y1 + i, bevel ? shade2 : shade1); + vline(x1 + i, y1 + i, y2 - i, bevel ? shade2 : shade1); } - glBegin(GL_TRIANGLE_FAN); - glVertex2i(x1, y1); - glVertex2i(x2 + 1, y1); - glVertex2i(x2 + 1 - depth, y1 + depth); - glVertex2i(x1 + depth, y2 + 1 - depth); - glVertex2i(x1, y2 + 1); - glEnd(); - if (!bevel) { - shade2.Bind(); - } else { - shade1.Bind(); + for (i = 0; i < depth; i++) { + hline(x1 + i, x2 - i, y2 - i, bevel ? shade1 : shade2); + vline(x2 - i, y1 + i, y2 - i, bevel ? shade1 : shade2); } - glBegin(GL_TRIANGLE_FAN); - glVertex2i(x2 + 1, y2 + 1); - glVertex2i(x1, y2 + 1); - glVertex2i(x1 + depth, y2 + 1 - depth); - glVertex2i(x2 + 1 - depth, y1 + depth); - glVertex2i(x2 + 1, y1); - glEnd(); - face.Bind(); - glBegin(GL_TRIANGLE_STRIP); - glVertex2i(x1 + depth, y1 + depth); - glVertex2i(x2 + 1 - depth, y1 + depth); - glVertex2i(x1 + depth, y2 + 1 - depth); - glVertex2i(x2 + 1 - depth, y2 + 1 - depth); - glEnd(); + box(x1 + depth, y1 + depth, x2 - depth, y2 - depth, face); LEAVE; -#endif } void mogltk::shape::obox3d(int x1, int y1, int x2, int y2, ColorP shade1, ColorP shade2, bool bevel) { -- cgit v1.2.3