X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Frenders%2Fopengl%2Fr_draw.pas;h=fbdae7e4ee8e09cdfd307dc29365d7b322f88149;hb=38f37ffd695612d219b1dbd7bf3165880a012502;hp=212043e93e25f730476450fa3e274ec26f392b1d;hpb=5915de9864c6054538d5b85aceb7db8c75132cea;p=d2df-sdl.git diff --git a/src/game/renders/opengl/r_draw.pas b/src/game/renders/opengl/r_draw.pas index 212043e..fbdae7e 100644 --- a/src/game/renders/opengl/r_draw.pas +++ b/src/game/renders/opengl/r_draw.pas @@ -18,17 +18,23 @@ unit r_draw; interface uses - g_textures, + g_animations, r_textures ; procedure r_Draw_Texture (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); procedure r_Draw_TextureRepeat (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); + procedure r_Draw_TextureRepeatRotate (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); procedure r_Draw_MultiTextureRepeat (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); - procedure r_Draw_MultiTextureRepeatRotate (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; rx, ry, angle: Integer; blend: Boolean); + procedure r_Draw_MultiTextureRepeatRotate (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); procedure r_Draw_Filter (l, t, r, b: Integer; rr, gg, bb, aa: Byte); + procedure r_Draw_FillRect (l, t, r, b: Integer; rr, gg, bb, aa: Byte); + procedure r_Draw_InvertRect (l, t, r, b: Integer; rr, gg, bb, aa: Byte); + + procedure r_Draw_Text (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont); + procedure r_Draw_GetTextSize (const text: AnsiString; f: TGLFont; out w, h: Integer); implementation @@ -115,8 +121,6 @@ implementation DrawTile(nil, x, y, w, h, flip, NTR, NTB, NTG, NTA, blend) else begin - glPushMatrix; - glScalef(w / img.width, h / img.height, 1); offx := 0; offy := 0; for j := 0 to img.lines - 1 do @@ -125,13 +129,16 @@ implementation begin n := img.GetTile(i, j); ASSERT(n <> nil); - DrawTile(n, x + offx, y + offy, n.width, n.height, flip, r, g, b, a, blend); + glPushMatrix; + glTranslatef(x + offx, y + offy, 0); + glScalef(w / img.width, h / img.height, 1); + DrawTile(n, 0, 0, n.width, n.height, flip, r, g, b, a, blend); + glPopMatrix; offx := offx + n.width; end; offx := 0; offy := offy + n.height; end; - glPopMatrix; end end; @@ -143,11 +150,28 @@ implementation if img = nil then r_Draw_Texture(nil, x, y, w, h, flip, NTR, NTG, NTB, NTB, blend) else - for j := 0 to h div img.height - 1 do - for i := 0 to w div img.width - 1 do + for j := 0 to (h - 1) div img.height do + for i := 0 to (w - 1) div img.width do r_Draw_Texture(img, x + i * img.width, y + j * img.height, img.width, img.height, flip, r, g, b, a, blend); end; + procedure r_Draw_TextureRepeatRotate (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); + begin + ASSERT(w >= 0); + ASSERT(h >= 0); + if a <> 0 then + begin + glPushMatrix; + glTranslatef(x + rx, y + ry, 0); + glRotatef(angle, 0, 0, 1); + glTranslatef(-(x + rx), -(y + ry), 0); + r_Draw_TextureRepeat(img, x, y, w, h, flip, r, g, b, a, blend); + glPopMatrix; + end + else + r_Draw_TextureRepeat(img, x, y, w, h, flip, r, g, b, a, blend); + end; + procedure r_Draw_MultiTextureRepeat (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); var img: TGLTexture; cur, total, i: Integer; begin @@ -169,8 +193,7 @@ implementation end end; - procedure r_Draw_MultiTextureRepeatRotate (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; rx, ry, angle: Integer; blend: Boolean); - var i, j: Integer; + procedure r_Draw_MultiTextureRepeatRotate (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); begin ASSERT(w >= 0); ASSERT(h >= 0); @@ -203,4 +226,65 @@ implementation glEnd; end; + procedure r_Draw_FillRect (l, t, r, b: Integer; rr, gg, bb, aa: Byte); + begin + ASSERT(r >= l); + ASSERT(b >= t); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_TEXTURE_2D); + glColor4ub(rr, gg, bb, aa); + glBegin(GL_QUADS); + glVertex2i(l, t); + glVertex2i(r, t); + glVertex2i(r, b); + glVertex2i(l, b); + glEnd; + end; + + procedure r_Draw_InvertRect (l, t, r, b: Integer; rr, gg, bb, aa: Byte); + begin + ASSERT(r >= l); + ASSERT(b >= t); + glEnable(GL_BLEND); + glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); + glDisable(GL_TEXTURE_2D); + glColor4ub(rr, gg, bb, aa); + glBegin(GL_QUADS); + glVertex2i(l, t); + glVertex2i(r, t); + glVertex2i(r, b); + glVertex2i(l, b); + glEnd; + end; + + procedure r_Draw_Text (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont); + var i, xoff, spc: Integer; t: TGLTexture; ch: AnsiChar; + begin + xoff := x; spc := MAX(0, f.GetSpace()); + for i := 1 to Length(text) do + begin + ch := text[i]; + t := f.GetChar(ch); + if t <> nil then + r_Draw_Texture(t, xoff, y, t.width, t.height, false, r, g, b, a, false); + Inc(xoff, f.GetWidth(ch) + spc); + end; + end; + + procedure r_Draw_GetTextSize (const text: AnsiString; f: TGLFont; out w, h: Integer); + var i, spc, len: Integer; + begin + w := 0; + h := f.GetMaxHeight(); + len := Length(text); + if len > 0 then + begin + spc := MAX(0, f.GetSpace()); + for i := 1 to len - 1 do + Inc(w, f.GetWidth(text[i]) + spc); + Inc(w, f.GetWidth(text[len])); + end; + end; + end.