// File: tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: DrawImageBillboard(ImageData*, gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&, gaps::R3Vector const&, double, double, double)
static void
DrawImageBillboard(ImageData *data, const R3Point& viewpoint,
  const R3Vector& towards, const R3Vector& right, const R3Vector& up,
  RNAngle xfov, RNAngle yfov, RNLength image_billboard_depth)
{
  // Check if drawing image billboards
  if (!show_image_billboards) return;

  // Load texture
  LoadTexture(data);
  if (data->texture_id == 0) return;

  // Enable texture
  glBindTexture(GL_TEXTURE_2D, data->texture_id);
  glEnable(GL_TEXTURE_2D);

  // Draw textured polygon
  R3Point origin = viewpoint + towards * image_billboard_depth;
  R3Vector dx = right * image_billboard_depth * tan(xfov);
  R3Vector dy = up * image_billboard_depth * tan(yfov);
  R3Point ur = origin + dx + dy;
  R3Point lr = origin + dx - dy;
  R3Point ul = origin - dx + dy;
  R3Point ll = origin - dx - dy;
  RNLoadRgb(1, 1, 1);
  RNGrfxBegin(RN_GRFX_POLYGON);
  R3LoadTextureCoords(0,0);
  R3LoadPoint(ll);
  R3LoadTextureCoords(1,0);
  R3LoadPoint(lr);
  R3LoadTextureCoords(1, 1);
  R3LoadPoint(ur);
  R3LoadTextureCoords(0,1);
  R3LoadPoint(ul);
  RNGrfxEnd();
  
  // Disable texture
  glDisable(GL_TEXTURE_2D);
}

// Assembly:
subq $0x198, %rsp            # imm = 0x198
movq %rdi, 0x190(%rsp)
movq %rsi, 0x188(%rsp)
movq %rdx, 0x180(%rsp)
movq %rcx, 0x178(%rsp)
movq %r8, 0x170(%rsp)
movsd %xmm0, 0x168(%rsp)
movsd %xmm1, 0x160(%rsp)
movsd %xmm2, 0x158(%rsp)
cmpl $0x0, 0x2c9e3f(%rip)    # 0x2feef0
jne 0x350b8
jmp 0x35314
movq 0x190(%rsp), %rdi
callq 0x36360
movq 0x190(%rsp), %rax
cmpl $0x0, 0x770(%rax)
jne 0x350db
jmp 0x35314
movq 0x190(%rsp), %rax
movl 0x770(%rax), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq 0x2a4b0
movl $0xde1, %edi            # imm = 0xDE1
callq 0x29a50
movq 0x188(%rsp), %rax
movq %rax, (%rsp)
movq 0x180(%rsp), %rsi
movsd 0x158(%rsp), %xmm0
leaq 0x128(%rsp), %rdi
callq 0x181dc0
movq (%rsp), %rsi
leaq 0x140(%rsp), %rdi
leaq 0x128(%rsp), %rdx
callq 0x180350
movq 0x178(%rsp), %rsi
movsd 0x158(%rsp), %xmm0
leaq 0xf8(%rsp), %rdi
callq 0x181dc0
movsd 0x168(%rsp), %xmm0
callq 0x299c0
leaq 0x110(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x181dc0
movq 0x170(%rsp), %rsi
movsd 0x158(%rsp), %xmm0
leaq 0xc8(%rsp), %rdi
callq 0x181dc0
movsd 0x160(%rsp), %xmm0
callq 0x299c0
leaq 0xe0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x181dc0
leaq 0x98(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x180350
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x180350
leaq 0x68(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x180350
leaq 0x80(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x180cf0
leaq 0x38(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x180cf0
leaq 0x50(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x180350
leaq 0x8(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x180cf0
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x180cf0
movl $0x1, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x39820
movl $0x9, %edi
callq 0x38d90
xorl %esi, %esi
movl %esi, %edi
callq 0x39cc0
leaq 0x20(%rsp), %rdi
callq 0x38e20
movl $0x1, %edi
xorl %esi, %esi
callq 0x39cc0
leaq 0x80(%rsp), %rdi
callq 0x38e20
movl $0x1, %esi
movl %esi, %edi
callq 0x39cc0
leaq 0xb0(%rsp), %rdi
callq 0x38e20
xorl %edi, %edi
movl $0x1, %esi
callq 0x39cc0
leaq 0x50(%rsp), %rdi
callq 0x38e20
callq 0x38e40
movl $0xde1, %edi            # imm = 0xDE1
callq 0x2a130
addq $0x198, %rsp            # imm = 0x198
retq
nopl (%rax)