// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movl %ecx, %ebp
movl %edx, %r15d
cvtsd2ss 0x133ba1(%rip), %xmm0   # 0x15b850
movq %rsi, %rbx
cvtsd2ss 0x133b9e(%rip), %xmm1   # 0x15b858
movq %rdi, %r14
cvtsd2ss 0x133b9b(%rip), %xmm2   # 0x15b860
movss 0xc63f3(%rip), %xmm3    # 0xee0c0
callq 0x22e10
movl $0x4100, %edi           # imm = 0x4100
callq 0x221d0
cmpl $0x9, %r15d
je 0x27d1a
movl $0xb50, %edi            # imm = 0xB50
cmpl $0x1, %r15d
jne 0x27db3
callq 0x227e0
movzbl 0x133ba3(%rip), %esi    # 0x15b8a0
movq %rbx, %rdi
movl $0x7, %edx
callq 0x2c00a
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
jmp 0x27dd4
movaps 0xc63af(%rip), %xmm0    # 0xee0d0
movaps %xmm0, 0x133bf8(%rip)   # 0x15b920
leaq 0x133bf1(%rip), %rsi    # 0x15b920
movl $0xb53, %edi            # imm = 0xB53
callq 0x231e0
movslq 0x44(%rbx), %rax
testq %rax, %rax
jle 0x27de9
shlq $0x3, %rax
leaq (%rax,%rax,2), %r12
movq %r12, %rdi
callq 0x22040
movq %rax, %r15
xorl %r13d, %r13d
leaq (%r15,%r13), %rdi
callq 0x99e58
addq $0x18, %r13
cmpq %r13, %r12
jne 0x27d5c
cmpl $0x0, 0x44(%rbx)
jle 0x27dec
movl %ebp, 0x4(%rsp)
xorl %ebp, %ebp
movq %r15, %r12
movq 0x38(%rbx), %rax
movq (%rax,%rbp,8), %r13
leaq 0x20(%r13), %rsi
movq %r12, %rdi
callq 0x99f0a
leaq 0x38(%r13), %rsi
movq %r13, %rdi
callq 0x4734c
incq %rbp
movslq 0x44(%rbx), %rax
addq $0x18, %r12
cmpq %rax, %rbp
jl 0x27d7d
movl 0x4(%rsp), %ebp
jmp 0x27dec
callq 0x221e0
movsd 0xc62b0(%rip), %xmm0    # 0xee070
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22e60
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movl %ebp, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2a23b
xorl %r15d, %r15d
movl $0x4000, %r12d          # imm = 0x4000
movl %r12d, %edi
callq 0x221e0
incl %r12d
cmpl $0x4008, %r12d          # imm = 0x4008
jne 0x27df2
movsd 0xc6262(%rip), %xmm0    # 0xee070
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
callq 0x22e60
movl $0xb50, %edi            # imm = 0xB50
callq 0x227e0
movq %r14, %rdi
movq %rbx, %rsi
movl $0x9, %edx
movl %ebp, %ecx
callq 0x2a23b
cmpb $0x0, 0x133a64(%rip)    # 0x15b8a0
je 0x27e48
movl $0x4000, %edi           # imm = 0x4000
callq 0x227e0
testq %r15, %r15
je 0x27e8f
cmpl $0x0, 0x44(%rbx)
jle 0x27e79
xorl %r12d, %r12d
movq %r15, %r14
movq 0x38(%rbx), %rax
movq (%rax,%r12,8), %rdi
movq %r14, %rsi
callq 0x4734c
incq %r12
movslq 0x44(%rbx), %rax
addq $0x18, %r14
cmpq %rax, %r12
jl 0x27e59
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22c10
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x23280
movq %rbx, %rdi
callq 0x230b0