Author Topic: Texture drawing  (Read 34493 times)

0 Members and 2 Guests are viewing this topic.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #75 on: July 28, 2011, 06:31:46 pm »
I've just rewritten the routine, but it doesn't draw anything. Not a single pixel :( .
What am I doing wrong?
Spoiler For the code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TexQuad
;in: x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3, x4, y4, u4, v4
;out: textured quad is drawn to the buffer
TexQuad:
  ld a, (x1)
  ld b, a
  ld a, (x2)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (dx1), hl
  ld a, (x1)
  ld b, a
  ld a, (x3)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (dx2), hl
  ld a, (x2)
  ld b, a
  ld a, (x4)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (dx3), hl
  ld a, (x3)
  ld b, a
  ld a, (x4)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (dx4), hl
  ld a, (u1)
  ld b, a
  ld a, (u2)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (du1), hl
  ld a, (u1)
  ld b, a
  ld a, (u3)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (du2), hl
  ld a, (u2)
  ld b, a
  ld a, (u4)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (du3), hl
  ld a, (u3)
  ld b, a
  ld a, (u4)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (du4), hl
  ld a, (v1)
  ld b, a
  ld a, (v2)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (dv1), hl
  ld a, (v1)
  ld b, a
  ld a, (v3)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (dv2), hl
  ld a, (v2)
  ld b, a
  ld a, (v4)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (dv3), hl
  ld a, (v3)
  ld b, a
  ld a, (v4)
  sub b
  ld h, a
  ld l, 0
  push hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld d, a
  ld e, 0
  pop hl
  call divFP
  ld (dv4), hl
  ld a, (x1)
  ld h, a
  ld l, 0
  ld (tx1), hl
  ld (tx2), hl
  ld a, (u1)
  ld h, a
  ld l, 0
  ld (tu1), hl
  ld (tu2), hl
  ld a, (v1)
  ld h, a
  ld l, 0
  ld (tv1), hl
  ld (tv2), hl
  ld a, (y1)
  ld (ty), a

;TODO: plot first line

  ld a, (y1)
  inc a
  ld (ty), a

QuadDrawLoop1:
  ld hl, (tx1)
  ld de, (dx1)
  add hl, de
  ld (tx1), hl
  ld hl, (tu1)
  ld de, (du1)
  add hl, de
  ld (tu1), hl
  ld hl, (tv1)
  ld de, (dv1)
  add hl, de
  ld (tv1), hl
  ld hl, (tx2)
  ld de, (dx2)
  add hl, de
  ld (tx2), hl
  ld hl, (tu2)
  ld de, (du2)
  add hl, de
  ld (tu2), hl
  ld hl, (tv2)
  ld de, (dv2)
  add hl, de
  ld (tv2), hl

  ld hl, (tx1)
  ld (temp), hl      ;x = temp

QuadPlotLoop1:
  ld hl, (tx2)
  ld de, (tx1)
  subFP
  push hl
  ld hl, (temp)
  ld de, (tx1)
  subFP
  pop de
  call DivFP
  ld (temp2), hl   ;T = temp2
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tu1)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tu2)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3), a      ;u = temp3
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tv1)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tv2)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3+1), a      ;v = temp3+1
;Get the pixel at (u,v) from the texture
  ld   hl, (temp3+1)
  ld   h, 0

  ld   de, texture
  add   hl, de

  ld   a, (temp3)
  ld   b, a
  inc   b
  ld a, (hl)
shiftLoop1:
  rl   c
  djnz   shiftLoop1

  push af
  ld a, (ty)
  ld l, a
  ld de, (temp)
  ld a, d
  call GetPixel
  ld h, a
  pop af
  ld a, h
  jr c, setPixel1

ResPixel1:
  cpl
  and (hl)
  ld (hl), a
  jr EndPlot1

SetPixel1:
  or (hl)
  ld (hl), a

EndPlot1:
  ld hl, (temp)
  ld de, (tx2)
  inc h
  ld (temp), hl
  ld b, h
  ld a, d
  cp b
  jp nc, QuadPlotLoop1

  ld hl, ty
  inc (hl)
  ld a, (y2)
  cp (hl)
  jp nc, QuadDrawLoop1

