Results 1 to 2 of 2

Thread: OpenGl and Ada

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011

    OpenGl and Ada

    I'm trying to run some example program which I found and it's not mine but there's the same problem that I have with my own program.
    Here's the code:
    -- GlutMain.adb
    with Interfaces.C.Strings;
    with Win32.Gl; use Win32.Gl;
    with Win32.Glu; use Win32.Glu;
    with win32.GLUT; use win32.GLUT;

    procedure GlutMain is
    package ICS renames Interfaces.C.Strings;

    use type Interfaces.C.unsigned;

    type chars_ptr_ptr is access ICS.chars_ptr;

    angle : GLFloat := 0.0;

    procedure Display;
    pragma Convention (C, Display);

    procedure Display is
    -- wyczysc bufor coloru i bufor glebokosci
    -- resetuj macierz widoku

    -- przeksztalc macierz
    glRotatef( angle, 0.0, 0.0, 1.0 );

    -- rozpocznij tryb renderowania
    -- prymitywem: pasy trojkatow
    glBegin( GL_TRIANGLE_STRIP );
    -- ustaw kolor pierwszego wierzcholka
    glColor3f( 1.0, 0.0, 0.0 );
    -- ustaw wspolrzedne wierzcholka
    glVertex3f( -0.6, 0.6, -2.0 );
    -- i podobnie dla pozostalych wierzcholkow:
    glColor3f( 0.0, 1.0, 0.0 );
    glVertex3f( -0.6, -0.6, -2.0 );
    glColor3f( 1.0, 0.0, 1.0 );
    glVertex3f( 0.6, 0.6, -2.0 );
    glColor3f( 0.0, 0.0, 1.0 );
    glVertex3f( 0.6, -0.6, -2.0 );

    -- zwieksz kat obrotu
    angle := angle + 0.02;

    end Display;

    -- importuj wartosci 'argc'
    argc : aliased integer;
    pragma Import (C, argc, "gnat_argc");

    -- importuj wartosci 'argv'
    argv : chars_ptr_ptr;
    pragma Import (C, argv, "gnat_argv");

    -- uchwyt okna GLUT
    win : Integer;

    -- Stworz okno, i ustaw tryb graficzny
    glutInit( argc'Access, argv );
    glutInitDisplayMode( GLUT_RGBA or GLUT_DEPTH or GLUT_DOUBLE );
    glutInitWindowSize( 500, 500 );
    glutInitWindowPosition( 200, 400 );
    win := glutCreateWindow( "GlutMain" );

    -- ustaw macierze oraz obszar obcinania
    glViewport( 0, 0, 500, 500 );
    glMatrixMode( GL_PROJECTION );
    gluPerspective( 45.0, 1.0, 0.1, 100.0 );
    glMatrixMode( GL_MODELVIEW );

    -- procedura rysujaca klatke animacji
    glutDisplayFunc( Display'Unrestricted_Access );
    glutIdleFunc( Display'Unrestricted_Access );
    -- petla glowna
    end GlutMain;

    When I execute it there's a message: raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION
    I know that there is a problem with assignment to variable angle any value inside the Display procedure but I have no idea why it doesn't work.
    Thanks in adavnce.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Oct 2009

    Re: OpenGl and Ada

    I have no idea about ADA, but if I was you I'd use GNAT under linux or one of the many BSDs and then gdb. It shows exactly (in the backtrace), where the crash occurs. If you are a power user, you could also try to use GNAT and gdb under cygwin.

    Otherwise, your code is very basic and I don't see anything wrong with it. I am not certain you can simply point the idle func to your rendering func. I usually do it like this:


    in a separate idling function. Of course, that's C++. I strongly suggest you stop using ADA and move on to something more common, e.g. Python or just to plain C/C++. The more people use a language, the more help you will get with your problems and the easier they will be to debug.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean