DEADSOFTWARE

fixed garbage on textures with transparency, implemented GetScancodeName
[d2df-sdl.git] / src / nogl / noGLALSW.inc
1 implementation
3 uses Allegro, Math, SDL2, e_Log;
5 const
6 GL_INVALID_ENUM = $0500;
8 const
9 ValPerVertex = 2;
10 ValPerColor = 1; (* colors stored in one integer *)
11 ValPerCoord = 2;
12 StackSize = 16;
14 BLEND_BLEND = 0;
15 BLEND_DARKER = 1;
16 BLEND_FILTER = 2;
17 BLEND_INVERT = 3;
18 BLEND_DEFAULT = 5;
20 type
21 TArrayFloat = array of GLfloat;
22 TArrayInteger = array of Integer;
24 TCmds = record
25 mode: GLenum;
26 v: TArrayInteger;
27 c: TArrayInteger;
28 t: TArrayFloat;
29 end;
31 TArrayTexture = array of record
32 used: Boolean;
33 bmp: PBITMAP;
34 end;
36 var
37 cmds: TCmds;
38 tex: TArrayTexture;
39 ctex: Integer;
40 ccol: Integer;
41 clearColor: cint;
42 stack: array [0..StackSize - 1] of record
43 x, y, a: Integer;
44 end;
45 stack_ptr: Integer;
46 vpx, vpy: Integer;
47 pointSize: Integer;
48 matrixMode: GLenum;
49 blendMode: Integer;
51 globalTransTable: COLOR_MAP_T;
52 redTransTable: COLOR_MAP_T;
53 greenTransTable: COLOR_MAP_T;
54 blueTransTable: COLOR_MAP_T;
55 darkTransTable: COLOR_MAP_T;
56 lightTransTable: COLOR_MAP_T;
58 function AddTexture: Integer;
59 var i: Integer;
60 begin
61 for i := 1 to High(tex) do
62 if not tex[i].used then
63 begin
64 tex[i].used := true;
65 tex[i].bmp := nil;
66 result := i;
67 exit
68 end;
69 i := Length(tex);
70 SetLength(tex, i + 1);
71 tex[i].used := true;
72 tex[i].bmp := nil;
73 result := i
74 end;
76 procedure RemoveTexture(i: Integer);
77 begin
78 assert(i >= 0);
79 assert(i <= High(tex));
80 assert((i = 0) or tex[i].used); (* free unallocated texture *)
81 tex[i].used := false;
82 if tex[i].bmp <> nil then
83 destroy_bitmap(tex[i].bmp);
84 tex[i].bmp := nil
85 end;
87 procedure Addi (var x: TArrayInteger; f: Integer);
88 var i: Integer;
89 begin
90 i := Length(x);
91 SetLength(x, i + 1);
92 x[i] := f;
93 end;
95 procedure Addf (var x: TArrayFloat; f: GLfloat);
96 var i: Integer;
97 begin
98 i := Length(x);
99 SetLength(x, i + 1);
100 x[i] := f;
101 end;
103 (** Open GL **)
105 procedure glEnable(cap: GLenum);
106 begin
107 end;
109 procedure glDisable(cap: GLenum);
110 begin
111 end;
113 function glIsEnabled(cap: GLenum): GLboolean;
114 begin
115 result := 0
116 end;
118 function glGetString(name: GLenum): PChar;
119 begin
120 if name = GL_EXTENSIONS then (* separated by space *)
121 result := 'GL_ARB_texture_non_power_of_two'
122 else
123 result := nil
124 end;
126 procedure glClearColor(red, green, blue, alpha: GLclampf);
127 begin
128 clearColor := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255));
129 end;
131 procedure glClear(mask: GLbitfield);
132 begin
133 if (mask and GL_COLOR_BUFFER_BIT) <> 0 then
134 clear_to_color(sdl2allegro_screen, clearColor)
135 end;
137 procedure glAlphaFunc(func: GLenum; ref: GLclampf);
138 begin
139 end;
141 procedure glBlendFunc(sfactor, dfactor: GLenum);
142 begin
143 if (sfactor = GL_SRC_ALPHA) and (dfactor = GL_ONE) then blendMode := BLEND_BLEND
144 else if (sfactor = GL_ZERO) and (dfactor = GL_SRC_ALPHA) then blendMode := BLEND_DARKER
145 else if (sfactor = GL_DST_COLOR) and (dfactor = GL_SRC_COLOR) then blendMode := BLEND_FILTER
146 else if (sfactor = GL_ONE_MINUS_DST_COLOR) and (dfactor = GL_ZERO) then blendMode := BLEND_INVERT
147 else if (sfactor = GL_SRC_ALPHA) and (dfactor = GL_ONE_MINUS_SRC_ALPHA) then blendMode := BLEND_DEFAULT
148 else ASSERT(FALSE)
149 end;
151 procedure SetupBlendColor (col: cint);
152 var r, g, b, a: cint;
153 begin
154 //set_trans_blender(r, g, b, a);
155 //set_add_blender(r, g, b, a);
156 //set_burn_blender(r, g, b, a);
157 //set_color_blender(r, g, b, a);
158 //set_difference_blender(r, g, b, a);
159 //set_dissolve_blender(r, g, b, a);
160 //set_dodge_blender(r, g, b, a);
161 //set_hue_blender(r, g, b, a);
162 //set_invert_blender(r, g, b, a);
163 //set_luminance_blender(r, g, b, a);
164 //set_multiply_blender(r, g, b, a);
165 //set_saturation_blender(r, g, b, a);
166 //set_screen_blender(r, g, b, a);
167 r := getr(col);
168 g := getg(col);
169 b := getb(col);
170 a := geta(col);
171 color_map := @globalTransTable;
172 case blendMode of
173 BLEND_BLEND:
174 begin
175 color_map := @lightTransTable;
176 set_add_blender(r, g, b, a);
177 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
178 end;
179 BLEND_DARKER:
180 begin
181 color_map := @darkTransTable;
182 set_multiply_blender(0, 0, 0, 255 - a);
183 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
184 end;
185 BLEND_FILTER:
186 begin
187 set_luminance_blender(0, 0, 0, 255);
188 if r <> 0 then
189 color_map := @redTransTable
190 else if g <> 0 then
191 color_map := @greenTransTable
192 else if b <> 0 then
193 color_map := @blueTransTable;
194 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
195 end;
196 BLEND_INVERT:
197 begin
198 drawing_mode(DRAW_MODE_XOR, nil, 0, 0)
199 end;
200 BLEND_DEFAULT:
201 begin
202 (* FIX texture colorize *)
203 if DEFAULT_DEPTH <= 8 then
204 begin
205 drawing_mode(DRAW_MODE_SOLID, nil, 0, 0)
206 end
207 else
208 begin
209 set_color_blender(0, 0, 0, 0);
210 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
211 end
212 end
213 else
214 ASSERT(FALSE)
215 end
216 end;
218 procedure glPointSize(size: GLfloat);
219 begin
220 ASSERT(size >= 0);
221 if size <= 1.0 then pointSize := ceil(size)
222 else pointSize := floor(size)
223 end;
225 procedure glLineWidth(width: GLfloat);
226 begin
227 (* width > 1 used in rare cases, not critical *)
228 end;
230 procedure glGetIntegerv(pname: GLenum; params: PGLint);
231 begin
232 params^ := 0
233 end;
235 procedure glFlush;
236 begin
237 end;
239 procedure glFinish;
240 begin
241 end;
243 procedure glBegin(mode: GLenum);
244 begin
245 assert(cmds.mode = GL_INVALID_ENUM);
246 assert((mode = GL_POINTS) or (mode = GL_LINES) or (mode = GL_QUADS));
247 cmds.mode := mode;
248 SetLength(cmds.v, 0);
249 SetLength(cmds.c, 0);
250 SetLength(cmds.t, 0);
251 end;
253 procedure glEnd;
254 var
255 i, j, k, w, h, x0, y0, x1, y1, offx, offy, tmp, s0, t0, s1, t1, angle: Integer;
256 oldx0, oldy0, oldx1, oldy1: cint;
257 flipv, fliph: Boolean;
258 draw_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint); cdecl;
259 rotate_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint; a: cint32); cdecl;
260 begin
261 assert(cmds.mode <> GL_INVALID_ENUM);
262 assert(Length(cmds.v) mod ValPerVertex = 0);
263 assert(Length(cmds.c) mod ValPerColor = 0);
264 assert(Length(cmds.t) mod ValPerCoord = 0);
266 offx := vpx + stack[stack_ptr].x;
267 offy := vpy + stack[stack_ptr].y;
268 angle := stack[stack_ptr].a;
270 drawing_mode(DRAW_MODE_SOLID, nil, 0, 0);
272 case cmds.mode of
273 GL_POINTS:
274 begin
275 (* implement case for texture coords? *)
276 if pointSize = 1 then
277 begin
278 if Length(cmds.c) <> 0 then
279 begin
280 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
281 for i := 0 to Length(cmds.v) div 2 - 1 do
282 putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], cmds.c[i])
283 end
284 else
285 begin
286 for i := 0 to Length(cmds.v) div 2 - 1 do
287 putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], ccol)
288 end
289 end
290 else if pointSize > 1 then
291 begin
292 x0 := offx - pointSize div 2;
293 y0 := offy - pointSize div 2;
294 x1 := offx - (pointSize - 1) div 2;
295 y1 := offy - (pointSize - 1) div 2;
296 if Length(cmds.c) <> 0 then
297 begin
298 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
299 for i := 0 to Length(cmds.v) div 2 - 1 do
300 begin
301 w := cmds.v[i * 2 + 0];
302 h := cmds.v[i * 2 + 1];
303 rectfill(sdl2allegro_screen, x0 + w, y0 + h, x1 + w, y1 + h, cmds.c[i])
304 end
305 end
306 else
307 begin
308 for i := 0 to Length(cmds.v) div 2 - 1 do
309 begin
310 w := cmds.v[i * 2 + 0];
311 h := cmds.v[i * 2 + 1];
312 rectfill(sdl2allegro_screen, x0 + w, y0 + h, x1 + w, y1 + h, ccol)
313 end
314 end
315 end
316 end;
317 GL_LINES:
318 begin
319 assert(Length(cmds.v) mod 4 = 0); (* broken line *)
320 (* implement case for texture coords? *)
321 if Length(cmds.c) <> 0 then
322 begin
323 assert(Length(cmds.c) * 2 = Length(cmds.v));
324 for i := 0 to Length(cmds.v) div 4 - 1 do
325 fastline(sdl2allegro_screen, offx + cmds.v[i * 4], offy + cmds.v[i * 4 + 1], offx + cmds.v[i * 4 + 2], offy + cmds.v[i * 4 + 3], cmds.c[i * 2])
326 end
327 else
328 begin
329 for i := 0 to Length(cmds.v) div 4 - 1 do
330 fastline(sdl2allegro_screen, offx + cmds.v[i * 4], offy + cmds.v[i * 4 + 1], offx + cmds.v[i * 4 + 2], offy + cmds.v[i * 4 + 3], ccol)
331 end
332 end;
333 GL_QUADS:
334 begin
335 ASSERT(Length(cmds.v) mod 8 = 0); (* broken quad *)
336 if Length(cmds.t) <> 0 then
337 begin
338 ASSERT(Length(cmds.t) = Length(cmds.v)); (* not enough texture coords *)
339 ASSERT(ctex >= 0);
340 ASSERT(ctex <= High(tex));
341 ASSERT(tex[ctex].bmp <> nil);
342 for i := 0 to Length(cmds.v) div 8 - 1 do
343 begin
344 flipv := False; fliph := False;
345 x0 := cmds.v[i * 8 + 0]; y0 := cmds.v[i * 8 + 1];
346 x1 := cmds.v[i * 8 + 4]; y1 := cmds.v[i * 8 + 5];
347 if x1 < x0 then
348 begin
349 tmp := x0;
350 x0 := x1;
351 x1 := tmp;
352 fliph := not fliph
353 end;
354 if y1 < y0 then
355 begin
356 tmp := y0;
357 y0 := y1;
358 y1 := tmp;
359 flipv := not flipv
360 end;
362 w := tex[ctex].bmp.w;
363 h := tex[ctex].bmp.h;
364 s0 := Trunc(cmds.t[i * 8 + 0] * w);
365 t0 := Trunc(cmds.t[i * 8 + 1] * h);
366 s1 := Trunc(cmds.t[i * 8 + 4] * w);
367 t1 := Trunc(cmds.t[i * 8 + 5] * h);
369 if s1 < s0 then
370 begin
371 tmp := s0;
372 s0 := s1;
373 s1 := tmp;
374 fliph := not fliph;
375 end;
376 if t1 < t0 then
377 begin
378 tmp := t0;
379 t0 := t1;
380 t1 := tmp;
381 flipv := not flipv;
382 end;
384 if fliph then
385 begin
386 tmp := s0;
387 s0 := w - s1;
388 s1 := w - tmp;
389 end;
390 if flipv then
391 begin
392 tmp := t0;
393 t0 := h - t1;
394 t1 := h - tmp;
395 end;
397 s0 := s0 mod w;
398 t0 := t0 mod h;
399 s1 := s1 mod w;
400 t1 := t1 mod h;
402 if flipv and fliph then
403 draw_sprite_proc := Allegro.draw_sprite_vh_flip
404 else if flipv then
405 draw_sprite_proc := Allegro.draw_sprite_v_flip
406 else if fliph then
407 draw_sprite_proc := Allegro.draw_sprite_h_flip
408 else
409 draw_sprite_proc := Allegro.draw_sprite;
411 if flipv and fliph then
412 rotate_sprite_proc := Allegro.rotate_sprite_v_flip (* ??? *)
413 else if flipv then
414 rotate_sprite_proc := Allegro.rotate_sprite_v_flip
415 else if fliph then
416 rotate_sprite_proc := Allegro.rotate_sprite (* ??? *)
417 else
418 rotate_sprite_proc := Allegro.rotate_sprite;
420 oldx0 := 0; oldy0 := 0; oldx1 := 0; oldy1 := 0;
421 get_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
422 set_clip_rect(sdl2allegro_screen, max(oldx0, offx + x0), max(oldy0, offy + y0), min(oldx1, offx + x1), min(oldy1, offy + y1));
424 SetupBlendColor(ccol);
425 if angle = 0 then
426 for j := 0 to (y1 - y0 + h - 1) div h - 1 do
427 for k := 0 to (x1 - x0 + w - 1) div w - 1 do
428 draw_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0)
429 else
430 for j := 0 to (y1 - y0 + h - 1) div h - 1 do
431 for k := 0 to (x1 - x0 + w - 1) div w - 1 do
432 rotate_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0, angle);
434 set_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
436 //rect(sdl2allegro_screen, offx + x0, offy + y0, offx + x1, offy + y1, makecol(255, 0, 0));
437 //rect(sdl2allegro_screen, offx + oldx0, offy + oldy0, offx + oldx1, offy + oldx1, makecol(0, 255, 0));
438 end
439 end
440 else if Length(cmds.c) <> 0 then
441 begin
442 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
443 for i := 0 to Length(cmds.v) div 8 - 1 do
444 begin
445 SetupBlendColor(cmds.c[i * 4]);
446 rectfill(sdl2allegro_screen, offx + cmds.v[i * 8], offy + cmds.v[i * 8 + 1], offx + cmds.v[i * 8 + 4], offy + cmds.v[i * 8 + 5], cmds.c[i * 4])
447 end
448 end
449 else
450 begin
451 SetupBlendColor(ccol);
452 for i := 0 to Length(cmds.v) div 8 - 1 do
453 rectfill(sdl2allegro_screen, offx + cmds.v[i * 8], offy + cmds.v[i * 8 + 1], offx + cmds.v[i * 8 + 4], offy + cmds.v[i * 8 + 5], ccol)
454 end
455 end;
456 else
457 assert(false)
458 end;
460 SetLength(cmds.v, 0);
461 SetLength(cmds.c, 0);
462 SetLength(cmds.t, 0);
463 cmds.mode := GL_INVALID_ENUM;
464 end;
466 procedure glVertex2f(x, y: GLfloat);
467 begin
468 Addi(cmds.v, ceil(x));
469 Addi(cmds.v, ceil(y))
470 end;
472 procedure glVertex2i(x, y: GLint);
473 begin
474 Addi(cmds.v, x);
475 Addi(cmds.v, y)
476 end;
478 procedure glColor4f(red, green, blue, alpha: GLfloat);
479 begin
480 ccol := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255));
481 Addi(cmds.c, ccol)
482 end;
484 procedure glColor4ub(red, green, blue, alpha: GLubyte);
485 begin
486 ccol := makeacol(red, green, blue, alpha);
487 Addi(cmds.c, ccol)
488 end;
490 procedure glColor3ub(red, green, blue: GLubyte);
491 begin
492 ccol := makecol(red, green, blue);
493 Addi(cmds.c, ccol)
494 end;
496 procedure glTexCoord2f(s, t: GLfloat);
497 begin
498 Addf(cmds.t, s);
499 Addf(cmds.t, t);
500 end;
502 procedure glTexCoord2i(s, t: GLint);
503 begin
504 Addf(cmds.t, s);
505 Addf(cmds.t, t);
506 end;
508 procedure glReadPixels(x, y: GLint; width, height: GLsizei; format, atype: GLenum; pixels: Pointer);
509 begin
510 end;
512 procedure glLoadIdentity;
513 begin
514 if matrixMode <> GL_MODELVIEW then Exit;
515 with stack[stack_ptr] do
516 begin
517 x := 0;
518 y := 0;
519 (* TODO Rotation and scale *)
520 end
521 end;
523 procedure glMatrixMode(mode: GLenum);
524 begin
525 (* GL_PROJECTION -> verify or ignore *)
526 (* GL_MODELVIEW -> apply *)
527 ASSERT((mode = GL_PROJECTION) or (mode = GL_MODELVIEW));
528 matrixMode := mode;
529 end;
531 procedure glLoadMatrixd(const m: PGLdouble);
532 begin
533 if matrixMode <> GL_MODELVIEW then Exit;
535 (*
536 e_LogWritefln('glLoadMatrix:', []);
537 e_LogWritefln('| %s %s %s %s |', [m[0], m[1], m[2], m[3]]);
538 e_LogWritefln('| %s %s %s %s |', [m[4], m[5], m[6], m[7]]);
539 e_LogWritefln('| %s %s %s %s |', [m[8], m[9], m[10], m[11]]);
540 e_LogWritefln('| %s %s %s %s |', [m[12], m[13], m[14], m[15]]);
541 *)
542 with stack[stack_ptr] do
543 begin
544 x := Trunc(m[3]);
545 y := Trunc(m[7]);
546 ASSERT(m[11] = 0);
547 (* TODO Rotation and Scale *)
548 end
549 end;
551 procedure glPushMatrix;
552 begin
553 if matrixMode <> GL_MODELVIEW then Exit;
554 stack[stack_ptr + 1] := stack[stack_ptr];
555 INC(stack_ptr);
556 end;
558 procedure glPopMatrix;
559 begin
560 if matrixMode <> GL_MODELVIEW then Exit;
561 DEC(stack_ptr)
562 end;
564 procedure glTranslatef(x, y, z: GLfloat);
565 begin
566 if matrixMode <> GL_MODELVIEW then Exit;
567 ASSERT(z = 0); (* 3D not supported *)
568 stack[stack_ptr].x += Trunc(x);
569 stack[stack_ptr].y += Trunc(y);
570 end;
572 procedure glRotatef(angle, x, y, z: GLfloat);
573 begin
574 if matrixMode <> GL_MODELVIEW then Exit;
575 ASSERT(x = 0); (* 3D not supported *)
576 ASSERT(y = 0); (* 3D not supported *)
577 // angle 360deg == 256 with conversion to fixed point 16.16
578 stack[stack_ptr].a += floor(angle * z * 0.71111) * 65536
579 end;
581 procedure glScalef(x, y, z: GLfloat);
582 begin
583 if matrixMode <> GL_MODELVIEW then Exit;
584 (* 3D not supported, but z can be any *)
585 (* TODO Scale *)
586 end;
588 procedure glViewport(x, y: GLint; width, height: GLsizei);
589 begin
590 vpx := x; vpy := y;
591 set_clip_rect(sdl2allegro_screen, x, y, x + width, y + height);
592 end;
594 procedure glScissor(x, y: GLint; width, height: GLsizei);
595 begin
596 //set_clip_rect(sdl2allegro_screen, x, y, width, height)
597 end;
599 procedure glStencilMask(mask: GLuint);
600 begin
601 end;
603 procedure glStencilFunc(func: GLenum; ref: GLint; mask: GLuint);
604 begin
605 end;
607 procedure glStencilOp(fail, zfail, zpass: GLenum);
608 begin
609 end;
611 procedure glColorMask(red, green, blue, alpha: GLboolean);
612 begin
613 end;
615 procedure glBindTexture(target: GLenum; texture: GLuint);
616 begin
617 assert(target = GL_TEXTURE_2D);
618 ctex := texture;
619 end;
621 procedure glGenTextures(n: GLsizei; textures: PGLuint);
622 var i: Integer;
623 begin
624 for i := 0 to n - 1 do
625 textures[i] := AddTexture
626 end;
628 procedure glTexEnvi(target: GLenum; pname: GLenum; param: GLint);
629 begin
630 end;
632 procedure glTexParameterf(target: GLenum; pname: GLenum; param: GLfloat);
633 begin
634 end;
636 procedure glTexParameteri(target: GLenum; pname: GLenum; param: GLint);
637 begin
638 end;
640 procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer);
641 var i, j, adr: Integer; p: PByte; color, trans: cint;
642 begin
643 assert(target = GL_TEXTURE_2D);
644 assert(level = 0);
645 assert((internalformat = GL_RGBA) or (internalformat = GL_RGB));
646 assert((format = GL_RGBA) or (format = GL_RGB));
647 assert(border = 0);
648 assert(atype = GL_UNSIGNED_BYTE);
650 assert(ctex >= 0);
651 assert(ctex <= High(tex));
652 assert(tex[ctex].used);
654 if tex[ctex].bmp <> nil then
655 destroy_bitmap(tex[ctex].bmp);
656 tex[ctex].bmp := create_system_bitmap(width, height);
657 if tex[ctex].bmp = nil then
658 tex[ctex].bmp := create_bitmap(width, height);
659 assert(tex[ctex].bmp <> nil);
661 if pixels = nil then exit;
663 p := pixels;
664 if format = GL_RGBA then
665 begin
666 if DEFAULT_DEPTH <= 8 then
667 trans := 0
668 else
669 trans := makeacol(255, 0, 255, 0);
671 for j := 0 to height - 1 do
672 for i := 0 to width - 1 do
673 begin
674 adr := j * width * 4 + i * 4;
675 if p[adr + 3] = 0 then
676 color := trans
677 else
678 color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]);
679 putpixel(tex[ctex].bmp, i, j, color)
680 end
681 end
682 else
683 begin
684 for j := 0 to height - 1 do
685 for i := 0 to width - 1 do
686 begin
687 adr := j * width * 3 + i * 3;
688 putpixel(tex[ctex].bmp, i, j, makecol(p[adr], p[adr + 1], p[adr + 2]))
689 end
690 end
691 end;
693 procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer);
694 var i, j, adr: Integer; p: PByte; color, trans: Cint;
695 begin
696 assert(target = GL_TEXTURE_2D);
697 assert(level = 0);
698 assert((format = GL_RGBA) or (format = GL_RGB));
699 assert(atype = GL_UNSIGNED_BYTE);
701 assert(ctex >= 0);
702 assert(ctex <= High(tex));
703 assert(tex[ctex].used);
705 assert(xoffset = 0);
706 assert(yoffset = 0);
708 if pixels = nil then exit;
710 p := pixels;
711 if format = GL_RGBA then
712 begin
713 if DEFAULT_DEPTH <= 8 then
714 trans := 0
715 else
716 trans := makeacol(255, 0, 255, 0);
718 for j := 0 to height - 1 do
719 for i := 0 to width - 1 do
720 begin
721 adr := j * width * 4 + i * 4;
722 if p[adr + 3] = 0 then
723 color := trans
724 else
725 color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]);
726 putpixel(tex[ctex].bmp, i, j, color)
727 end
728 end
729 else
730 begin
731 for j := 0 to height - 1 do
732 for i := 0 to width - 1 do
733 begin
734 adr := j * width * 3 + i * 3;
735 putpixel(tex[ctex].bmp, i, j, makecol(p[adr], p[adr + 1], p[adr + 2]))
736 end
737 end
738 end;
740 procedure glDeleteTextures(n: GLsizei; const textures: PGLuint);
741 var i: Integer;
742 begin
743 for i := 0 to n - 1 do
744 RemoveTexture(textures[i])
745 end;
747 procedure nogl_Init;
748 begin
749 cmds.mode := GL_INVALID_ENUM;
750 create_trans_table(@globalTransTable, default_palette, 255, 255, 255, nil);
751 create_trans_table(@redTransTable, default_palette, 0, 255, 255, nil);
752 create_trans_table(@greenTransTable, default_palette, 255, 0, 255, nil);
753 create_trans_table(@blueTransTable, default_palette, 255, 255, 0, nil);
754 create_trans_table(@darkTransTable, default_palette, 191, 191, 191, nil);
755 create_trans_table(@lightTransTable, default_palette, 64, 64, 64, nil);
756 color_map := @globalTransTable;
757 end;
759 procedure nogl_Quit;
760 begin
761 end;
763 initialization