QuadDrawLoop2:
  ld hl, (tx1)
  ld de, (dx3)
  add hl, de
  ld (tx1), hl
  ld hl, (tu1)
  ld de, (du3)
  add hl, de
  ld (tu1), hl
  ld hl, (tv1)
  ld de, (dv3)
  add hl, de
  ld (tv1), hl
  ld hl, (tx2)
  ld de, (dx2)
  add hl, de
  ld (tx2), hl
  ld hl, (tu2)
  ld de, (du2)
  add hl, de
  ld (tu2), hl
  ld hl, (tv2)
  ld de, (dv2)
  add hl, de
  ld (tv2), hl

  ld hl, (tx1)
  ld (temp), hl      ;x = temp

QuadPlotLoop2:
  ld hl, (tx2)
  ld de, (tx1)
  subFP
  push hl
  ld hl, (temp)
  ld de, (tx1)
  subFP
  pop de
  call DivFP
  ld (temp2), hl   ;T = temp2
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tu1)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tu2)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3), a      ;u = temp3
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tv1)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tv2)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3+1), a      ;v = temp3+1
;Get the pixel at (u,v) from the texture
  ld   hl, (temp3+1)
  ld   h, 0

  ld   de, texture
  add   hl, de

  ld   a, (temp3)
  ld   b, a
  inc   b
  ld a, (hl)
shiftLoop2:
  rl   c
  djnz   shiftLoop2

  push af
  ld a, (ty)
  ld l, a
  ld de, (temp)
  ld a, d
  call GetPixel
  ld h, a
  pop af
  ld a, h
  jr c, setPixel2

ResPixel2:
  cpl
  and (hl)
  ld (hl), a
  jr EndPlot2

SetPixel2:
  or (hl)
  ld (hl), a

EndPlot2:
  ld hl, (temp)
  ld de, (tx2)
  inc h
  ld (temp), hl
  ld b, h
  ld a, d
  cp b
  jp nc, QuadPlotLoop2

  ld hl, ty
  inc (hl)
  ld a, (y3)
  cp (hl)
  jp nc, QuadDrawLoop2

QuadDrawLoop3:
  ld hl, (tx1)
  ld de, (dx3)
  add hl, de
  ld (tx1), hl
  ld hl, (tu1)
  ld de, (du3)
  add hl, de
  ld (tu1), hl
  ld hl, (tv1)
  ld de, (dv3)
  add hl, de
  ld (tv1), hl
  ld hl, (tx2)
  ld de, (dx4)
  add hl, de
  ld (tx2), hl
  ld hl, (tu2)
  ld de, (du4)
  add hl, de
  ld (tu2), hl
  ld hl, (tv2)
  ld de, (dv4)
  add hl, de
  ld (tv2), hl

  ld hl, (tx1)
  ld (temp), hl      ;x = temp

QuadPlotLoop3:
  ld hl, (tx2)
  ld de, (tx1)
  subFP
  push hl
  ld hl, (temp)
  ld de, (tx1)
  subFP
  pop de
  call DivFP
  ld (temp2), hl   ;T = temp2
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tu1)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tu2)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3), a      ;u = temp3
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tv1)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tv2)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3+1), a      ;v = temp3+1
;Get the pixel at (u,v) from the texture
  ld   hl, (temp3+1)
  ld   h, 0

  ld   de, texture
  add   hl, de

  ld   a, (temp3)
  ld   b, a
  inc   b
  ld a, (hl)
shiftLoop3:
  rl   c
  djnz   shiftLoop3

  push af
  ld a, (ty)
  ld l, a
  ld de, (temp)
  ld a, d
  call GetPixel
  ld h, a
  pop af
  ld a, h
  jr c, setPixel3

ResPixel3:
  cpl
  and (hl)
  ld (hl), a
  jr EndPlot3

SetPixel3:
  or (hl)
  ld (hl), a

EndPlot3:
  ld hl, (temp)
  ld de, (tx2)
  inc h
  ld (temp), hl
  ld b, h
  ld a, d
  cp b
  jp nc, QuadPlotLoop3

  ld hl, ty
  inc (hl)
  ld a, (y2)
  cp (hl)
  jp nc, QuadDrawLoop3

  ret



getPixel:
   ld   h, 0
   ld   d, h
   ld   e, l
   
   add   hl, hl
   add   hl, de
   add   hl, hl
   add   hl, hl
   
   ld   e, a
   srl   e
   srl   e
   srl   e
   add   hl, de
   
   ld   de, PlotSScreen
   add   hl, de
   
   and   7
   ld   b, a
   ld   a, $80
   ret   z
   
   rrca
   djnz   $-1
   ret

