// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/scn2img/scn2img.cpp
// Function: DrawSceneWithOpenGL(gaps::R3Camera const&, gaps::R3Scene*, int, int)
static int
DrawSceneWithOpenGL(const R3Camera& camera, R3Scene *scene, int color_scheme, RNBoolean omit_objects = FALSE)
{
  // Clear window
  glClearColor(background.R(), background.G(), background.B(), 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Check color scheme
  if (color_scheme == RGB_COLOR_SCHEME) {
    // Draw scene
    glEnable(GL_LIGHTING);
    scene->LoadLights(headlight);
    DrawRootWithOpenGL(camera, scene, color_scheme, omit_objects);
  }
  else if (color_scheme == ALBEDO_COLOR_SCHEME) {
    // Load ambient light
    static GLfloat ambient[4];
    ambient[0] = 1;
    ambient[1] = 1;
    ambient[2] = 1;
    ambient[3] = 1;
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);

    // Copy diffuse reflections into ambient reflections
    RNRgb *saved_ambients = NULL;
    if (scene->NBrdfs() > 0) {
      saved_ambients = new RNRgb [ scene->NBrdfs() ];
      for (int i = 0; i < scene->NBrdfs(); i++) {
        R3Brdf *brdf = scene->Brdf(i);
        saved_ambients[i] = brdf->Ambient();
        brdf->SetAmbient(brdf->Diffuse());
      }
    }

    // Disable lights
    for (int i = 0; i < 8; i++) {
      glDisable(GL_LIGHT0 + i);
    }

    // Draw scene with only ambient light
    RNLoadRgb(1.0, 1.0, 1.0);
    glEnable(GL_LIGHTING);
    DrawRootWithOpenGL(camera, scene, color_scheme, omit_objects);

    // Restore lights
    if (headlight) {
      glEnable(GL_LIGHT0);
    }

    // Restore ambient reflections
    if (saved_ambients) {
      for (int i = 0; i < scene->NBrdfs(); i++) {
        R3Brdf *brdf = scene->Brdf(i);
        brdf->SetAmbient(saved_ambients[i]);
      }
      delete [] saved_ambients;
    }
  }
  else {
    // Draw scene
    glDisable(GL_LIGHTING);
    RNLoadRgb(1.0, 1.0, 1.0);
    DrawRootWithOpenGL(camera, scene, color_scheme, omit_objects);
  }

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r12d
movl %edx, %r15d
cvtsd2ss 0x121881(%rip), %xmm0   # 0x148860
movq %rsi, %rbx
cvtsd2ss 0x12187e(%rip), %xmm1   # 0x148868
movq %rdi, %r14
cvtsd2ss 0x12187b(%rip), %xmm2   # 0x148870
movss 0xae0c3(%rip), %xmm3    # 0xd50c0
callq 0x22e20
movl $0x4100, %edi           # imm = 0x4100
callq 0x221f0
cmpl $0x9, %r15d
je 0x27046
movl $0xb50, %edi            # imm = 0xB50
cmpl $0x1, %r15d
jne 0x270da
callq 0x227f0
movzbl 0x121883(%rip), %esi    # 0x1488b0
pushq $0x7
popq %rdx
movq %rbx, %rdi
callq 0x2ab32
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
jmp 0x270fb
movaps 0xae083(%rip), %xmm0    # 0xd50d0
movaps %xmm0, 0x1218dc(%rip)   # 0x148930
leaq 0x1218d5(%rip), %rsi    # 0x148930
movl $0xb53, %edi            # imm = 0xB53
callq 0x231f0
movslq 0x44(%rbx), %rax
xorl %ebp, %ebp
testq %rax, %rax
movq %r14, 0x10(%rsp)
jle 0x27118
movl %r12d, 0xc(%rsp)
imulq $0x18, %rax, %r12
movq %r12, %rdi
callq 0x22040
movq %rax, %r15
xorl %r14d, %r14d
leaq (%r15,%r14), %rdi
callq 0x8c36a
addq $0x18, %r14
cmpq %r14, %r12
jne 0x27090
xorl %r14d, %r14d
movq %r15, %r12
movslq 0x44(%rbx), %rax
cmpq %rax, %r14
jge 0x27111
movq 0x38(%rbx), %rax
movq (%rax,%r14,8), %r13
leaq 0x20(%r13), %rsi
movq %r12, %rdi
callq 0x8c41a
leaq 0x38(%r13), %rsi
movq %r13, %rdi
callq 0x41dc2
incq %r14
addq $0x18, %r12
jmp 0x270a8
callq 0x22200
movsd 0xadf89(%rip), %xmm0    # 0xd5070
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22e70
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movl %r12d, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x292c5
movl 0xc(%rsp), %r12d
jmp 0x2711b
xorl %r15d, %r15d
pushq $0x8
popq %r14
subl $0x1, %r14d
jb 0x27136
movl %ebp, %edi
orl $0x4000, %edi           # imm = 0x4000
callq 0x22200
incl %ebp
jmp 0x2711f
movsd 0xadf32(%rip), %xmm0    # 0xd5070
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22e70
movl $0xb50, %edi            # imm = 0xB50
callq 0x227f0
pushq $0x9
popq %rdx
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movl %r12d, %ecx
callq 0x292c5
cmpb $0x0, 0x121743(%rip)    # 0x1488b0
je 0x27179
movl $0x4000, %edi           # imm = 0x4000
callq 0x227f0
testq %r15, %r15
je 0x271bc
xorl %r12d, %r12d
movq %r15, %r14
movslq 0x44(%rbx), %rax
cmpq %rax, %r12
jge 0x271a6
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rdi
movq %r14, %rsi
callq 0x41dc2
incq %r12
addq $0x18, %r14
jmp 0x27184
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22c00
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x232a0
movq %rbx, %rdi
callq 0x230c0