ruby-glfw 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +1 -0
- data/README.API +73 -0
- data/Rakefile +120 -0
- data/examples/boing.rb +519 -0
- data/examples/gears.rb +327 -0
- data/examples/keytest.rb +117 -0
- data/examples/listmodes.rb +20 -0
- data/examples/mipmaps.rb +104 -0
- data/examples/mipmaps.tga +0 -0
- data/examples/particles.rb +837 -0
- data/examples/pong3d.rb +741 -0
- data/examples/pong3d_field.tga +0 -0
- data/examples/pong3d_instr.tga +0 -0
- data/examples/pong3d_menu.tga +0 -0
- data/examples/pong3d_title.tga +0 -0
- data/examples/pong3d_winner1.tga +0 -0
- data/examples/pong3d_winner2.tga +0 -0
- data/examples/splitview.rb +432 -0
- data/examples/triangle.rb +89 -0
- data/examples/wave.rb +294 -0
- data/ext/glfw/glfw.c +1094 -0
- data/ext/glfw/mkrf_conf.rb +70 -0
- data/glfw-src/Makefile +220 -0
- data/glfw-src/compile.ami +61 -0
- data/glfw-src/compile.bat +217 -0
- data/glfw-src/compile.sh +607 -0
- data/glfw-src/docs/Makefile +57 -0
- data/glfw-src/docs/Reference.pdf +0 -0
- data/glfw-src/docs/UsersGuide.pdf +0 -0
- data/glfw-src/docs/cleanup.bat +22 -0
- data/glfw-src/docs/glfwdoc.sty +80 -0
- data/glfw-src/docs/glfwrm.tex +3034 -0
- data/glfw-src/docs/glfwug.tex +2024 -0
- data/glfw-src/docs/readme.txt +80 -0
- data/glfw-src/examples/Makefile.amigaos.gcc +70 -0
- data/glfw-src/examples/Makefile.amigaos.vbcc +70 -0
- data/glfw-src/examples/Makefile.dos.djgpp +71 -0
- data/glfw-src/examples/Makefile.macosx.gcc +96 -0
- data/glfw-src/examples/Makefile.win32.bcc +75 -0
- data/glfw-src/examples/Makefile.win32.cross-mgw +79 -0
- data/glfw-src/examples/Makefile.win32.cygwin +79 -0
- data/glfw-src/examples/Makefile.win32.lcc +74 -0
- data/glfw-src/examples/Makefile.win32.mgw +75 -0
- data/glfw-src/examples/Makefile.win32.msvc +74 -0
- data/glfw-src/examples/Makefile.win32.ow +74 -0
- data/glfw-src/examples/Makefile.win32.pellesc +74 -0
- data/glfw-src/examples/Makefile.x11.in +54 -0
- data/glfw-src/examples/boing.c +606 -0
- data/glfw-src/examples/bundle.sh +46 -0
- data/glfw-src/examples/gears.c +382 -0
- data/glfw-src/examples/keytest.c +264 -0
- data/glfw-src/examples/listmodes.c +48 -0
- data/glfw-src/examples/mipmaps.c +126 -0
- data/glfw-src/examples/mipmaps.tga +0 -0
- data/glfw-src/examples/mtbench.c +301 -0
- data/glfw-src/examples/mthello.c +48 -0
- data/glfw-src/examples/particles.c +1148 -0
- data/glfw-src/examples/pong3d.c +839 -0
- data/glfw-src/examples/pong3d_field.tga +0 -0
- data/glfw-src/examples/pong3d_instr.tga +0 -0
- data/glfw-src/examples/pong3d_menu.tga +0 -0
- data/glfw-src/examples/pong3d_title.tga +0 -0
- data/glfw-src/examples/pong3d_winner1.tga +0 -0
- data/glfw-src/examples/pong3d_winner2.tga +0 -0
- data/glfw-src/examples/splitview.c +506 -0
- data/glfw-src/examples/triangle.c +108 -0
- data/glfw-src/examples/wave.c +397 -0
- data/glfw-src/images/opengl.gif +0 -0
- data/glfw-src/images/osicert.gif +0 -0
- data/glfw-src/include/GL/glfw.h +486 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.gcc +128 -0
- data/glfw-src/lib/amigaos/Makefile.amigaos.vbcc +128 -0
- data/glfw-src/lib/amigaos/SDI_compiler.h +94 -0
- data/glfw-src/lib/amigaos/amigaos_enable.c +51 -0
- data/glfw-src/lib/amigaos/amigaos_fullscreen.c +319 -0
- data/glfw-src/lib/amigaos/amigaos_glext.c +61 -0
- data/glfw-src/lib/amigaos/amigaos_init.c +284 -0
- data/glfw-src/lib/amigaos/amigaos_joystick.c +359 -0
- data/glfw-src/lib/amigaos/amigaos_thread.c +494 -0
- data/glfw-src/lib/amigaos/amigaos_time.c +206 -0
- data/glfw-src/lib/amigaos/amigaos_window.c +830 -0
- data/glfw-src/lib/amigaos/platform.h +337 -0
- data/glfw-src/lib/dos/Makefile.dos.djgpp +146 -0
- data/glfw-src/lib/dos/dos_enable.c +51 -0
- data/glfw-src/lib/dos/dos_events.c +173 -0
- data/glfw-src/lib/dos/dos_fullscreen.c +101 -0
- data/glfw-src/lib/dos/dos_glext.c +59 -0
- data/glfw-src/lib/dos/dos_init.c +105 -0
- data/glfw-src/lib/dos/dos_irq.s +246 -0
- data/glfw-src/lib/dos/dos_joystick.c +94 -0
- data/glfw-src/lib/dos/dos_keyboard.c +694 -0
- data/glfw-src/lib/dos/dos_mouse.c +337 -0
- data/glfw-src/lib/dos/dos_thread.c +267 -0
- data/glfw-src/lib/dos/dos_time.c +309 -0
- data/glfw-src/lib/dos/dos_window.c +563 -0
- data/glfw-src/lib/dos/platform.h +341 -0
- data/glfw-src/lib/enable.c +295 -0
- data/glfw-src/lib/fullscreen.c +95 -0
- data/glfw-src/lib/glext.c +201 -0
- data/glfw-src/lib/image.c +629 -0
- data/glfw-src/lib/init.c +108 -0
- data/glfw-src/lib/input.c +280 -0
- data/glfw-src/lib/internal.h +210 -0
- data/glfw-src/lib/joystick.c +101 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc +172 -0
- data/glfw-src/lib/macosx/Makefile.macosx.gcc.universal +166 -0
- data/glfw-src/lib/macosx/libglfw.pc.in +11 -0
- data/glfw-src/lib/macosx/macosx_enable.c +42 -0
- data/glfw-src/lib/macosx/macosx_fullscreen.c +126 -0
- data/glfw-src/lib/macosx/macosx_glext.c +52 -0
- data/glfw-src/lib/macosx/macosx_init.c +194 -0
- data/glfw-src/lib/macosx/macosx_joystick.c +50 -0
- data/glfw-src/lib/macosx/macosx_thread.c +414 -0
- data/glfw-src/lib/macosx/macosx_time.c +112 -0
- data/glfw-src/lib/macosx/macosx_window.c +1279 -0
- data/glfw-src/lib/macosx/platform.h +349 -0
- data/glfw-src/lib/stream.c +194 -0
- data/glfw-src/lib/tga.c +405 -0
- data/glfw-src/lib/thread.c +340 -0
- data/glfw-src/lib/time.c +83 -0
- data/glfw-src/lib/win32/Makefile.win32.bcc +265 -0
- data/glfw-src/lib/win32/Makefile.win32.cross-mgw +274 -0
- data/glfw-src/lib/win32/Makefile.win32.cygwin +279 -0
- data/glfw-src/lib/win32/Makefile.win32.lcc +246 -0
- data/glfw-src/lib/win32/Makefile.win32.mgw +243 -0
- data/glfw-src/lib/win32/Makefile.win32.msvc +242 -0
- data/glfw-src/lib/win32/Makefile.win32.ow +242 -0
- data/glfw-src/lib/win32/Makefile.win32.pellesc +242 -0
- data/glfw-src/lib/win32/glfwdll.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw1.def +67 -0
- data/glfw-src/lib/win32/glfwdll_mgw2.def +67 -0
- data/glfw-src/lib/win32/glfwdll_pellesc.def +65 -0
- data/glfw-src/lib/win32/libglfw.pc.in +11 -0
- data/glfw-src/lib/win32/platform.h +474 -0
- data/glfw-src/lib/win32/win32_dllmain.c +60 -0
- data/glfw-src/lib/win32/win32_enable.c +155 -0
- data/glfw-src/lib/win32/win32_fullscreen.c +317 -0
- data/glfw-src/lib/win32/win32_glext.c +85 -0
- data/glfw-src/lib/win32/win32_init.c +356 -0
- data/glfw-src/lib/win32/win32_joystick.c +234 -0
- data/glfw-src/lib/win32/win32_thread.c +511 -0
- data/glfw-src/lib/win32/win32_time.c +146 -0
- data/glfw-src/lib/win32/win32_window.c +1714 -0
- data/glfw-src/lib/window.c +727 -0
- data/glfw-src/lib/x11/Makefile.x11.in +243 -0
- data/glfw-src/lib/x11/platform.h +415 -0
- data/glfw-src/lib/x11/x11_enable.c +51 -0
- data/glfw-src/lib/x11/x11_fullscreen.c +524 -0
- data/glfw-src/lib/x11/x11_glext.c +69 -0
- data/glfw-src/lib/x11/x11_init.c +275 -0
- data/glfw-src/lib/x11/x11_joystick.c +371 -0
- data/glfw-src/lib/x11/x11_keysym2unicode.c +902 -0
- data/glfw-src/lib/x11/x11_thread.c +507 -0
- data/glfw-src/lib/x11/x11_time.c +154 -0
- data/glfw-src/lib/x11/x11_window.c +1746 -0
- data/glfw-src/license.txt +21 -0
- data/glfw-src/readme.html +927 -0
- data/glfw-src/support/d/examples/Makefile +59 -0
- data/glfw-src/support/d/examples/boing.d +610 -0
- data/glfw-src/support/d/examples/gears.d +379 -0
- data/glfw-src/support/d/examples/keytest.d +272 -0
- data/glfw-src/support/d/examples/listmodes.d +48 -0
- data/glfw-src/support/d/examples/mipmaps.d +126 -0
- data/glfw-src/support/d/examples/mtbench.d +304 -0
- data/glfw-src/support/d/examples/mthello.d +54 -0
- data/glfw-src/support/d/examples/particles.d +1150 -0
- data/glfw-src/support/d/examples/pong3d.d +840 -0
- data/glfw-src/support/d/examples/splitview.d +486 -0
- data/glfw-src/support/d/examples/triangle.d +108 -0
- data/glfw-src/support/d/examples/wave.d +400 -0
- data/glfw-src/support/d/imports/gl.d +4539 -0
- data/glfw-src/support/d/imports/glfw.d +349 -0
- data/glfw-src/support/d/imports/glu.d +328 -0
- data/glfw-src/support/d/lib/glfwdll.def +64 -0
- data/glfw-src/support/d/lib/glu32.def +56 -0
- data/glfw-src/support/d/lib/makefile +12 -0
- data/glfw-src/support/d/lib/opengl32.def +372 -0
- data/glfw-src/support/d/readme.html +83 -0
- data/glfw-src/support/delphi/examples/Triangle.dpr +105 -0
- data/glfw-src/support/delphi/lib/glfw.pas +437 -0
- data/glfw-src/support/delphi/readme.html +97 -0
- data/glfw-src/support/lua/examples/gears.lua +383 -0
- data/glfw-src/support/lua/examples/test1.lua +68 -0
- data/glfw-src/support/lua/readme.html +128 -0
- data/glfw-src/support/lua/src/luaglfw.c +1179 -0
- data/glfw-src/support/lua/src/luaglfw.h +48 -0
- data/glfw-src/support/lua/src/runlua.c +82 -0
- data/glfw-src/support/masm/examples/fpc.mac +47 -0
- data/glfw-src/support/masm/examples/makeit.bat +66 -0
- data/glfw-src/support/masm/examples/triangle.asm +232 -0
- data/glfw-src/support/masm/include/glfw.inc +326 -0
- data/glfw-src/support/masm/include/glu32.inc +55 -0
- data/glfw-src/support/masm/include/opengl32.inc +372 -0
- data/glfw-src/support/masm/lib/glfwdll.lib +0 -0
- data/glfw-src/support/masm/readme.html +170 -0
- data/glfw-src/support/msvc80/GLFW.sln +26 -0
- data/glfw-src/support/msvc80/GLFW.vcproj +257 -0
- data/glfw-src/support/msvc80/GLFWDLL.vcproj +287 -0
- data/glfw-src/support/visualbasic/bindings/glfw.bas +320 -0
- data/glfw-src/support/visualbasic/bindings/glu32.bas +284 -0
- data/glfw-src/support/visualbasic/bindings/opengl32.bas +999 -0
- data/glfw-src/support/visualbasic/examples/Triangle.bas +101 -0
- data/glfw-src/support/visualbasic/readme.html +164 -0
- data/website/index.html +84 -0
- data/website/style.css +110 -0
- metadata +301 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
//========================================================================
|
|
2
|
+
// This is a small test application for GLFW.
|
|
3
|
+
// The program uses a "split window" view, rendering four views of the
|
|
4
|
+
// same scene in one window (e.g. uesful for 3D modelling software). This
|
|
5
|
+
// demo uses scissors to separete the four different rendering areas from
|
|
6
|
+
// each other.
|
|
7
|
+
//
|
|
8
|
+
// (If the code seems a little bit strange here and there, it may be
|
|
9
|
+
// because I am not a friend of orthogonal projections)
|
|
10
|
+
//========================================================================
|
|
11
|
+
|
|
12
|
+
#include <GL/glfw.h>
|
|
13
|
+
#include <math.h>
|
|
14
|
+
|
|
15
|
+
#ifndef PI
|
|
16
|
+
#define PI 3.14159265358979323846
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
//========================================================================
|
|
21
|
+
// Global variables
|
|
22
|
+
//========================================================================
|
|
23
|
+
|
|
24
|
+
// Mouse position
|
|
25
|
+
int xpos = 0, ypos = 0;
|
|
26
|
+
|
|
27
|
+
// Window size
|
|
28
|
+
int width, height;
|
|
29
|
+
|
|
30
|
+
// Active view: 0 = none, 1 = upper left, 2 = upper right, 3 = lower left,
|
|
31
|
+
// 4 = lower right
|
|
32
|
+
int active_view = 0;
|
|
33
|
+
|
|
34
|
+
// Rotation around each axis
|
|
35
|
+
int rot_x = 0, rot_y = 0, rot_z = 0;
|
|
36
|
+
|
|
37
|
+
// Do redraw?
|
|
38
|
+
int do_redraw = 1;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
//========================================================================
|
|
42
|
+
// DrawTorus() - Draw a solid torus (use a display list for the model)
|
|
43
|
+
//========================================================================
|
|
44
|
+
|
|
45
|
+
#define TORUS_MAJOR 1.5
|
|
46
|
+
#define TORUS_MINOR 0.5
|
|
47
|
+
#define TORUS_MAJOR_RES 32
|
|
48
|
+
#define TORUS_MINOR_RES 32
|
|
49
|
+
|
|
50
|
+
void DrawTorus( void )
|
|
51
|
+
{
|
|
52
|
+
static GLuint torus_list = 0;
|
|
53
|
+
int i, j, k;
|
|
54
|
+
double s, t, x, y, z, nx, ny, nz, scale, twopi;
|
|
55
|
+
|
|
56
|
+
if( !torus_list )
|
|
57
|
+
{
|
|
58
|
+
// Start recording displaylist
|
|
59
|
+
torus_list = glGenLists( 1 );
|
|
60
|
+
glNewList( torus_list, GL_COMPILE_AND_EXECUTE );
|
|
61
|
+
|
|
62
|
+
// Draw torus
|
|
63
|
+
twopi = 2.0 * PI;
|
|
64
|
+
for( i = 0; i < TORUS_MINOR_RES; i++ )
|
|
65
|
+
{
|
|
66
|
+
glBegin( GL_QUAD_STRIP );
|
|
67
|
+
for( j = 0; j <= TORUS_MAJOR_RES; j++ )
|
|
68
|
+
{
|
|
69
|
+
for( k = 1; k >= 0; k-- )
|
|
70
|
+
{
|
|
71
|
+
s = (i + k) % TORUS_MINOR_RES + 0.5;
|
|
72
|
+
t = j % TORUS_MAJOR_RES;
|
|
73
|
+
|
|
74
|
+
// Calculate point on surface
|
|
75
|
+
x = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*cos(t*twopi/TORUS_MAJOR_RES);
|
|
76
|
+
y = TORUS_MINOR * sin(s * twopi / TORUS_MINOR_RES);
|
|
77
|
+
z = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*sin(t*twopi/TORUS_MAJOR_RES);
|
|
78
|
+
|
|
79
|
+
// Calculate surface normal
|
|
80
|
+
nx = x - TORUS_MAJOR*cos(t*twopi/TORUS_MAJOR_RES);
|
|
81
|
+
ny = y;
|
|
82
|
+
nz = z - TORUS_MAJOR*sin(t*twopi/TORUS_MAJOR_RES);
|
|
83
|
+
scale = 1.0 / sqrt( nx*nx + ny*ny + nz*nz );
|
|
84
|
+
nx *= scale;
|
|
85
|
+
ny *= scale;
|
|
86
|
+
nz *= scale;
|
|
87
|
+
|
|
88
|
+
glNormal3f( (float)nx, (float)ny, (float)nz );
|
|
89
|
+
glVertex3f( (float)x, (float)y, (float)z );
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
glEnd();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Stop recording displaylist
|
|
96
|
+
glEndList();
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
{
|
|
100
|
+
// Playback displaylist
|
|
101
|
+
glCallList( torus_list );
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
//========================================================================
|
|
107
|
+
// DrawScene() - Draw the scene (a rotating torus)
|
|
108
|
+
//========================================================================
|
|
109
|
+
|
|
110
|
+
void DrawScene( void )
|
|
111
|
+
{
|
|
112
|
+
const GLfloat model_diffuse[4] = {1.0f, 0.8f, 0.8f, 1.0f};
|
|
113
|
+
const GLfloat model_specular[4] = {0.6f, 0.6f, 0.6f, 1.0f};
|
|
114
|
+
const GLfloat model_shininess = 20.0f;
|
|
115
|
+
|
|
116
|
+
glPushMatrix();
|
|
117
|
+
|
|
118
|
+
// Rotate the object
|
|
119
|
+
glRotatef( (GLfloat)rot_x*0.5f, 1.0f, 0.0f, 0.0f );
|
|
120
|
+
glRotatef( (GLfloat)rot_y*0.5f, 0.0f, 1.0f, 0.0f );
|
|
121
|
+
glRotatef( (GLfloat)rot_z*0.5f, 0.0f, 0.0f, 1.0f );
|
|
122
|
+
|
|
123
|
+
// Set model color (used for orthogonal views, lighting disabled)
|
|
124
|
+
glColor4fv( model_diffuse );
|
|
125
|
+
|
|
126
|
+
// Set model material (used for perspective view, lighting enabled)
|
|
127
|
+
glMaterialfv( GL_FRONT, GL_DIFFUSE, model_diffuse );
|
|
128
|
+
glMaterialfv( GL_FRONT, GL_SPECULAR, model_specular );
|
|
129
|
+
glMaterialf( GL_FRONT, GL_SHININESS, model_shininess );
|
|
130
|
+
|
|
131
|
+
// Draw torus
|
|
132
|
+
DrawTorus();
|
|
133
|
+
|
|
134
|
+
glPopMatrix();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
//========================================================================
|
|
139
|
+
// DrawGrid() - Draw a 2D grid (used for orthogonal views)
|
|
140
|
+
//========================================================================
|
|
141
|
+
|
|
142
|
+
void DrawGrid( float scale, int steps )
|
|
143
|
+
{
|
|
144
|
+
int i;
|
|
145
|
+
float x, y;
|
|
146
|
+
|
|
147
|
+
glPushMatrix();
|
|
148
|
+
|
|
149
|
+
// Set background to some dark bluish grey
|
|
150
|
+
glClearColor( 0.05f, 0.05f, 0.2f, 0.0f);
|
|
151
|
+
glClear( GL_COLOR_BUFFER_BIT );
|
|
152
|
+
|
|
153
|
+
// Setup modelview matrix (flat XY view)
|
|
154
|
+
glLoadIdentity();
|
|
155
|
+
gluLookAt( 0.0, 0.0, 1.0,
|
|
156
|
+
0.0, 0.0, 0.0,
|
|
157
|
+
0.0, 1.0, 0.0 );
|
|
158
|
+
|
|
159
|
+
// We don't want to update the Z-buffer
|
|
160
|
+
glDepthMask( GL_FALSE );
|
|
161
|
+
|
|
162
|
+
// Set grid color
|
|
163
|
+
glColor3f( 0.0f, 0.5f, 0.5f );
|
|
164
|
+
|
|
165
|
+
glBegin( GL_LINES );
|
|
166
|
+
|
|
167
|
+
// Horizontal lines
|
|
168
|
+
x = scale * 0.5f * (float)(steps-1);
|
|
169
|
+
y = -scale * 0.5f * (float)(steps-1);
|
|
170
|
+
for( i = 0; i < steps; i ++ )
|
|
171
|
+
{
|
|
172
|
+
glVertex3f( -x, y, 0.0f );
|
|
173
|
+
glVertex3f( x, y, 0.0f );
|
|
174
|
+
y += scale;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Vertical lines
|
|
178
|
+
x = -scale * 0.5f * (float)(steps-1);
|
|
179
|
+
y = scale * 0.5f * (float)(steps-1);
|
|
180
|
+
for( i = 0; i < steps; i ++ )
|
|
181
|
+
{
|
|
182
|
+
glVertex3f( x, -y, 0.0f );
|
|
183
|
+
glVertex3f( x, y, 0.0f );
|
|
184
|
+
x += scale;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
glEnd();
|
|
188
|
+
|
|
189
|
+
// Enable Z-buffer writing again
|
|
190
|
+
glDepthMask( GL_TRUE );
|
|
191
|
+
|
|
192
|
+
glPopMatrix();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
//========================================================================
|
|
197
|
+
// DrawAllViews()
|
|
198
|
+
//========================================================================
|
|
199
|
+
|
|
200
|
+
void DrawAllViews( void )
|
|
201
|
+
{
|
|
202
|
+
const GLfloat light_position[4] = {0.0f, 8.0f, 8.0f, 1.0f};
|
|
203
|
+
const GLfloat light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
204
|
+
const GLfloat light_specular[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
|
205
|
+
const GLfloat light_ambient[4] = {0.2f, 0.2f, 0.3f, 1.0f};
|
|
206
|
+
double aspect;
|
|
207
|
+
|
|
208
|
+
// Calculate aspect of window
|
|
209
|
+
if( height > 0 )
|
|
210
|
+
{
|
|
211
|
+
aspect = (double)width / (double)height;
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
{
|
|
215
|
+
aspect = 1.0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Clear screen
|
|
219
|
+
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
|
|
220
|
+
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
221
|
+
|
|
222
|
+
// Enable scissor test
|
|
223
|
+
glEnable( GL_SCISSOR_TEST );
|
|
224
|
+
|
|
225
|
+
// Enable depth test
|
|
226
|
+
glEnable( GL_DEPTH_TEST );
|
|
227
|
+
glDepthFunc( GL_LEQUAL );
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
// ** ORTHOGONAL VIEWS **
|
|
231
|
+
|
|
232
|
+
// For orthogonal views, use wireframe rendering
|
|
233
|
+
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
|
234
|
+
|
|
235
|
+
// Enable line anti-aliasing
|
|
236
|
+
glEnable( GL_LINE_SMOOTH );
|
|
237
|
+
glEnable( GL_BLEND );
|
|
238
|
+
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
239
|
+
|
|
240
|
+
// Setup orthogonal projection matrix
|
|
241
|
+
glMatrixMode( GL_PROJECTION );
|
|
242
|
+
glLoadIdentity();
|
|
243
|
+
glOrtho( -3.0*aspect, 3.0*aspect, -3.0, 3.0, 1.0, 50.0 );
|
|
244
|
+
|
|
245
|
+
// Upper left view (TOP VIEW)
|
|
246
|
+
glViewport( 0, height/2, width/2, height/2 );
|
|
247
|
+
glScissor( 0, height/2, width/2, height/2 );
|
|
248
|
+
glMatrixMode( GL_MODELVIEW );
|
|
249
|
+
glLoadIdentity();
|
|
250
|
+
gluLookAt( 0.0f, 10.0f, 1e-3f, // Eye-position (above)
|
|
251
|
+
0.0f, 0.0f, 0.0f, // View-point
|
|
252
|
+
0.0f, 1.0f, 0.0f ); // Up-vector
|
|
253
|
+
DrawGrid( 0.5, 12 );
|
|
254
|
+
DrawScene();
|
|
255
|
+
|
|
256
|
+
// Lower left view (FRONT VIEW)
|
|
257
|
+
glViewport( 0, 0, width/2, height/2 );
|
|
258
|
+
glScissor( 0, 0, width/2, height/2 );
|
|
259
|
+
glMatrixMode( GL_MODELVIEW );
|
|
260
|
+
glLoadIdentity();
|
|
261
|
+
gluLookAt( 0.0f, 0.0f, 10.0f, // Eye-position (in front of)
|
|
262
|
+
0.0f, 0.0f, 0.0f, // View-point
|
|
263
|
+
0.0f, 1.0f, 0.0f ); // Up-vector
|
|
264
|
+
DrawGrid( 0.5, 12 );
|
|
265
|
+
DrawScene();
|
|
266
|
+
|
|
267
|
+
// Lower right view (SIDE VIEW)
|
|
268
|
+
glViewport( width/2, 0, width/2, height/2 );
|
|
269
|
+
glScissor( width/2, 0, width/2, height/2 );
|
|
270
|
+
glMatrixMode( GL_MODELVIEW );
|
|
271
|
+
glLoadIdentity();
|
|
272
|
+
gluLookAt( 10.0f, 0.0f, 0.0f, // Eye-position (to the right)
|
|
273
|
+
0.0f, 0.0f, 0.0f, // View-point
|
|
274
|
+
0.0f, 1.0f, 0.0f ); // Up-vector
|
|
275
|
+
DrawGrid( 0.5, 12 );
|
|
276
|
+
DrawScene();
|
|
277
|
+
|
|
278
|
+
// Disable line anti-aliasing
|
|
279
|
+
glDisable( GL_LINE_SMOOTH );
|
|
280
|
+
glDisable( GL_BLEND );
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
// ** PERSPECTIVE VIEW **
|
|
284
|
+
|
|
285
|
+
// For perspective view, use solid rendering
|
|
286
|
+
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
|
287
|
+
|
|
288
|
+
// Enable face culling (faster rendering)
|
|
289
|
+
glEnable( GL_CULL_FACE );
|
|
290
|
+
glCullFace( GL_BACK );
|
|
291
|
+
glFrontFace( GL_CW );
|
|
292
|
+
|
|
293
|
+
// Setup perspective projection matrix
|
|
294
|
+
glMatrixMode( GL_PROJECTION );
|
|
295
|
+
glLoadIdentity();
|
|
296
|
+
gluPerspective( 65.0f, aspect, 1.0f, 50.0f );
|
|
297
|
+
|
|
298
|
+
// Upper right view (PERSPECTIVE VIEW)
|
|
299
|
+
glViewport( width/2, height/2, width/2, height/2 );
|
|
300
|
+
glScissor( width/2, height/2, width/2, height/2 );
|
|
301
|
+
glMatrixMode( GL_MODELVIEW );
|
|
302
|
+
glLoadIdentity();
|
|
303
|
+
gluLookAt( 3.0f, 1.5f, 3.0f, // Eye-position
|
|
304
|
+
0.0f, 0.0f, 0.0f, // View-point
|
|
305
|
+
0.0f, 1.0f, 0.0f ); // Up-vector
|
|
306
|
+
|
|
307
|
+
// Configure and enable light source 1
|
|
308
|
+
glLightfv( GL_LIGHT1, GL_POSITION, light_position );
|
|
309
|
+
glLightfv( GL_LIGHT1, GL_AMBIENT, light_ambient );
|
|
310
|
+
glLightfv( GL_LIGHT1, GL_DIFFUSE, light_diffuse );
|
|
311
|
+
glLightfv( GL_LIGHT1, GL_SPECULAR, light_specular );
|
|
312
|
+
glEnable( GL_LIGHT1 );
|
|
313
|
+
glEnable( GL_LIGHTING );
|
|
314
|
+
|
|
315
|
+
// Draw scene
|
|
316
|
+
DrawScene();
|
|
317
|
+
|
|
318
|
+
// Disable lighting
|
|
319
|
+
glDisable( GL_LIGHTING );
|
|
320
|
+
|
|
321
|
+
// Disable face culling
|
|
322
|
+
glDisable( GL_CULL_FACE );
|
|
323
|
+
|
|
324
|
+
// Disable depth test
|
|
325
|
+
glDisable( GL_DEPTH_TEST );
|
|
326
|
+
|
|
327
|
+
// Disable scissor test
|
|
328
|
+
glDisable( GL_SCISSOR_TEST );
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
// Draw a border around the active view
|
|
332
|
+
if( active_view > 0 && active_view != 2 )
|
|
333
|
+
{
|
|
334
|
+
glViewport( 0, 0, width, height );
|
|
335
|
+
glMatrixMode( GL_PROJECTION );
|
|
336
|
+
glLoadIdentity();
|
|
337
|
+
glOrtho( 0.0, 2.0, 0.0, 2.0, 0.0, 1.0 );
|
|
338
|
+
glMatrixMode( GL_MODELVIEW );
|
|
339
|
+
glLoadIdentity();
|
|
340
|
+
glColor3f( 1.0f, 1.0f, 0.6f );
|
|
341
|
+
glTranslatef( (active_view-1)&1, 1-(active_view-1)/2, 0.0f );
|
|
342
|
+
glBegin( GL_LINE_STRIP );
|
|
343
|
+
glVertex2i( 0, 0 );
|
|
344
|
+
glVertex2i( 1, 0 );
|
|
345
|
+
glVertex2i( 1, 1 );
|
|
346
|
+
glVertex2i( 0, 1 );
|
|
347
|
+
glVertex2i( 0, 0 );
|
|
348
|
+
glEnd();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
//========================================================================
|
|
354
|
+
// WindowSizeFun() - Window size callback function
|
|
355
|
+
//========================================================================
|
|
356
|
+
|
|
357
|
+
void GLFWCALL WindowSizeFun( int w, int h )
|
|
358
|
+
{
|
|
359
|
+
width = w;
|
|
360
|
+
height = h > 0 ? h : 1;
|
|
361
|
+
do_redraw = 1;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
//========================================================================
|
|
366
|
+
// WindowRefreshFun() - Window refresh callback function
|
|
367
|
+
//========================================================================
|
|
368
|
+
|
|
369
|
+
void GLFWCALL WindowRefreshFun( void )
|
|
370
|
+
{
|
|
371
|
+
do_redraw = 1;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
//========================================================================
|
|
376
|
+
// MousePosFun() - Mouse position callback function
|
|
377
|
+
//========================================================================
|
|
378
|
+
|
|
379
|
+
void GLFWCALL MousePosFun( int x, int y )
|
|
380
|
+
{
|
|
381
|
+
// Depending on which view was selected, rotate around different axes
|
|
382
|
+
switch( active_view )
|
|
383
|
+
{
|
|
384
|
+
case 1:
|
|
385
|
+
rot_x += y - ypos;
|
|
386
|
+
rot_z += x - xpos;
|
|
387
|
+
do_redraw = 1;
|
|
388
|
+
break;
|
|
389
|
+
case 3:
|
|
390
|
+
rot_x += y - ypos;
|
|
391
|
+
rot_y += x - xpos;
|
|
392
|
+
do_redraw = 1;
|
|
393
|
+
break;
|
|
394
|
+
case 4:
|
|
395
|
+
rot_y += x - xpos;
|
|
396
|
+
rot_z += y - ypos;
|
|
397
|
+
do_redraw = 1;
|
|
398
|
+
break;
|
|
399
|
+
default:
|
|
400
|
+
// Do nothing for perspective view, or if no view is selected
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// Remember mouse position
|
|
405
|
+
xpos = x;
|
|
406
|
+
ypos = y;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
//========================================================================
|
|
411
|
+
// MouseButtonFun() - Mouse button callback function
|
|
412
|
+
//========================================================================
|
|
413
|
+
|
|
414
|
+
void GLFWCALL MouseButtonFun( int button, int action )
|
|
415
|
+
{
|
|
416
|
+
// Button clicked?
|
|
417
|
+
if( ( button == GLFW_MOUSE_BUTTON_LEFT ) && action == GLFW_PRESS )
|
|
418
|
+
{
|
|
419
|
+
// Detect which of the four views was clicked
|
|
420
|
+
active_view = 1;
|
|
421
|
+
if( xpos >= width/2 )
|
|
422
|
+
{
|
|
423
|
+
active_view += 1;
|
|
424
|
+
}
|
|
425
|
+
if( ypos >= height/2 )
|
|
426
|
+
{
|
|
427
|
+
active_view += 2;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Button released?
|
|
432
|
+
else if( button == GLFW_MOUSE_BUTTON_LEFT )
|
|
433
|
+
{
|
|
434
|
+
// Deselect any previously selected view
|
|
435
|
+
active_view = 0;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
do_redraw = 1;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
//========================================================================
|
|
443
|
+
// main()
|
|
444
|
+
//========================================================================
|
|
445
|
+
|
|
446
|
+
int main( void )
|
|
447
|
+
{
|
|
448
|
+
int running;
|
|
449
|
+
|
|
450
|
+
// Initialise GLFW
|
|
451
|
+
glfwInit();
|
|
452
|
+
|
|
453
|
+
// Open OpenGL window
|
|
454
|
+
if( !glfwOpenWindow( 500, 500, 0,0,0,0, 16,0, GLFW_WINDOW ) )
|
|
455
|
+
{
|
|
456
|
+
glfwTerminate();
|
|
457
|
+
return 0;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Set window title
|
|
461
|
+
glfwSetWindowTitle( "Split view demo" );
|
|
462
|
+
|
|
463
|
+
// Enable sticky keys
|
|
464
|
+
glfwEnable( GLFW_STICKY_KEYS );
|
|
465
|
+
|
|
466
|
+
// Enable mouse cursor (only needed for fullscreen mode)
|
|
467
|
+
glfwEnable( GLFW_MOUSE_CURSOR );
|
|
468
|
+
|
|
469
|
+
// Disable automatic event polling
|
|
470
|
+
glfwDisable( GLFW_AUTO_POLL_EVENTS );
|
|
471
|
+
|
|
472
|
+
// Set callback functions
|
|
473
|
+
glfwSetWindowSizeCallback( WindowSizeFun );
|
|
474
|
+
glfwSetWindowRefreshCallback( WindowRefreshFun );
|
|
475
|
+
glfwSetMousePosCallback( MousePosFun );
|
|
476
|
+
glfwSetMouseButtonCallback( MouseButtonFun );
|
|
477
|
+
|
|
478
|
+
// Main loop
|
|
479
|
+
do
|
|
480
|
+
{
|
|
481
|
+
// Only redraw if we need to
|
|
482
|
+
if( do_redraw )
|
|
483
|
+
{
|
|
484
|
+
// Draw all views
|
|
485
|
+
DrawAllViews();
|
|
486
|
+
|
|
487
|
+
// Swap buffers
|
|
488
|
+
glfwSwapBuffers();
|
|
489
|
+
|
|
490
|
+
do_redraw = 0;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Wait for new events
|
|
494
|
+
glfwWaitEvents();
|
|
495
|
+
|
|
496
|
+
// Check if the ESC key was pressed or the window was closed
|
|
497
|
+
running = !glfwGetKey( GLFW_KEY_ESC ) &&
|
|
498
|
+
glfwGetWindowParam( GLFW_OPENED );
|
|
499
|
+
}
|
|
500
|
+
while( running );
|
|
501
|
+
|
|
502
|
+
// Close OpenGL window and terminate GLFW
|
|
503
|
+
glfwTerminate();
|
|
504
|
+
|
|
505
|
+
return 0;
|
|
506
|
+
}
|