Generated by the BBCode Converter (http://clrhome.co.cc/resources/bbify/)

EDIT: the code is now syntax highlighted to make it more readable.
« Last Edit: July 29, 2011, 06:54:55 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #76 on: August 04, 2011, 03:50:22 pm »
I've got goo news and bad news: the good news: I've got affine texture mapping to work on a computer. The bad news: I can't get it to work on a calc.
what am I doing wrong?
Computer
Calculator
Everything works just the way it's supposed to.In the first step (TriangleDrawLoop1), it just draws black pixels,
and in the secound draw loop, nothing is drawn.
Spoiler For GML source code:
dx1 = (x2-x1)/(y2-y1)
dx2 = (x3-x2)/(y3-y2)
dx3 = (x3-x1)/(y3-y1)
du1 = (u2-u1)/(y2-y1)
du2 = (u3-u2)/(y3-y2)
du3 = (u3-u1)/(y3-y1)
dv1 = (v2-v1)/(y2-y1)
dv2 = (v3-v2)/(y3-y2)
dv3 = (v3-v1)/(y3-y1)

tx1 = x1
tx2 = x1
tu1 = u1
tu2 = u1
tv1 = v1
tv2 = v1

surf = surface_create(24,24)
surface_set_target(surf)
draw_sprite(sprite0,-1,0,0)
surface_reset_target();

for(ty = y1; ty < y2; ty += 1){
    //draw_line(tx1,ty,tx2,ty)
    for(tx = tx2; tx <= tx1; tx += 1){
        if(tx1==tx2){
            tmp = 0
        }else{
            tmp = (tx - tx2)/(tx1-tx2)
        }
        draw_point_color(tx,ty,surface_getpixel(surf,floor((1-tmp)*tu2+tmp*tu1),floor((1-tmp)*tv2+tmp*tv1)))
    }
    tx1 += dx1
    tx2 += dx3
    tu1 += du1
    tu2 += du3
    tv1 += dv1
    tv2 += dv3
}


for(ty = y2; ty <= y3; ty += 1){
    //draw_line(tx1,ty,tx2,ty)
    for(tx = tx2; tx <= tx1; tx += 1){
        if(tx1==tx2){
            tmp = 0
        }else{
            tmp = (tx - tx2)/(tx1-tx2)
        }
        draw_point_color(tx,ty,surface_getpixel(surf,floor((1-tmp)*tu2+tmp*tu1),floor((1-tmp)*tv2+tmp*tv1)))
    }
    tx1 += dx2
    tx2 += dx3
    tu1 += du2
    tu2 += du3
    tv1 += dv2
    tv2 += dv3
}
draw_surface_stretched(surf,300,0,100,100)
surface_free(surf)

A surface is almost the same as a sprite.
Spoiler For z80 source:
DrawTriangle:
  ld a, (x1)
  ld b, a
  ld a, (x2)
  sub b
  ld h, a
  ld l, 0
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (dx1), hl
  ld a, (x2)
  ld b, a
  ld a, (x3)
  sub b
  ld h, a
  ld l, 0
  ld a, (y2)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (dx2), hl
  ld a, (x1)
  ld b, a
  ld a, (x3)
  sub b
  ld h, a
  ld l, 0
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (dx3), hl
  ld a, (u1)
  ld b, a
  ld a, (u2)
  sub b
  ld h, a
  ld l, 0
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (du1), hl
  ld a, (u2)
  ld b, a
  ld a, (u3)
  sub b
  ld h, a
  ld l, 0
  ld a, (y2)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (du2), hl
  ld a, (u1)
  ld b, a
  ld a, (u3)
  sub b
  ld h, a
  ld l, 0
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (du3), hl
  ld a, (v1)
  ld b, a
  ld a, (v2)
  sub b
  ld h, a
  ld l, 0
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (dv1), hl
  ld a, (v2)
  ld b, a
  ld a, (v3)
  sub b
  ld h, a
  ld l, 0
  ld a, (y2)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (dv2), hl
  ld a, (v1)
  ld b, a
  ld a, (v3)
  sub b
  ld h, a
  ld l, 0
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld d, a
  ld e, 0
  call DivFP
  ld (dv3), hl

  ld a, (x1)
  ld h, a
  ld l, 0
  ld (tx1), hl
  ld (tx2), hl
  ld a, (u1)
  ld h, a
  ld l, 0
  ld (tu1), hl
  ld (tu2), hl
  ld a, (v1)
  ld h, a
  ld l, 0
  ld (tv1), hl
  ld (tv2), hl

  ld a, (y1)
  ld (_ty), a

TriangleDrawLoop1:
  ld hl, (tx2)
  ld a, h
  ld (temp), a

TrianglePlotLoop1:
  ld hl, (tx1)
  ld de, (tx2)
  subFP
  push hl
  ld a, (temp)
  ld h, a
  ld l, 0
  ld de, (tx2)
  subFP
  pop de
  call DivFP
  ld (temp2), hl   ;tmp = temp2
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tu2)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tu1)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3), a      ;u = temp3
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tv2)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tv1)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3+1), a   ;v = temp3+1

  ld a, (temp3+1)
  ld l, a
  ld h, 0

  ld de, texture
  add hl, de

  ld a, (temp3)
  ld b, a
  inc b
  ld a, (hl)
  ld c, a
