

Task

Display a smooth shaded triangle with OpenGL.

 Triangle created using C example compiled with GCC 4.1.2 and freeglut3.


nomainwin
    struct rect, x as long, y as long, x2 as long, y2 as long
    struct PFD,   Size as word, Version as word, Flags as long,_
        PixelType as char[1], ColorBits as char[1], RedBits as char[1],_
        RedShift as char[1], GreenBits as char[1], GreenShift as char[1],_
        BlueBits as char[1], BlueShift as char[1], AlphaBits as char[1],_
        AlphaShift as char[1],AccumBits as char[1], AccumRedBits as char[1],_
        AccumGreenBits as char[1], AccumBlueBits as char[1], AccumAlphaBits as char[1],_
        DepthBits as char[1], StencilBits as char[1], AuxBuffers as char[1],_
        LayerType as char[1], Reserved as char[1], LayerMask as long,_
        VisibleMask as long, DamageMask as long
    PFD.Version.struct=1
    PFD.ColorBits.struct=24
    PFD.DepthBits.struct=16
    PFD.Size.struct=len(PFD.struct)
    PFD.Flags.struct=37
    GlColorBufferBit=16384
    open "opengl32.dll" for dll as #gl
    open "glu32.dll" for dll as #glu
    WindowWidth=500
    WindowHeight=500
    UpperLeftX=1
    UpperLeftY=1
    open "Triangle" for window_nf as #main
    print #main,"trapclose [quit]"
    MainH=hwnd(#main)
    calldll #user32,"GetDC", MainH as ulong, MainDC as ulong
    calldll #gdi32,"ChoosePixelFormat", MainDC as ulong, PFD as struct, ret as long
    calldll #gdi32, "SetPixelFormat", MainDC as ulong, ret as long, PFD as struct, t as long
    calldll #gl,"wglCreateContext", MainDC as ulong, GLContext as ulong
    calldll #gl,"wglMakeCurrent", MainDC as ulong, GLContext as ulong, ret as long
    calldll #gl,"glClear", GlColorBufferBit as long,  ret as long
    calldll #gl,"glRotated", 0 as double, 0 as double, 0 as double, 0 as double, ret as long
    calldll #gl,"glBegin", 4 as long, ret as long
    calldll #gl,"glColor3d", 0 as double, 0 as double, 255 as double, ret as long
    calldll #gl,"glVertex3i", -1 as long, -1 as long, 0 as long, ret as long
    calldll #gl,"glColor3d", 255 as double, 0 as double, 0 as double, ret as long
    calldll #gl,"glVertex3i", 0 as long, 1 as long, 0 as long, ret as long
    calldll #gl,"glColor3d", 0 as double, 255 as double, 0 as double, ret as long
    calldll #gl,"glVertex3i", 1 as long, -1 as long, 0 as long, ret as long
    calldll #gl,"glEnd", ret as void
    calldll #gdi32,"SwapBuffers", MainDC as ulong, ret as long
    wait
[quit]
    calldll #gl,"wglMakeCurrent", 0 as ulong, 0 as ulong, ret as long
    calldll #gl,"wglDeleteContext", GLContext as ulong, ret as long
    calldll #user32, "ReleaseDC", MainH as ulong, MainDC as ulong,ret as long
    close #main
    close #glu
    close #gl
    end