]> gitweb.factorcode.org Git - factor.git/blob - extra/rosetta-code/opengl/opengl.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / extra / rosetta-code / opengl / opengl.factor
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
4 ui.gadgets ui.render ;
5 IN: rosetta-code.opengl
6
7 ! http://rosettacode.org/wiki/OpenGL
8
9 ! In this task, the goal is to display a smooth shaded triangle
10 ! with OpenGL.
11
12 TUPLE: triangle-gadget < gadget ;
13
14 : reshape ( width height -- )
15     [ 0 0 ] 2dip glViewport
16     GL_PROJECTION glMatrixMode
17     glLoadIdentity
18     -30.0 30.0 -30.0 30.0 -30.0 30.0 glOrtho
19     GL_MODELVIEW glMatrixMode ;
20
21 : paint ( -- )
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
25     glLoadIdentity
26     -15.0 -15.0 0.0 glTranslatef
27     GL_TRIANGLES glBegin
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
31     glEnd
32     glFlush ;
33
34 M: triangle-gadget pref-dim* drop { 640 480 } ;
35 M: triangle-gadget draw-gadget*
36     rect-bounds nip first2 reshape paint ;
37
38 : triangle-window ( -- )
39    [ triangle-gadget new "Triangle" open-window ] with-ui ;
40
41 MAIN: triangle-window