TshiftLoop1:
  rl   c
  djnz   TshiftLoop1

  push af
 
  ld a, (_ty)
  ld l, a
  ld a, (temp)      ;tx = temp
  call GetPixel
  ld b, a
  pop af
  jr c, TSetPixel1

TResPixel1:
  ld a, b
  cpl
  and (hl)
  ld (hl), a
  jr TEndPlot1

TSetPixel1:
  ld a, b
  or (hl)
  ld (hl), a

TEndPlot1:
  ld hl, temp
  inc (hl)
  ld a, (tx1+1)
  cp (hl)
  jp nc, TrianglePlotLoop1

  ld hl, (tx1)
  ld de, (dx1)
  add hl, de
  ld (tx1), hl
  ld hl, (tx2)
  ld de, (dx3)
  add hl, de
  ld (tx2), hl

  ld hl, _ty
  inc (hl)
  ld a, (y2)
  cp (hl)
  jp nc, TriangleDrawLoop1

  ld a, (x2)
  ld h, a
  ld l, 0
  ld (tx1), hl

TriangleDrawLoop2:
  ld hl, (tx2)
  ld a, h
  ld (temp), a

TrianglePlotLoop2:
  ld hl, (tx1)
  ld de, (tx2)
  subFP
  push hl
  ld a, (temp)
  ld h, a
  ld l, 0
  ld de, (tx2)
  subFP
  pop de
  call DivFP
  ld (temp2), hl   ;tmp = temp2
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tu2)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tu1)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3), a      ;u = temp3
  ld hl, $0100
  ld de, (temp2)
  subFP
  ld bc, (tv2)
  call MulFP
  push de
  ld hl, (temp2)
  ld bc, (tv1)
  call MulFP
  pop hl
  add hl, de
  ld a, h
  ld (temp3+1), a   ;v = temp3+1

  ld a, (temp3+1)
  ld l, a
  ld h, 0

  ld de, texture
  add hl, de

  ld a, (temp3)
  ld b, a
  inc b
  ld a, (hl)
  ld c, a
TshiftLoop2:
  rl   c
  djnz   TshiftLoop2

  push af
 
  ld a, (_ty)
  ld l, a
  ld a, (temp)      ;tx = temp
  call GetPixel
  ld b, a
  pop af
  jr c, TSetPixel2

TResPixel2:
  ld a, b
  cpl
  and (hl)
  ld (hl), a
  jr TEndPlot2

TSetPixel2:
  ld a, b
  or (hl)
  ld (hl), a

TEndPlot2:
  ld hl, temp
  inc (hl)
  ld a, (tx1+1)
  cp (hl)
  jp nc, TrianglePlotLoop2

  ld hl, (tx1)
  ld de, (dx2)
  add hl, de
  ld (tx1), hl
  ld hl, (tx2)
  ld de, (dx3)
  add hl, de
  ld (tx2), hl

  ld hl, _ty
  inc (hl)
  ld a, (y2)
  cp (hl)
  jp nc, TriangleDrawLoop2

  ret



getPixel:
   ld   h, 0
   ld   d, h
   ld   e, l
   
   add   hl, hl
   add   hl, de
   add   hl, hl
   add   hl, hl
   
   ld   e, a
   srl   e
   srl   e
   srl   e
   add   hl, de
   
   ld   de, PlotSScreen
   add   hl, de
   
   and   7
   ld   b, a
   ld   a, $80
   ret   z
   
   rrca
   djnz   $-1
   ret

