# This program is based on the color.c program written by Naofumi.

from GUI import Window, application
from GUI.GL import GLView
from OpenGL.GL import glClearColor, glClear, glBegin, glColor3f, glVertex2i, glEnd, \
    GL_COLOR_BUFFER_BIT, GL_TRIANGLES
from TestInput import TestInput

class TriangleView(TestInput, GLView):

    def init_context(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        
    def render(self):
        glClear(GL_COLOR_BUFFER_BIT)
        glBegin(GL_TRIANGLES)
        glColor3f(1.0, 0.0, 0.0)
        glVertex2i(0, 1)
        glColor3f(0.0, 1.0, 0.0)
        glVertex2i(-1, -1)
        glColor3f(0.0, 0.0, 1.0)
        glVertex2i(1, -1)
        glEnd()

view = TriangleView(size = (200, 200))
win = Window(title = "GLView", size = (240, 240))
win.place(view, left = 20, top = 20, sticky = "nsew")
view.become_target()
win.show()

print """\
The GLView should be 20 pixels in from the edge of the window
on all sides, maintained when the window is resized."""

application().run()
