summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpixel <pixel>2003-04-14 15:51:42 +0000
committerpixel <pixel>2003-04-14 15:51:42 +0000
commite318be8501559a9e53aa9990bf7e07b00c00ee51 (patch)
treee2df61a572721612437ce6fa81cabc06408a4ed8 /lib
parentebc6bb16f895b7c192b9f4c42d1fc4feb41e271c (diff)
Shapes fixed
Diffstat (limited to 'lib')
-rw-r--r--lib/base.cc1
-rw-r--r--lib/glbase.cc1
-rw-r--r--lib/glshape.cc30
-rw-r--r--lib/glsprite.cc2
-rw-r--r--lib/shape.cc51
-rw-r--r--lib/sprite.cc2
-rw-r--r--lib/texture.cc6
7 files changed, 56 insertions, 37 deletions
diff --git a/lib/base.cc b/lib/base.cc
index dcaf167..7891d50 100644
--- a/lib/base.cc
+++ b/lib/base.cc
@@ -47,7 +47,6 @@ int mogltk::base::GetHeight(void) {
}
void mogltk::base::Flip() {
- printm(M_INFO, "Flipping\n");
mogltk::engine::pollevents();
SDL_Flip(surface);
SDL_FillRect(surface, NULL, 0);
diff --git a/lib/glbase.cc b/lib/glbase.cc
index df093dd..3808620 100644
--- a/lib/glbase.cc
+++ b/lib/glbase.cc
@@ -106,7 +106,6 @@ void mogltk::glbase::Leave2DMode(void) {
}
void mogltk::glbase::Flip() {
- printm(M_INFO, "Flipping\n");
mogltk::engine::pollevents();
SDL_GL_SwapBuffers();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
diff --git a/lib/glshape.cc b/lib/glshape.cc
index e1c1faf..7662334 100644
--- a/lib/glshape.cc
+++ b/lib/glshape.cc
@@ -175,7 +175,7 @@ void mogltk::glshape::fdraw(fill * f, ColorP c, int sx, int sy) {
texture * t = f->GetTexture();
if (!t) {
- filldrawer * w = new filldrawer(f, t = f->Talloc(), c);
+ filldrawer * w = new filldrawer(f, t = f->Talloc(), WHITE);
f->walk(w);
delete w;
}
@@ -196,3 +196,31 @@ void mogltk::glshape::fdraw(fill * f, ColorP c, int sx, int sy) {
LEAVE;
}
+
+void mogltk::glshape::sdraw(fill * f, ColorP c, int sx, int sy) {
+ ENTERT;
+
+ texture * t = f->GetSTexture();
+
+ if (!t) {
+ segdrawer * w = new segdrawer(f, t = f->STalloc(), WHITE);
+ f->swalk(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;
+}
diff --git a/lib/glsprite.cc b/lib/glsprite.cc
index 3ccb2bd..478c0ef 100644
--- a/lib/glsprite.cc
+++ b/lib/glsprite.cc
@@ -22,10 +22,8 @@ void mogltk::glSprite::draw(int dx, int dy, ColorP c) {
if (!was2D)
mogltk::engine::glbase_o->Enter2DMode();
- printm(M_INFO, "Drawing gl Sprite at %i %i\n", dx, dy);
c.Bind();
- printm(M_INFO, "Drawing sprite texture...\n");
Bind();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2i(GetPX() , GetPY() ); glVertex2i(dx , dy );
diff --git a/lib/shape.cc b/lib/shape.cc
index de2a498..908d6d1 100644
--- a/lib/shape.cc
+++ b/lib/shape.cc
@@ -27,7 +27,7 @@ mogltk::segwalker::segwalker() {
mogltk::segwalker::~segwalker() {
}
-mogltk::segwalker::setup(int x1, int y1, int x2, int y2) {
+void mogltk::segwalker::step(int x1, int y1, int x2, int y2) {
}
mogltk::fill::fill() : minX(INT_MAX), minY(INT_MAX), maxX(INT_MIN), maxY(INT_MIN), cached(0), scached(0), header(0) {
@@ -52,7 +52,7 @@ void mogltk::fill::swalk(segwalker * s) {
std::vector<struct segment>::iterator i;
for (i = segments.begin(); i != segments.end(); i++) {
- s->setup(i->x1, i->y1, i->x2, i->y2);
+ s->step(i->x1, i->y1, i->x2, i->y2);
}
}
@@ -290,13 +290,13 @@ mogltk::fill::sline * mogltk::fill::sline::look(int _y) {
return next->look(_y);
}
-mogltk::shape(SDL_Surface * _surf) : surf(_surf) {
- if (!tex)
- tex = mogltk::engine::base_o->GetSurface();
+mogltk::shape::shape(SDL_Surface * _surf) : surf(_surf) {
+ if (!surf)
+ surf = mogltk::engine::base_o->getsurface();
}
-SDL_Surface * mogltk::GetSurf() {
- return Surf;
+SDL_Surface * mogltk::shape::GetSurf() {
+ return surf;
}
void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) {
@@ -305,7 +305,7 @@ void mogltk::shape::box(int x1, int y1, int x2, int y2, ColorP c) {
SDL_Rect rect;
rect.x = x1; rect.y = y1; rect.w = x2 - x1 + 1; rect.h = y2 - y1 + 1;
- SDL_FillRect(Surf, &rect, c.toSDL(Surf));
+ SDL_FillRect(surf, &rect, c.toSDL(surf->format));
LEAVE;
}
@@ -453,23 +453,23 @@ void mogltk::shape::bsubline_4(int x1, int y1, int x2, int y2, ColorP c) {
void mogltk::shape::line(int x1, int y1, int x2, int y2, ColorP c) {
float k = float(y2 - y1) / float(x2 - x1);
- if ((k >= 0) && (k <= 1))
+ if ((k >= 0) && (k <= 1)) {
bsubline_1(x1, y1, x2, y2, c);
- else if (k > 1)
+ } else if (k > 1) {
bsubline_2(x1, y1, x2, y2, c);
- else if ((k < 0) && (k >= -1))
+ } else if ((k < 0) && (k >= -1)) {
bsubline_3(x1, y1, x2, y2, c);
- else
+ } else {
bsubline_4(x1, y1, x2, y2, c);
-
+ }
}
void mogltk::shape::pixel(int x, int y, ColorP c) {
ENTER;
- int bpp = surface->format->BytesPerPixel;
- Uint8 *p = (Uint8 *)Surf->pixels + y * Surf->pitch + x * bpp;
- Uint32 pixel = c.toSDL(Surf);
+ int bpp = surf->format->BytesPerPixel;
+ Uint8 *p = (Uint8 *)surf->pixels + y * surf->pitch + x * bpp;
+ Uint32 pixel = c.toSDL(surf->format);
switch(bpp) {
case 1:
@@ -496,7 +496,7 @@ void mogltk::shape::pixel(int x, int y, ColorP c) {
*(Uint32 *)p = pixel;
break;
}
-
+
LEAVE;
}
@@ -556,7 +556,6 @@ mogltk::fill * mogltk::shape::fcircle(int x0, int y0, int r) {
f->insert(x0 - y, y0 + x);
f->insert(x0 + y, y0 + x);
*/
- printm(M_INFO, "fcircle: processing point %i %i\n", x, y);
if (t) {
f->insert(x0 - ox, y0 - oy, x0 - x, y0 - y);
f->insert(x0 + ox, y0 - oy, x0 + x, y0 - y);
@@ -639,19 +638,22 @@ void mogltk::shape::fdraw(fill * f, ColorP c, int sx, int sy) {
SDL_Rect r;
r.x = f->GetMinX() + sx;
r.y = f->GetMinY() + sy;
- SDL_BlitSurface(f->GetTexture()->GetSurface(), 0, Surf, &r);
+ SDL_BlitSurface(f->GetTexture()->GetSurface(), 0, surf, &r);
f->last = c.c;
LEAVE;
}
-mogltk::segdrawer::segdrawer(fill * _f, texture * _t, ColorP _c) : f(_f), t(_t), c(_c) {
+mogltk::segdrawer::segdrawer(fill * _f, texture * _t, ColorP _c) : f(_f), t(_t), c(_c), sh(new shape(_t->GetSurface())) {
}
mogltk::segdrawer::~segdrawer() {
+ delete sh;
}
void mogltk::segdrawer::step(int x1, int y1, int x2, int y2) {
+ sh->line(x1 - f->GetMinX(), y1 - f->GetMinY(), x2 - f->GetMinX(), y2 - f->GetMinY(), c);
+#if 0
if (oldy != y) {
oldx = -1;
}
@@ -672,6 +674,7 @@ void mogltk::segdrawer::step(int x1, int y1, int x2, int y2) {
oldx = -1;
}
oldy = y;
+#endif
}
void mogltk::shape::sdraw(fill * f, ColorP c, int sx, int sy) {
@@ -694,7 +697,7 @@ void mogltk::shape::sdraw(fill * f, ColorP c, int sx, int sy) {
SDL_Rect r;
r.x = f->GetMinX() + sx;
r.y = f->GetMinY() + sy;
- SDL_BlitSurface(f->GetSTexture()->GetSurface(), 0, Surf, &r);
+ SDL_BlitSurface(f->GetSTexture()->GetSurface(), 0, surf, &r);
f->last = c.c;
LEAVE;
@@ -854,8 +857,8 @@ void mogltk::shape::button(int x1, int y1, int x2, int y2,
}
bool mogltk::shape::Enter() {
- if (SDL_MUSTLOCK(Surf)) {
- SDL_LockSurface(Surf);
+ if (SDL_MUSTLOCK(surf)) {
+ SDL_LockSurface(surf);
return true;
} else {
return false;
@@ -864,7 +867,7 @@ bool mogltk::shape::Enter() {
void mogltk::shape::Leave(bool locked) {
if (locked)
- SDL_UnlockSurface(Surf);
+ SDL_UnlockSurface(surf);
}
void mogltk::shape::tbox(texture *, int x1, int y1, int x2, int y2, int tx, int ty, double f, ColorP c) {
diff --git a/lib/sprite.cc b/lib/sprite.cc
index 7e94ce5..9c1a320 100644
--- a/lib/sprite.cc
+++ b/lib/sprite.cc
@@ -140,8 +140,6 @@ void mogltk::Sprite::draw(int dx, int dy, ColorP c) {
src.x = posx; src.y = posy; src.w = sx; src.h = sy;
dst.x = dx; dst.y = dy; dst.w = sx; dst.h = sy;
- printm(M_INFO, "Drawing SDL sprite at %i %i\n", dx, dy);
-
SDL_BlitSurface(tlist->GetSurface(), &src, mogltk::engine::base_o->getsurface(), &dst);
if (locked)
diff --git a/lib/texture.cc b/lib/texture.cc
index bea33a4..43c8ac3 100644
--- a/lib/texture.cc
+++ b/lib/texture.cc
@@ -205,9 +205,6 @@ void mogltk::texture::Bind(bool expand) {
glEnable(GL_TEXTURE_2D);
if (active == this)
return;
-#ifdef DEBUG
- printm(M_INFO, _("Binding texture index %i.\n"), tex);
-#endif
glBindTexture(GL_TEXTURE_2D, tex);
if (expand) {
glMatrixMode(GL_TEXTURE);
@@ -252,9 +249,6 @@ void mogltk::texture::Unbind(void) {
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
active = 0;
-#ifdef DEBUG
- printm(M_INFO, _("Unbinding texture.\n"));
-#endif
}
}