Generated by the BBCode Converter (http://clrhome.tk/resources/bbify/)

What am i doing wrong?
« Last Edit: August 04, 2011, 04:32:49 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Texture drawing
« Reply #77 on: August 04, 2011, 09:54:12 pm »
did that basic to assembly source conversion thing work at all?
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #78 on: August 05, 2011, 02:28:11 pm »
did that basic to assembly source conversion thing work at all?
nope, I haven't found any program that actually converts anything, so I've ported it manually, but i must have made a mistake, ass this is clearly not doing what it should do.

BTW: this routine draws the triangle from top to bottom, which means that the points needs to be in the right order, so does anybody knows a routine to sort the points based on their Y coordinate?
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Texture drawing
« Reply #79 on: August 06, 2011, 08:49:00 am »
BTW: this routine draws the triangle from top to bottom, which means that the points needs to be in the right order, so does anybody knows a routine to sort the points based on their Y coordinate?
I made a routine thst would work for this in Cube Droid, but that's in Axe so I guess it doesn't help.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #80 on: August 06, 2011, 03:05:29 pm »
Maybe it does help. If i know how it should be done, then i might be able to rewrite it in asm. And i need a good sorting algorithm for when i'm going to add z-ordering to the engine.

EDIT: I just found a mistake in my code, and now, the triangle is fully drawn, but still just solid black.

EDIT2: I just noticed an other mistake in the source, which made texture mapping impossible. This was not the full cause of the texture not being mapped, however, ass the routine is still drawing a solid black triangle.

EDIT3: Finally!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


the third mistake was caused by a very stupid mistake: I have a text file in the project folder named 'Routines.txt', in which all names of all routines in my app are written, with the arguments and the registers that they destroy. A while ago, i replaced the fixed-point multiplication routine, which had other arguments, so this problem was caused by an outdated routines file

EDIT4: it now draws only 1.29 triangles every second, but I'm optimizing it right now. The first thing I'll do is replace the fixed-point math for every pixel with a much simpler one, which only has to be calculated for each horizontal line. The rest of the line can then be calculated with a simple add command. An other optimization I'll try to add is calling getPixel only once for every scan line, instead of every pixel, then using a right rotation to get the mask.
« Last Edit: August 06, 2011, 07:17:05 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #81 on: August 08, 2011, 07:47:30 pm »
I discovered an other problem: when i combine it wih my 3D engine, this happens:

For an instant, it's drawn correctely, then only a part is drawn

Does anyody knows what might be causing this?
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Texture drawing
« Reply #82 on: August 09, 2011, 08:25:11 am »
It seems like if it first draws everything and then deletes the other parts again.

maybe the program draws everything the first tim, but only draws a part of it again, it you toggle the camera!
*insert supercool signature*

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #83 on: August 11, 2011, 02:17:09 pm »
The camera stays at the same position, and the arguments passed to the triangle drawing routine are always the same, so I wonder why it draws it correctly the first time, and only draws a part of it the other times.

BTW: by filling the graphic buffer every frame, I noticed that the rest of the triangle is drawn white, but it is still drawn.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline chattahippie

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +27/-0
  • Super Member! :D
    • View Profile
Re: Texture drawing
« Reply #84 on: August 11, 2011, 04:48:06 pm »
Although I know it isn't working correctly right now, this is amazing!
I would never have the patience to debug/ create as much as you have.
I hope you find the errors, it seems like you kinda know where the code freaks out.
« Last Edit: August 11, 2011, 04:48:28 pm by chattahippie »

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Texture drawing
« Reply #85 on: August 11, 2011, 06:17:38 pm »
Maybe there was something you forgot to reset - like a register that was zero the first time around but never got reset to zero in the second frame.

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #86 on: August 11, 2011, 06:38:26 pm »
This is the start and loop code: I don't think anything is set or reset:
the 3D engine is passing the same arguments to it, so i guess the trianlge drawing routine itself couses it, most lickely in the texture handling code 'couse it's the texture that got messed up
Code: [Select]
Start:
  di
  call ClearGbuf
  call fastCopy
  ld a, 64*3
  ld (direction), a
  in a,($02)
  rla
  sbc a, a
  out ($20), a

  ld hl, 0
  ld (x), hl
  ld hl, $0200
  ld (y), hl

SpelLus:
  call ClearGBuf

  ld a, $FF
  ld (plotsscreen), a
  ld hl, plotsscreen
  ld de, plotsscreen+1
  ld bc, 767
  ldir

  ld hl, (x)
  ld (xfrom), hl
  ld hl, (y)
  ld (yfrom), hl
  ld hl, 0
  ld (zfrom), hl
  ld (zto), hl
  ld a, 64
  ld b, a
  ld a, (direction)
  add a, b
  call SinA
  ld de, (x)
  add hl, de
  ld (xto), hl
  ld a, (direction)
  call SinA
  ld de, (y)
  add hl, de
  ld (yto), hl
  ld hl, $0100
  ld (zup), hl
  ld hl, 0
  ld (xup), hl
  ld (yup), hl
  call InitView

  ld hl, -256
  ld (xpoint), hl
  ld hl, 0
  ld (ypoint), hl
  ld hl, -$0100
  ld (zpoint), hl
  call C3DTo2D
  ld hl, (screenx)
  ld (screenx2), hl
  ld hl, (screeny)
  ld (screeny2), hl
  ld hl, 256
  ld (xpoint), hl
  ld hl, 0
  ld (ypoint), hl
  ld hl, -$0100
  ld (zpoint), hl
  call C3DTo2D
  ld hl, (screenx)
  ld (screenx3), hl
  ld hl, (screeny)
  ld (screeny3), hl
  ld hl, -256
  ld (xpoint), hl
  ld hl, 0
  ld (ypoint), hl
  ld hl, $0100
  ld (zpoint), hl
  call C3DTo2D

  ld a, (screenx)
  ld (x1), a
  ld a, (screeny)
  ld (y1), a
  ld a, 0
  ld (u1), a
  ld (v1), a
  ld a, (screenx2)
  ld (x2), a
  ld a, (screeny2)
  ld (y2), a
  ld a, 0
  ld (u2), a
  ld a, 8
  ld (v2), a
  ld a, (screenx3)
  ld (x3), a
  ld a, (screeny3)
  ld (y3), a
  ld a, 8
  ld (u1), a
  ld (v1), a

  call DrawTriangle

  call FastCopy
 
  ;knoppen
  ld a, $FE
  out (1), a
  in a, (1)
  bit 0, a
  call z, MoveBack
  bit 3, a
  call z, MoveForward
  bit 1, a
  call z, TurnLeft
  bit 2, a
  call z, TurnRight
  ld a, %11111101
  out ($01), a
  in a, ($01)
  bit 6, a
  jp z, Einde
  jp spelLus
 
MoveBack:
  push af
  ld a, (direction)
  ld b, 64
  add a, b
  call SinA
  call NegHL
  ld de, $0A00
  call DivFP
  ld de, (X)
  add hl, de
  ld (X), hl
  ld a, (direction)
  call SinA
  call NegHL
  ld de, $0A00
  call DivFP
  ld de, (Y)
  add hl, de
  ld (Y), hl
  pop af
  ret
MoveForward:
  push af
  ld a, (direction)
  ld b, 64
  add a, b
  call SinA
  ld de, $0A00
  call DivFP
  ld de, (X)
  add hl, de
  ld (X), hl
  ld a, (direction)
  call SinA
  ld de, $0A00
  call DivFP
  ld de, (Y)
  add hl, de
  ld (Y), hl
  pop af
  ret
TurnLeft:
  push af
  ld a, (direction)
  inc a
  ld (direction), a
  pop af
  ret
TurnRight:
  ld a, (direction)
  dec a
  ld (direction), a
  ret
 
Einde:
  ;Key port resetten
  ld a, $FF
  out ($01), a
  call ClearGbuf
  call fastCopy
  ld hl, 0
  ld (CurRow), hl
  EI
  bjump(_JForceCmdNoChar)
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #87 on: August 16, 2011, 05:04:00 pm »
I think I've solved all bugs.
here's a screenshot of my triangle drawing routine and 3D engine in action:

It now not only fully works, it's also way more optimised and now all of the fixed-point calculations only have to be done once every triangle instead of once every scan line (or every pixel in the first version).
« Last Edit: August 16, 2011, 05:07:26 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline zeldaking

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 197
  • Rating: +15/-0
    • View Profile
Re: Texture drawing
« Reply #88 on: August 16, 2011, 05:05:23 pm »
That looks very nice, good job. Is this for some other project?

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: Texture drawing
« Reply #89 on: August 16, 2011, 05:12:29 pm »
That looks very nice, though it looks like there is a "seam" between the two triangles you are drawing. Is that intentional?