index 67bd23041275b237de894398f5960198e4691c30..fdb7c09ec1da8e08f639e21a26f4c26878473c89 100644 (file)
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);
- procedure r_Draw_Setup (w, h: Integer);
+ procedure r_Draw_Setup (sw, sh, gw, gh: Integer);
procedure r_Draw_SetRect (l, t, r, b: Integer);
procedure r_Draw_GetRect (out l, t, r, b: Integer);
+ procedure r_Draw_EnableTexture2D (enable: Boolean);
+ procedure r_Draw_SetColor (r, g, b, a: Byte);
+
implementation
uses
- {$IFDEF USE_GLES1}
- GLES11,
- {$ELSE}
- GL, GLEXT,
- {$ENDIF}
+ {$I ../../../nogl/noGLuses.inc}
SysUtils, Classes, Math,
e_log, utils
;
var
sl, st, sr, sb: Integer;
ScreenWidth, ScreenHeight: Integer;
+ GameWidth, GameHeight: Integer;
+
+ enableTexture2D: Boolean;
+ curR, curG, curB, curA: Byte;
- procedure r_Draw_Setup (w, h: Integer);
+ procedure r_Draw_EnableTexture2D (enable: Boolean);
begin
- ASSERT(w >= 0);
- ASSERT(h >= 0);
- ScreenWidth := w;
- ScreenHeight := h;
- glScissor(0, 0, w, h);
- glViewport(0, 0, w, h);
+ if enable <> enableTexture2D then
+ begin
+ if enable then glEnable(GL_TEXTURE_2D) else glDisable(GL_TEXTURE_2D);
+ enableTexture2D := enable;
+ end;
+ end;
+
+ procedure r_Draw_SetColor (r, g, b, a: Byte);
+ begin
+ if (r <> curR) or (g <> curG) or (b <> curB) or (curA <> a) then
+ begin
+ glColor4ub(r, g, b, a);
+ curR := r;
+ curG := g;
+ curB := b;
+ curA := a;
+ end;
+ end;
+
+ procedure r_Draw_Setup (sw, sh, gw, gh: Integer);
+ begin
+ ASSERT((sw >= 0) and (sh >= 0)); // screen/window size
+ ASSERT((gw >= 0) and (gh >= 0)); // virtual screen size
+ ScreenWidth := sw;
+ ScreenHeight := sh;
+ GameWidth := gw;
+ GameHeight := gh;
+ glScissor(0, 0, sw, sh);
+ glViewport(0, 0, sw, sh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
- glOrtho(0, w, h, 0, 0, 1);
+ glOrtho(0, gw, gh, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glEnable(GL_SCISSOR_TEST);
- r_Draw_SetRect(0, 0, w - 1, h - 1);
+ r_Draw_SetRect(0, 0, gw - 1, gh - 1);
end;
procedure DrawQuad (x, y, w, h: Integer);
begin
if tile = nil then
begin
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_SetColor(rr, gg, bb, aa);
if blend then glBlendFunc(GL_SRC_ALPHA, GL_ONE) else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_TEXTURE_2D);
+ r_Draw_EnableTexture2D(false);
glEnable(GL_BLEND);
DrawQuad(x, y, w, h);
end
ay := (tile.t) / nw;
by := (tile.b + 1) / nh;
l := x; t := y; r := x + w; b := y + h;
- glBindTexture(GL_TEXTURE_2D, tile.id);
- glColor4ub(rr, gg, bb, aa);
+ r_Textures_GL_Bind(tile.id);
+ r_Draw_SetColor(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(true);
if blend then glBlendFunc(GL_SRC_ALPHA, GL_ONE) else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBegin(GL_QUADS);
glTexCoord2f(ax, ay); glVertex2i(r, t);
glTexCoord2f(bx, by); glVertex2i(l, b);
glTexCoord2f(ax, by); glVertex2i(r, b);
glEnd();
- glDisable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, 0);
end
end;
ay := 0 / nw;
by := h / nh;
l := x; t := y; r := x + w; b := y + h;
- glBindTexture(GL_TEXTURE_2D, gltex);
- glColor4ub(rr, gg, bb, aa);
+ r_Textures_GL_Bind(gltex);
+ r_Draw_SetColor(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(true);
if blend then glBlendFunc(GL_SRC_ALPHA, GL_ONE) else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBegin(GL_QUADS);
glTexCoord2f(ax, ay); glVertex2i(r, t);
glTexCoord2f(bx, by); glVertex2i(l, b);
glTexCoord2f(ax, by); glVertex2i(r, b);
glEnd();
- glDisable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, 0);
end;
procedure r_Draw_Texture (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean);
ASSERT(b >= t);
glEnable(GL_BLEND);
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
- glDisable(GL_TEXTURE_2D);
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(false);
+ r_Draw_SetColor(rr, gg, bb, aa);
glBegin(GL_QUADS);
glVertex2i(l, t);
glVertex2i(r, t);
ASSERT(b >= t);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_TEXTURE_2D);
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(false);
+ r_Draw_SetColor(rr, gg, bb, aa);
glBegin(GL_LINE_LOOP);
{
glVertex2i(l, t);
ASSERT(b >= t);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_TEXTURE_2D);
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(false);
+ r_Draw_SetColor(rr, gg, bb, aa);
glBegin(GL_QUADS);
{
glVertex2i(l, t);
ASSERT(b >= t);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
- glDisable(GL_TEXTURE_2D);
- glColor4ub(rr, gg, bb, aa);
+ r_Draw_EnableTexture2D(false);
+ r_Draw_SetColor(rr, gg, bb, aa);
glBegin(GL_QUADS);
glVertex2i(l, t);
glVertex2i(r, t);
end;
procedure r_Draw_SetRect (l, t, r, b: Integer);
- var w, h: Integer;
+ var x, y, w, h: Integer;
begin
ASSERT(l <= r);
ASSERT(t <= b);
- w := r - l + 1;
- h := b - t + 1;
- glScissor(l, ScreenHeight - h - t, w, h);
+ x := l * ScreenWidth div GameWidth;
+ y := t * ScreenHeight div GameHeight;
+ w := (r - l + 1) * ScreenWidth div GameWidth;
+ h := (b - t + 1) * ScreenHeight div GameHeight;
+ glScissor(x, ScreenHeight - h - y, w, h);
sl := l; st := t; sr := r; sb := b;
end;