#!parrot
# Copyright (C) 2009, Parrot Foundation.
# $Id$

=head1 NAME

t/library/opengl.t  -- OpenGL Tests

=head1 SYNOPSIS

  ./parrot t/library/opengl.t

=head1 DESCRIPTION

Test Parrot's opengl interface.

=cut

.const int TESTS = 7

.sub 'main' :main
    .param pmc argv
        
    load_bytecode 'library/Test/More.pbc'
    .local pmc exports, curr_namespace, test_namespace
    curr_namespace = get_namespace
    test_namespace = get_namespace [ 'Test'; 'More' ]
    exports        = split ' ', 'plan diag ok nok is is_deeply like isa_ok skip isnt todo'

    test_namespace.'export_to'(curr_namespace, exports)

    load_bytecode "library/config.pbc"
    .local pmc conf_hash
    conf_hash = _config()
    $S1 = conf_hash['has_opengl']
    if $S1 == '1' goto HAS_OPENGL
    skip(TESTS, "no opengl")
    goto END

HAS_OPENGL:
    plan(TESTS)

    .include 'opengl_defines.pasm'
    load_bytecode 'OpenGL.pbc'
    'ok'(1, 'loaded OpenGL.pbc')

    load_bytecode 'library/NCI/call_toolkit_init.pbc'
    'ok'(2, 'loaded call_toolkit_init.pbc')

    .local pmc import_gl
    import_gl = get_global ['OpenGL'], '_export_all_functions'
    import_gl()
    'ok'(3, '_export_all_functions')

    glutInitWindowSize(20, 20)
    'ok'(4, 'glutInitWindowSize')

    # Initialize GLUT
    .local pmc argc
    .local int count
    count = argv
    argc  = new 'Integer'
    argc  = count
    glutInit(argc, argv)
    'ok'(5, 'glutInit')
    
    # Set display mode, create GLUT window, return window handle
    .local int mode
    mode    = .GLUT_DOUBLE | .GLUT_RGBA
    mode   |= .GLUT_DEPTH
    mode   |= .GLUT_STENCIL
    glutInitDisplayMode(mode)
    'ok'(6, 'glutInitDisplayMode')

    .local int window_id
    window_id = glutCreateWindow('test')
    if window_id goto OK_7
    'nok'(7, 'glutCreateWindow')
    goto END
OK_7: 
    'ok'(7, 'glutCreateWindow')
    
END:
.end

# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
