1 ! Copyright (c) 2012 Anonymous
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.rectangles opengl.gl sequences ui
5 IN: rosetta-code.opengl
7 ! http://rosettacode.org/wiki/OpenGL
9 ! In this task, the goal is to display a smooth shaded triangle
12 TUPLE: triangle-gadget < gadget ;
14 : reshape ( width height -- )
15 [ 0 0 ] 2dip glViewport
16 GL_PROJECTION glMatrixMode
18 -30.0 30.0 -30.0 30.0 -30.0 30.0 glOrtho
19 GL_MODELVIEW glMatrixMode ;
22 0.3 0.3 0.3 0.0 glClearColor
23 GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
24 GL_SMOOTH glShadeModel
26 -15.0 -15.0 0.0 glTranslatef
28 1.0 0.0 0.0 glColor3f 0.0 0.0 glVertex2f
29 0.0 1.0 0.0 glColor3f 30.0 0.0 glVertex2f
30 0.0 0.0 1.0 glColor3f 0.0 30.0 glVertex2f
34 M: triangle-gadget pref-dim* drop { 640 480 } ;
35 M: triangle-gadget draw-gadget*
36 rect-bounds nip first2 reshape paint ;
38 : triangle-window ( -- )
39 [ triangle-gadget new "Triangle" open-window ] with-ui ;