DEADSOFTWARE

implemented blending
[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 set_saturation_blender(0, 0, 0, 0);
204 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
205 end
206 else
207 ASSERT(FALSE)
208 end
209 end;
211 procedure glPointSize(size: GLfloat);
212 begin
213 ASSERT(size >= 0);
214 if size <= 1.0 then pointSize := ceil(size)
215 else pointSize := floor(size)
216 end;
218 procedure glLineWidth(width: GLfloat);
219 begin
220 (* width > 1 used in rare cases, not critical *)
221 end;
223 procedure glGetIntegerv(pname: GLenum; params: PGLint);
224 begin
225 params^ := 0
226 end;
228 procedure glFlush;
229 begin
230 end;
232 procedure glFinish;
233 begin
234 end;
236 procedure glBegin(mode: GLenum);
237 begin
238 assert(cmds.mode = GL_INVALID_ENUM);
239 assert((mode = GL_POINTS) or (mode = GL_LINES) or (mode = GL_QUADS));
240 cmds.mode := mode;
241 SetLength(cmds.v, 0);
242 SetLength(cmds.c, 0);
243 SetLength(cmds.t, 0);
244 end;
246 procedure glEnd;
247 var
248 i, j, k, w, h, x0, y0, x1, y1, offx, offy, tmp, s0, t0, s1, t1, angle: Integer;
249 oldx0, oldy0, oldx1, oldy1: cint;
250 flipv, fliph: Boolean;
251 draw_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint); cdecl;
252 rotate_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint; a: cint32); cdecl;
253 begin
254 assert(cmds.mode <> GL_INVALID_ENUM);
255 assert(Length(cmds.v) mod ValPerVertex = 0);
256 assert(Length(cmds.c) mod ValPerColor = 0);
257 assert(Length(cmds.t) mod ValPerCoord = 0);
259 offx := vpx + stack[stack_ptr].x;
260 offy := vpy + stack[stack_ptr].y;
261 angle := stack[stack_ptr].a;
263 drawing_mode(DRAW_MODE_SOLID, nil, 0, 0);
265 case cmds.mode of
266 GL_POINTS:
267 begin
268 (* implement case for texture coords? *)
269 if pointSize = 1 then
270 begin
271 if Length(cmds.c) <> 0 then
272 begin
273 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
274 for i := 0 to Length(cmds.v) div 2 - 1 do
275 putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], cmds.c[i])
276 end
277 else
278 begin
279 for i := 0 to Length(cmds.v) div 2 - 1 do
280 putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], ccol)
281 end
282 end
283 else if pointSize > 1 then
284 begin
285 x0 := offx - pointSize div 2;
286 y0 := offy - pointSize div 2;
287 x1 := offx - (pointSize - 1) div 2;
288 y1 := offy - (pointSize - 1) div 2;
289 if Length(cmds.c) <> 0 then
290 begin
291 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
292 for i := 0 to Length(cmds.v) div 2 - 1 do
293 begin
294 w := cmds.v[i * 2 + 0];
295 h := cmds.v[i * 2 + 1];
296 rectfill(sdl2allegro_screen, x0 + w, y0 + h, x1 + w, y1 + h, cmds.c[i])
297 end
298 end
299 else
300 begin
301 for i := 0 to Length(cmds.v) div 2 - 1 do
302 begin
303 w := cmds.v[i * 2 + 0];
304 h := cmds.v[i * 2 + 1];
305 rectfill(sdl2allegro_screen, x0 + w, y0 + h, x1 + w, y1 + h, ccol)
306 end
307 end
308 end
309 end;
310 GL_LINES:
311 begin
312 assert(Length(cmds.v) mod 4 = 0); (* broken line *)
313 (* implement case for texture coords? *)
314 if Length(cmds.c) <> 0 then
315 begin
316 assert(Length(cmds.c) * 2 = Length(cmds.v));
317 for i := 0 to Length(cmds.v) div 4 - 1 do
318 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])
319 end
320 else
321 begin
322 for i := 0 to Length(cmds.v) div 4 - 1 do
323 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)
324 end
325 end;
326 GL_QUADS:
327 begin
328 ASSERT(Length(cmds.v) mod 8 = 0); (* broken quad *)
329 if Length(cmds.t) <> 0 then
330 begin
331 ASSERT(Length(cmds.t) = Length(cmds.v)); (* not enough texture coords *)
332 ASSERT(ctex >= 0);
333 ASSERT(ctex <= High(tex));
334 ASSERT(tex[ctex].bmp <> nil);
335 for i := 0 to Length(cmds.v) div 8 - 1 do
336 begin
337 flipv := False; fliph := False;
338 x0 := cmds.v[i * 8 + 0]; y0 := cmds.v[i * 8 + 1];
339 x1 := cmds.v[i * 8 + 4]; y1 := cmds.v[i * 8 + 5];
340 if x1 < x0 then
341 begin
342 tmp := x0;
343 x0 := x1;
344 x1 := tmp;
345 fliph := not fliph
346 end;
347 if y1 < y0 then
348 begin
349 tmp := y0;
350 y0 := y1;
351 y1 := tmp;
352 flipv := not flipv
353 end;
355 w := tex[ctex].bmp.w;
356 h := tex[ctex].bmp.h;
357 s0 := Trunc(cmds.t[i * 8 + 0] * w);
358 t0 := Trunc(cmds.t[i * 8 + 1] * h);
359 s1 := Trunc(cmds.t[i * 8 + 4] * w);
360 t1 := Trunc(cmds.t[i * 8 + 5] * h);
362 if s1 < s0 then
363 begin
364 tmp := s0;
365 s0 := s1;
366 s1 := tmp;
367 fliph := not fliph;
368 end;
369 if t1 < t0 then
370 begin
371 tmp := t0;
372 t0 := t1;
373 t1 := tmp;
374 flipv := not flipv;
375 end;
377 if fliph then
378 begin
379 tmp := s0;
380 s0 := w - s1;
381 s1 := w - tmp;
382 end;
383 if flipv then
384 begin
385 tmp := t0;
386 t0 := h - t1;
387 t1 := h - tmp;
388 end;
390 s0 := s0 mod w;
391 t0 := t0 mod h;
392 s1 := s1 mod w;
393 t1 := t1 mod h;
395 if flipv and fliph then
396 draw_sprite_proc := Allegro.draw_sprite_vh_flip
397 else if flipv then
398 draw_sprite_proc := Allegro.draw_sprite_v_flip
399 else if fliph then
400 draw_sprite_proc := Allegro.draw_sprite_h_flip
401 else
402 draw_sprite_proc := Allegro.draw_sprite;
404 if flipv and fliph then
405 rotate_sprite_proc := Allegro.rotate_sprite_v_flip (* ??? *)
406 else if flipv then
407 rotate_sprite_proc := Allegro.rotate_sprite_v_flip
408 else if fliph then
409 rotate_sprite_proc := Allegro.rotate_sprite (* ??? *)
410 else
411 rotate_sprite_proc := Allegro.rotate_sprite;
413 oldx0 := 0; oldy0 := 0; oldx1 := 0; oldy1 := 0;
414 get_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
415 set_clip_rect(sdl2allegro_screen, max(oldx0, offx + x0), max(oldy0, offy + y0), min(oldx1, offx + x1), min(oldy1, offy + y1));
417 SetupBlendColor(ccol);
418 if angle = 0 then
419 for j := 0 to (y1 - y0 + h - 1) div h - 1 do
420 for k := 0 to (x1 - x0 + w - 1) div w - 1 do
421 draw_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0)
422 else
423 for j := 0 to (y1 - y0 + h - 1) div h - 1 do
424 for k := 0 to (x1 - x0 + w - 1) div w - 1 do
425 rotate_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0, angle);
427 set_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
429 //rect(sdl2allegro_screen, offx + x0, offy + y0, offx + x1, offy + y1, makecol(255, 0, 0));
430 //rect(sdl2allegro_screen, offx + oldx0, offy + oldy0, offx + oldx1, offy + oldx1, makecol(0, 255, 0));
431 end
432 end
433 else if Length(cmds.c) <> 0 then
434 begin
435 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
436 for i := 0 to Length(cmds.v) div 8 - 1 do
437 begin
438 SetupBlendColor(cmds.c[i * 4]);
439 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])
440 end
441 end
442 else
443 begin
444 SetupBlendColor(ccol);
445 for i := 0 to Length(cmds.v) div 8 - 1 do
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], ccol)
447 end
448 end;
449 else
450 assert(false)
451 end;
453 SetLength(cmds.v, 0);
454 SetLength(cmds.c, 0);
455 SetLength(cmds.t, 0);
456 cmds.mode := GL_INVALID_ENUM;
457 end;
459 procedure glVertex2f(x, y: GLfloat);
460 begin
461 Addi(cmds.v, ceil(x));
462 Addi(cmds.v, ceil(y))
463 end;
465 procedure glVertex2i(x, y: GLint);
466 begin
467 Addi(cmds.v, x);
468 Addi(cmds.v, y)
469 end;
471 procedure glColor4f(red, green, blue, alpha: GLfloat);
472 begin
473 ccol := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255));
474 Addi(cmds.c, ccol)
475 end;
477 procedure glColor4ub(red, green, blue, alpha: GLubyte);
478 begin
479 ccol := makeacol(red, green, blue, alpha);
480 Addi(cmds.c, ccol)
481 end;
483 procedure glColor3ub(red, green, blue: GLubyte);
484 begin
485 ccol := makecol(red, green, blue);
486 Addi(cmds.c, ccol)
487 end;
489 procedure glTexCoord2f(s, t: GLfloat);
490 begin
491 Addf(cmds.t, s);
492 Addf(cmds.t, t);
493 end;
495 procedure glTexCoord2i(s, t: GLint);
496 begin
497 Addf(cmds.t, s);
498 Addf(cmds.t, t);
499 end;
501 procedure glReadPixels(x, y: GLint; width, height: GLsizei; format, atype: GLenum; pixels: Pointer);
502 begin
503 end;
505 procedure glLoadIdentity;
506 begin
507 if matrixMode <> GL_MODELVIEW then Exit;
508 with stack[stack_ptr] do
509 begin
510 x := 0;
511 y := 0;
512 (* TODO Rotation and scale *)
513 end
514 end;
516 procedure glMatrixMode(mode: GLenum);
517 begin
518 (* GL_PROJECTION -> verify or ignore *)
519 (* GL_MODELVIEW -> apply *)
520 ASSERT((mode = GL_PROJECTION) or (mode = GL_MODELVIEW));
521 matrixMode := mode;
522 end;
524 procedure glLoadMatrixd(const m: PGLdouble);
525 begin
526 if matrixMode <> GL_MODELVIEW then Exit;
528 (*
529 e_LogWritefln('glLoadMatrix:', []);
530 e_LogWritefln('| %s %s %s %s |', [m[0], m[1], m[2], m[3]]);
531 e_LogWritefln('| %s %s %s %s |', [m[4], m[5], m[6], m[7]]);
532 e_LogWritefln('| %s %s %s %s |', [m[8], m[9], m[10], m[11]]);
533 e_LogWritefln('| %s %s %s %s |', [m[12], m[13], m[14], m[15]]);
534 *)
535 with stack[stack_ptr] do
536 begin
537 x := Trunc(m[3]);
538 y := Trunc(m[7]);
539 ASSERT(m[11] = 0);
540 (* TODO Rotation and Scale *)
541 end
542 end;
544 procedure glPushMatrix;
545 begin
546 if matrixMode <> GL_MODELVIEW then Exit;
547 stack[stack_ptr + 1] := stack[stack_ptr];
548 INC(stack_ptr);
549 end;
551 procedure glPopMatrix;
552 begin
553 if matrixMode <> GL_MODELVIEW then Exit;
554 DEC(stack_ptr)
555 end;
557 procedure glTranslatef(x, y, z: GLfloat);
558 begin
559 if matrixMode <> GL_MODELVIEW then Exit;
560 ASSERT(z = 0); (* 3D not supported *)
561 stack[stack_ptr].x += Trunc(x);
562 stack[stack_ptr].y += Trunc(y);
563 end;
565 procedure glRotatef(angle, x, y, z: GLfloat);
566 begin
567 if matrixMode <> GL_MODELVIEW then Exit;
568 ASSERT(x = 0); (* 3D not supported *)
569 ASSERT(y = 0); (* 3D not supported *)
570 // angle 360deg == 256 with conversion to fixed point 16.16
571 stack[stack_ptr].a += floor(angle * z * 0.71111) * 65536
572 end;
574 procedure glScalef(x, y, z: GLfloat);
575 begin
576 if matrixMode <> GL_MODELVIEW then Exit;
577 (* 3D not supported, but z can be any *)
578 (* TODO Scale *)
579 end;
581 procedure glViewport(x, y: GLint; width, height: GLsizei);
582 begin
583 vpx := x; vpy := y;
584 set_clip_rect(sdl2allegro_screen, x, y, x + width, y + height);
585 end;
587 procedure glScissor(x, y: GLint; width, height: GLsizei);
588 begin
589 //set_clip_rect(sdl2allegro_screen, x, y, width, height)
590 end;
592 procedure glStencilMask(mask: GLuint);
593 begin
594 end;
596 procedure glStencilFunc(func: GLenum; ref: GLint; mask: GLuint);
597 begin
598 end;
600 procedure glStencilOp(fail, zfail, zpass: GLenum);
601 begin
602 end;
604 procedure glColorMask(red, green, blue, alpha: GLboolean);
605 begin
606 end;
608 procedure glBindTexture(target: GLenum; texture: GLuint);
609 begin
610 assert(target = GL_TEXTURE_2D);
611 ctex := texture;
612 end;
614 procedure glGenTextures(n: GLsizei; textures: PGLuint);
615 var i: Integer;
616 begin
617 for i := 0 to n - 1 do
618 textures[i] := AddTexture
619 end;
621 procedure glTexEnvi(target: GLenum; pname: GLenum; param: GLint);
622 begin
623 end;
625 procedure glTexParameterf(target: GLenum; pname: GLenum; param: GLfloat);
626 begin
627 end;
629 procedure glTexParameteri(target: GLenum; pname: GLenum; param: GLint);
630 begin
631 end;
633 procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer);
634 var i, j, adr: Integer; p: PByte; color, trans: cint;
635 begin
636 assert(target = GL_TEXTURE_2D);
637 assert(level = 0);
638 assert((internalformat = GL_RGBA) or (internalformat = GL_RGB));
639 assert((format = GL_RGBA) or (format = GL_RGB));
640 assert(border = 0);
641 assert(atype = GL_UNSIGNED_BYTE);
643 assert(ctex >= 0);
644 assert(ctex <= High(tex));
645 assert(tex[ctex].used);
647 if tex[ctex].bmp <> nil then
648 destroy_bitmap(tex[ctex].bmp);
649 tex[ctex].bmp := create_system_bitmap(width, height);
650 if tex[ctex].bmp = nil then
651 tex[ctex].bmp := create_bitmap(width, height);
652 assert(tex[ctex].bmp <> nil);
654 if pixels = nil then exit;
656 p := pixels;
657 if format = GL_RGBA then
658 begin
659 if DEFAULT_DEPTH <= 8 then
660 trans := 0
661 else
662 trans := makeacol(255, 0, 255, 0);
664 for j := 0 to height - 1 do
665 for i := 0 to width - 1 do
666 begin
667 adr := j * width * 4 + i * 4;
668 if p[adr + 3] = 0 then
669 color := trans
670 else
671 color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]);
672 putpixel(tex[ctex].bmp, i, j, color)
673 end
674 end
675 else
676 begin
677 for j := 0 to height - 1 do
678 for i := 0 to width - 1 do
679 begin
680 adr := j * width * 3 + i * 3;
681 putpixel(tex[ctex].bmp, i, j, makecol(p[adr], p[adr + 1], p[adr + 2]))
682 end
683 end
684 end;
686 procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer);
687 var i, j, adr: Integer; p: PByte; color, trans: Cint;
688 begin
689 assert(target = GL_TEXTURE_2D);
690 assert(level = 0);
691 assert((format = GL_RGBA) or (format = GL_RGB));
692 assert(atype = GL_UNSIGNED_BYTE);
694 assert(ctex >= 0);
695 assert(ctex <= High(tex));
696 assert(tex[ctex].used);
698 assert(xoffset = 0);
699 assert(yoffset = 0);
701 if pixels = nil then exit;
703 p := pixels;
704 if format = GL_RGBA then
705 begin
706 if DEFAULT_DEPTH <= 8 then
707 trans := 0
708 else
709 trans := makeacol(255, 0, 255, 0);
711 for j := 0 to height - 1 do
712 for i := 0 to width - 1 do
713 begin
714 adr := j * width * 4 + i * 4;
715 if p[adr + 3] = 0 then
716 color := trans
717 else
718 color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]);
719 putpixel(tex[ctex].bmp, i, j, color)
720 end
721 end
722 else
723 begin
724 for j := 0 to height - 1 do
725 for i := 0 to width - 1 do
726 begin
727 adr := j * width * 3 + i * 3;
728 putpixel(tex[ctex].bmp, i, j, makecol(p[adr], p[adr + 1], p[adr + 2]))
729 end
730 end
731 end;
733 procedure glDeleteTextures(n: GLsizei; const textures: PGLuint);
734 var i: Integer;
735 begin
736 for i := 0 to n - 1 do
737 RemoveTexture(textures[i])
738 end;
740 procedure nogl_Init;
741 begin
742 cmds.mode := GL_INVALID_ENUM;
743 create_trans_table(@globalTransTable, default_palette, 255, 255, 255, nil);
744 create_trans_table(@redTransTable, default_palette, 0, 255, 255, nil);
745 create_trans_table(@greenTransTable, default_palette, 255, 0, 255, nil);
746 create_trans_table(@blueTransTable, default_palette, 255, 255, 0, nil);
747 create_trans_table(@darkTransTable, default_palette, 191, 191, 191, nil);
748 create_trans_table(@lightTransTable, default_palette, 64, 64, 64, nil);
749 color_map := @globalTransTable;
750 end;
752 procedure nogl_Quit;
753 begin
754 end;
756 initialization