'
' This is the BaCon port of the 'Stroke' OpenGL program.
'
' See also: http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html
'
' Port by Peter van Eerten - January 2010.
'
' Copyright (c) Mark J. Kilgard, 1994.
'
' This program is freely distributable without licensing fees
' and is provided without guarantee or warrantee expressed or
' implied. This program is -not- in the public domain.
'
INCLUDE "gl.bac"
INCLUDE "glu.bac"
INCLUDE "glut.bac"

defaultMessage$ = "GLUT means OpenGL."
message$ = defaultMessage$

DECLARE fonts[1]
fonts[0] = GLUT_STROKE_ROMAN
fonts[1] = GLUT_STROKE_MONO_ROMAN

font = GLUT_STROKE_ROMAN

DECLARE angle TYPE int

SUB selectFont(int newfont)

    font = fonts[newfont]
    glutPostRedisplay

END SUB

SUB selectMessage(int msg)

    SELECT msg
        CASE 1
            message$ = "abcdefghijklmnop"
        CASE 2
            message$ = "ABCDEFGHIJKLMNOP"
    ENDSELECT
END SUB

SUB tick

  angle = angle - 2
  glutPostRedisplay

END SUB

SUB display

    LOCAL len, i TYPE int

    glClear(GL_COLOR_BUFFER_BIT)
    glPushMatrix
    glRotatef(angle, 0.0, 0.0, 1.0)
    glTranslatef(-750, 0, 0)
    len = (int) strlen(message$)
    FOR i = 1 TO len
        glutStrokeCharacter(font, ASC(MID$(message$, i)))
    NEXT

    glPopMatrix
    glutSwapBuffers

    SLEEP 10

END SUB

SUB mainprog

    LOCAL i, submenu TYPE int

    SPLIT ARGUMENT$ BY " " TO arg$ SIZE i
    IF i > 1 THEN
        IF NOT(EQUAL(arg$[1], "-mono")) THEN
            font = GLUT_STROKE_MONO_ROMAN
        ENDIF
    ENDIF
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
    glutInitWindowSize(600, 600)
    glutCreateWindow("anti-aliased stroke font")
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity
    gluOrtho2D(0, 2000, 0, 2000)
    glMatrixMode(GL_MODELVIEW)
    glEnable(GL_LINE_SMOOTH)
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    glLineWidth(3.0)
    glTranslatef(1000, 1000, 0)
    glClearColor(0.0, 0.0, 0.0, 1.0)
    glColor3f(1.0, 1.0, 1.0)
    glutDisplayFunc(ADDRESS(display))
    glutIdleFunc(ADDRESS(tick))
    submenu = glutCreateMenu(ADDRESS(selectMessage))
    glutAddMenuEntry("abc", 1)
    glutAddMenuEntry("ABC", 2)
    glutCreateMenu(ADDRESS(selectFont))
    glutAddMenuEntry("Roman", 0)
    glutAddMenuEntry("Mono Roman", 1)
    glutAddSubMenu("Messages", submenu)
    glutAttachMenu(GLUT_RIGHT_BUTTON)
    glutMainLoop

END SUB

mainprog