summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: be2f0e3)
raw | patch | inline | side by side (parent: be2f0e3)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 1 Feb 2019 18:48:34 +0000 (21:48 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 10 Feb 2019 10:05:11 +0000 (13:05 +0300) |
src/game/g_window.pas | patch | blob | history | |
src/nogl/noGLALSW.inc | patch | blob | history | |
src/wrappers/sdl2/sdl2allegro.inc | patch | blob | history |
diff --git a/src/game/g_window.pas b/src/game/g_window.pas
index 3958d24d12df79b518b6dc351942a53d487acc52..3d9753377d8fc65d01eabec01fb77a39cfc5c60a 100644 (file)
--- a/src/game/g_window.pas
+++ b/src/game/g_window.pas
procedure InitOpenGL ();
begin
{$IF not DEFINED(HEADLESS)}
- {$IFDEF USE_GLES1}
+ {$IF DEFINED(USE_GLES1)}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
{$ELSE}
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
diff --git a/src/nogl/noGLALSW.inc b/src/nogl/noGLALSW.inc
index 853c22495095f6c1f2ce94b996490eb92b48f72e..b9f1ddd960d79fb4dfc274ec739ead974103bc94 100644 (file)
--- a/src/nogl/noGLALSW.inc
+++ b/src/nogl/noGLALSW.inc
x, y: Integer;
end;
stack_ptr: Integer;
+ vpx, vpy: Integer;
+ pointSize: Integer;
+ matrixMode: GLenum;
function AddTexture: Integer;
var i: Integer;
begin
- for i := 0 to High(tex) do
+ for i := 1 to High(tex) do
if not tex[i].used then
begin
tex[i].used := true;
begin
assert(i >= 0);
assert(i <= High(tex));
- //assert(tex[i].used); (* free unallocated texture *)
+ assert((i = 0) or tex[i].used); (* free unallocated texture *)
tex[i].used := false;
if tex[i].bmp <> nil then
destroy_bitmap(tex[i].bmp);
function glGetString(name: GLenum): PChar;
begin
- result := ''
+ if name = GL_EXTENSIONS then (* separated by space *)
+ result := 'GL_ARB_texture_non_power_of_two'
+ else
+ result := nil
end;
procedure glClearColor(red, green, blue, alpha: GLclampf);
procedure glPointSize(size: GLfloat);
begin
+ ASSERT(size >= 0);
+ if size <= 1.0 then pointSize := ceil(size)
+ else pointSize := floor(size)
end;
procedure glLineWidth(width: GLfloat);
begin
+ (* width > 1 used in rare cases, not critical *)
end;
procedure glGetIntegerv(pname: GLenum; params: PGLint);
assert(Length(cmds.c) mod ValPerColor = 0);
assert(Length(cmds.t) mod ValPerCoord = 0);
- offx := stack[stack_ptr].x;
- offy := stack[stack_ptr].y;
+ offx := vpx + stack[stack_ptr].x;
+ offy := vpy + stack[stack_ptr].y;
case cmds.mode of
GL_POINTS:
begin
- (* implement case for texture coords? *)
- if Length(cmds.c) <> 0 then
- begin
- assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
- for i := 0 to Length(cmds.v) div 2 - 1 do
- putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], cmds.c[i])
- end
- else
- begin
- for i := 0 to Length(cmds.v) div 2 - 1 do
- putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], ccol)
- end
+ (* implement case for texture coords? *)
+ if pointSize = 1 then
+ begin
+ if Length(cmds.c) <> 0 then
+ begin
+ assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
+ for i := 0 to Length(cmds.v) div 2 - 1 do
+ putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], cmds.c[i])
+ end
+ else
+ begin
+ for i := 0 to Length(cmds.v) div 2 - 1 do
+ putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], ccol)
+ end
+ end
+ else if pointSize > 1 then
+ begin
+ x0 := offx - pointSize div 2;
+ y0 := offy - pointSize div 2;
+ x1 := offx - (pointSize - 1) div 2;
+ y1 := offy - (pointSize - 1) div 2;
+ if Length(cmds.c) <> 0 then
+ begin
+ assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
+ for i := 0 to Length(cmds.v) div 2 - 1 do
+ begin
+ w := cmds.v[i * 2 + 0];
+ h := cmds.v[i * 2 + 1];
+ rectfill(sdl2allegro_screen, x0 + w, y0 + h, x1 + w, y1 + h, cmds.c[i])
+ end
+ end
+ else
+ begin
+ for i := 0 to Length(cmds.v) div 2 - 1 do
+ begin
+ w := cmds.v[i * 2 + 0];
+ h := cmds.v[i * 2 + 1];
+ rectfill(sdl2allegro_screen, x0 + w, y0 + h, x1 + w, y1 + h, ccol)
+ end
+ end
+ end
end;
GL_LINES:
begin
tmp := s0;
s0 := s1;
s1 := tmp;
- fliph := not fliph
+ fliph := not fliph;
end;
if t1 < t0 then
begin
tmp := t0;
t0 := t1;
t1 := tmp;
- flipv := not flipv
+ flipv := not flipv;
+ end;
+
+ if fliph then
+ begin
+ tmp := s0;
+ s0 := w - s1;
+ s1 := w - tmp;
+ end;
+ if flipv then
+ begin
+ tmp := t0;
+ t0 := h - t1;
+ t1 := h - tmp;
end;
s0 := s0 mod w;
for j := 0 to (y1 - y0 + h - 1) div h - 1 do
for k := 0 to (x1 - x0 + w - 1) div w - 1 do
draw_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0);
- //blit(tex[ctex].bmp, sdl2allegro_screen, 0, 0, offx + x0 + k * w - s0, offy + y0 + j * h - t0, w, h);
set_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
procedure glLoadIdentity;
begin
+ if matrixMode <> GL_MODELVIEW then Exit;
with stack[stack_ptr] do
begin
x := 0;
y := 0;
+ (* TODO Rotation and scale *)
end
end;
procedure glMatrixMode(mode: GLenum);
begin
+ (* GL_PROJECTION -> verify or ignore *)
+ (* GL_MODELVIEW -> apply *)
+ ASSERT((mode = GL_PROJECTION) or (mode = GL_MODELVIEW));
+ matrixMode := mode;
end;
procedure glLoadMatrixd(const m: PGLdouble);
begin
- //m[x,y]
+ if matrixMode <> GL_MODELVIEW then Exit;
+
+ (*
+ e_LogWritefln('glLoadMatrix:', []);
+ e_LogWritefln('| %s %s %s %s |', [m[0], m[1], m[2], m[3]]);
+ e_LogWritefln('| %s %s %s %s |', [m[4], m[5], m[6], m[7]]);
+ e_LogWritefln('| %s %s %s %s |', [m[8], m[9], m[10], m[11]]);
+ e_LogWritefln('| %s %s %s %s |', [m[12], m[13], m[14], m[15]]);
+ *)
+ with stack[stack_ptr] do
+ begin
+ x := Trunc(m[3]);
+ y := Trunc(m[7]);
+ ASSERT(m[11] = 0);
+ (* TODO Rotation and Scale *)
+ end
end;
procedure glPushMatrix;
begin
+ if matrixMode <> GL_MODELVIEW then Exit;
stack[stack_ptr + 1] := stack[stack_ptr];
INC(stack_ptr);
end;
procedure glPopMatrix;
begin
+ if matrixMode <> GL_MODELVIEW then Exit;
DEC(stack_ptr)
end;
procedure glTranslatef(x, y, z: GLfloat);
begin
+ if matrixMode <> GL_MODELVIEW then Exit;
ASSERT(z = 0); (* 3D not supported *)
- stack[stack_ptr].x := Trunc(x);
- stack[stack_ptr].y := Trunc(y);
+ stack[stack_ptr].x += Trunc(x);
+ stack[stack_ptr].y += Trunc(y);
end;
procedure glRotatef(angle, x, y, z: GLfloat);
begin
- //ASSERT(z = 0); (* 3D not supported *)
- (* TODO Rotation *)
+ if matrixMode <> GL_MODELVIEW then Exit;
+ ASSERT(x = 0); (* 3D not supported *)
+ ASSERT(y = 0); (* 3D not supported *)
+ (* TODO a := deg(angle * z) *)
end;
procedure glScalef(x, y, z: GLfloat);
begin
- //ASSERT(z = 1); (* 3D not supported *)
+ if matrixMode <> GL_MODELVIEW then Exit;
+ (* 3D not supported, but z can be any *)
(* TODO Scale *)
end;
procedure glViewport(x, y: GLint; width, height: GLsizei);
begin
+ vpx := x; vpy := y;
+ set_clip_rect(sdl2allegro_screen, x, y, x + width, y + height);
end;
procedure glScissor(x, y: GLint; width, height: GLsizei);
begin
+ //set_clip_rect(sdl2allegro_screen, x, y, width, height)
end;
procedure glStencilMask(mask: GLuint);
end;
procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer);
- var i, j, adr: Integer; p: PByte; color: cint;
+ var i, j, adr: Integer; p: PByte; color, trans: cint;
begin
assert(target = GL_TEXTURE_2D);
assert(level = 0);
if tex[ctex].bmp <> nil then
destroy_bitmap(tex[ctex].bmp);
- // Video bitmap can lead to bad textures under dos
- //tex[ctex].bmp := create_video_bitmap(width, height);
- //if tex[ctex].bmp = nil then
- tex[ctex].bmp := create_system_bitmap(width, height);
+ tex[ctex].bmp := create_system_bitmap(width, height);
if tex[ctex].bmp = nil then
tex[ctex].bmp := create_bitmap(width, height);
assert(tex[ctex].bmp <> nil);
p := pixels;
if format = GL_RGBA then
begin
+ if DEFAULT_DEPTH <= 8 then
+ trans := 0
+ else
+ trans := makeacol(255, 0, 255, 0);
+
for j := 0 to height - 1 do
for i := 0 to width - 1 do
begin
adr := j * width * 4 + i * 4;
- if p[adr + 3] <> $FF then
- color := 0
+ if p[adr + 3] = 0 then
+ color := trans
else
color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]);
putpixel(tex[ctex].bmp, i, j, color)
end;
procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer);
- var i, j, adr: Integer; p: PByte; color: Cint;
+ var i, j, adr: Integer; p: PByte; color, trans: Cint;
begin
assert(target = GL_TEXTURE_2D);
assert(level = 0);
p := pixels;
if format = GL_RGBA then
begin
+ if DEFAULT_DEPTH <= 8 then
+ trans := 0
+ else
+ trans := makeacol(255, 0, 255, 0);
+
for j := 0 to height - 1 do
for i := 0 to width - 1 do
begin
adr := j * width * 4 + i * 4;
- if p[adr + 3] <> $FF then
- color := 0
+ if p[adr + 3] = 0 then
+ color := trans
else
color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]);
putpixel(tex[ctex].bmp, i, j, color)
index 0d00c6a2359d6f37e8cf4d270f59f45becebfd88..ebedf9c02a85980f99b5b8e619959d3a6c257575 100644 (file)
/// MACRO ///
-//from "sdl_pixels.h"
-
function SDL_PIXELFLAG(X: Cardinal): Cardinal;
begin
Result := (X shr 28) and $0F;
function SDL_GetPerformanceCounter: UInt64;
begin
- //e_LogWriteln('SDL_GetPerformanceCounter');
(* TODO *)
result := ticks;
end;
function SDL_GetPerformanceFrequency: UInt64;
begin
- //e_LogWriteln('SDL_GetPerformanceFrequency');
(* TODO *)
result := 1
end;
procedure SDL_Delay(ms: UInt32);
begin
- //e_LogWriteln('SDL_Delay');
rest(ms)
end;
function SDL_GetTicks: UInt32;
begin
- //e_LogWriteln('SDL_GetTicks');
result := ticks;
end;
function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
begin
e_LogWritefln('SDL_GL_SetAttribute %s %s', [attr, value]);
- result := -1;
+ allegro_error := 'Attribute ' + IntToStr(attr) + ' := ' + IntToStr(value) + 'not supported';
+ result := -1
end;
function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
function SDL_ShowCursor(toggle: SInt32): SInt32;
begin
e_LogWritefln('SDL_ShowCursor %s', [toggle]);
+ (* TODO *)
result := 0
end;
function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
begin
e_LogWritefln('SDL_SetHint %s %s', [name, value]);
+ (* TODO *)
result := false
end;
function SDL_GetError: PAnsiChar;
begin
- e_LogWritefln('SDL_GetError => %s', [allegro_error]);
result := allegro_error;
end;
function SDL_Init(flags: UInt32): SInt32;
begin
- e_LogWritefln('SDL_Init %u', [flags]);
result := -1;
{$IFDEF GO32V2}
FIX_ARGV;
procedure SDL_Quit;
begin
- e_LogWriteln('SDL_Quit');
set_close_button_callback(nil);
remove_keyboard;
remove_timer;