mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Formatting.
This commit is contained in:
parent
a4a2eaaa0f
commit
cba8d35c65
@ -50,48 +50,49 @@ static int do_redraw = 1;
|
|||||||
#define TORUS_MAJOR_RES 32
|
#define TORUS_MAJOR_RES 32
|
||||||
#define TORUS_MINOR_RES 32
|
#define TORUS_MINOR_RES 32
|
||||||
|
|
||||||
static void drawTorus( void )
|
static void drawTorus(void)
|
||||||
{
|
{
|
||||||
static GLuint torus_list = 0;
|
static GLuint torus_list = 0;
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
double s, t, x, y, z, nx, ny, nz, scale, twopi;
|
double s, t, x, y, z, nx, ny, nz, scale, twopi;
|
||||||
|
|
||||||
if( !torus_list )
|
if (!torus_list)
|
||||||
{
|
{
|
||||||
// Start recording displaylist
|
// Start recording displaylist
|
||||||
torus_list = glGenLists( 1 );
|
torus_list = glGenLists(1);
|
||||||
glNewList( torus_list, GL_COMPILE_AND_EXECUTE );
|
glNewList(torus_list, GL_COMPILE_AND_EXECUTE);
|
||||||
|
|
||||||
// Draw torus
|
// Draw torus
|
||||||
twopi = 2.0 * M_PI;
|
twopi = 2.0 * M_PI;
|
||||||
for( i = 0; i < TORUS_MINOR_RES; i++ )
|
for (i = 0; i < TORUS_MINOR_RES; i++)
|
||||||
{
|
{
|
||||||
glBegin( GL_QUAD_STRIP );
|
glBegin(GL_QUAD_STRIP);
|
||||||
for( j = 0; j <= TORUS_MAJOR_RES; j++ )
|
for (j = 0; j <= TORUS_MAJOR_RES; j++)
|
||||||
{
|
{
|
||||||
for( k = 1; k >= 0; k-- )
|
for (k = 1; k >= 0; k--)
|
||||||
{
|
{
|
||||||
s = (i + k) % TORUS_MINOR_RES + 0.5;
|
s = (i + k) % TORUS_MINOR_RES + 0.5;
|
||||||
t = j % TORUS_MAJOR_RES;
|
t = j % TORUS_MAJOR_RES;
|
||||||
|
|
||||||
// Calculate point on surface
|
// Calculate point on surface
|
||||||
x = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*cos(t*twopi/TORUS_MAJOR_RES);
|
x = (TORUS_MAJOR + TORUS_MINOR * cos(s * twopi / TORUS_MINOR_RES)) * cos(t * twopi / TORUS_MAJOR_RES);
|
||||||
y = TORUS_MINOR * sin(s * twopi / TORUS_MINOR_RES);
|
y = TORUS_MINOR * sin(s * twopi / TORUS_MINOR_RES);
|
||||||
z = (TORUS_MAJOR+TORUS_MINOR*cos(s*twopi/TORUS_MINOR_RES))*sin(t*twopi/TORUS_MAJOR_RES);
|
z = (TORUS_MAJOR + TORUS_MINOR * cos(s * twopi / TORUS_MINOR_RES)) * sin(t * twopi / TORUS_MAJOR_RES);
|
||||||
|
|
||||||
// Calculate surface normal
|
// Calculate surface normal
|
||||||
nx = x - TORUS_MAJOR*cos(t*twopi/TORUS_MAJOR_RES);
|
nx = x - TORUS_MAJOR * cos(t * twopi / TORUS_MAJOR_RES);
|
||||||
ny = y;
|
ny = y;
|
||||||
nz = z - TORUS_MAJOR*sin(t*twopi/TORUS_MAJOR_RES);
|
nz = z - TORUS_MAJOR * sin(t * twopi / TORUS_MAJOR_RES);
|
||||||
scale = 1.0 / sqrt( nx*nx + ny*ny + nz*nz );
|
scale = 1.0 / sqrt(nx*nx + ny*ny + nz*nz);
|
||||||
nx *= scale;
|
nx *= scale;
|
||||||
ny *= scale;
|
ny *= scale;
|
||||||
nz *= scale;
|
nz *= scale;
|
||||||
|
|
||||||
glNormal3f( (float)nx, (float)ny, (float)nz );
|
glNormal3f((float) nx, (float) ny, (float) nz);
|
||||||
glVertex3f( (float)x, (float)y, (float)z );
|
glVertex3f((float) x, (float) y, (float) z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ static void drawTorus( void )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Playback displaylist
|
// Playback displaylist
|
||||||
glCallList( torus_list );
|
glCallList(torus_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ static void drawTorus( void )
|
|||||||
// Draw the scene (a rotating torus)
|
// Draw the scene (a rotating torus)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void drawScene( void )
|
static void drawScene(void)
|
||||||
{
|
{
|
||||||
const GLfloat model_diffuse[4] = {1.0f, 0.8f, 0.8f, 1.0f};
|
const GLfloat model_diffuse[4] = {1.0f, 0.8f, 0.8f, 1.0f};
|
||||||
const GLfloat model_specular[4] = {0.6f, 0.6f, 0.6f, 1.0f};
|
const GLfloat model_specular[4] = {0.6f, 0.6f, 0.6f, 1.0f};
|
||||||
@ -119,17 +120,17 @@ static void drawScene( void )
|
|||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
// Rotate the object
|
// Rotate the object
|
||||||
glRotatef( (GLfloat)rot_x*0.5f, 1.0f, 0.0f, 0.0f );
|
glRotatef((GLfloat) rot_x * 0.5f, 1.0f, 0.0f, 0.0f);
|
||||||
glRotatef( (GLfloat)rot_y*0.5f, 0.0f, 1.0f, 0.0f );
|
glRotatef((GLfloat) rot_y * 0.5f, 0.0f, 1.0f, 0.0f);
|
||||||
glRotatef( (GLfloat)rot_z*0.5f, 0.0f, 0.0f, 1.0f );
|
glRotatef((GLfloat) rot_z * 0.5f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
// Set model color (used for orthogonal views, lighting disabled)
|
// Set model color (used for orthogonal views, lighting disabled)
|
||||||
glColor4fv( model_diffuse );
|
glColor4fv(model_diffuse);
|
||||||
|
|
||||||
// Set model material (used for perspective view, lighting enabled)
|
// Set model material (used for perspective view, lighting enabled)
|
||||||
glMaterialfv( GL_FRONT, GL_DIFFUSE, model_diffuse );
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, model_diffuse);
|
||||||
glMaterialfv( GL_FRONT, GL_SPECULAR, model_specular );
|
glMaterialfv(GL_FRONT, GL_SPECULAR, model_specular);
|
||||||
glMaterialf( GL_FRONT, GL_SHININESS, model_shininess );
|
glMaterialf(GL_FRONT, GL_SHININESS, model_shininess);
|
||||||
|
|
||||||
// Draw torus
|
// Draw torus
|
||||||
drawTorus();
|
drawTorus();
|
||||||
@ -142,55 +143,55 @@ static void drawScene( void )
|
|||||||
// Draw a 2D grid (used for orthogonal views)
|
// Draw a 2D grid (used for orthogonal views)
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void drawGrid( float scale, int steps )
|
static void drawGrid(float scale, int steps)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
// Set background to some dark bluish grey
|
// Set background to some dark bluish grey
|
||||||
glClearColor( 0.05f, 0.05f, 0.2f, 0.0f);
|
glClearColor(0.05f, 0.05f, 0.2f, 0.0f);
|
||||||
glClear( GL_COLOR_BUFFER_BIT );
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// Setup modelview matrix (flat XY view)
|
// Setup modelview matrix (flat XY view)
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 0.0, 0.0, 1.0,
|
gluLookAt(0.0, 0.0, 1.0,
|
||||||
0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0 );
|
0.0, 1.0, 0.0);
|
||||||
|
|
||||||
// We don't want to update the Z-buffer
|
// We don't want to update the Z-buffer
|
||||||
glDepthMask( GL_FALSE );
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
// Set grid color
|
// Set grid color
|
||||||
glColor3f( 0.0f, 0.5f, 0.5f );
|
glColor3f(0.0f, 0.5f, 0.5f);
|
||||||
|
|
||||||
glBegin( GL_LINES );
|
glBegin(GL_LINES);
|
||||||
|
|
||||||
// Horizontal lines
|
// Horizontal lines
|
||||||
x = scale * 0.5f * (float)(steps-1);
|
x = scale * 0.5f * (float) (steps - 1);
|
||||||
y = -scale * 0.5f * (float)(steps-1);
|
y = -scale * 0.5f * (float) (steps - 1);
|
||||||
for( i = 0; i < steps; i ++ )
|
for (i = 0; i < steps; i++)
|
||||||
{
|
{
|
||||||
glVertex3f( -x, y, 0.0f );
|
glVertex3f(-x, y, 0.0f);
|
||||||
glVertex3f( x, y, 0.0f );
|
glVertex3f(x, y, 0.0f);
|
||||||
y += scale;
|
y += scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vertical lines
|
// Vertical lines
|
||||||
x = -scale * 0.5f * (float)(steps-1);
|
x = -scale * 0.5f * (float) (steps - 1);
|
||||||
y = scale * 0.5f * (float)(steps-1);
|
y = scale * 0.5f * (float) (steps - 1);
|
||||||
for( i = 0; i < steps; i ++ )
|
for (i = 0; i < steps; i++)
|
||||||
{
|
{
|
||||||
glVertex3f( x, -y, 0.0f );
|
glVertex3f(x, -y, 0.0f);
|
||||||
glVertex3f( x, y, 0.0f );
|
glVertex3f(x, y, 0.0f);
|
||||||
x += scale;
|
x += scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
// Enable Z-buffer writing again
|
// Enable Z-buffer writing again
|
||||||
glDepthMask( GL_TRUE );
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
@ -200,7 +201,7 @@ static void drawGrid( float scale, int steps )
|
|||||||
// Draw all views
|
// Draw all views
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void drawAllViews( void )
|
static void drawAllViews(void)
|
||||||
{
|
{
|
||||||
const GLfloat light_position[4] = {0.0f, 8.0f, 8.0f, 1.0f};
|
const GLfloat light_position[4] = {0.0f, 8.0f, 8.0f, 1.0f};
|
||||||
const GLfloat light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
const GLfloat light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
@ -209,145 +210,142 @@ static void drawAllViews( void )
|
|||||||
double aspect;
|
double aspect;
|
||||||
|
|
||||||
// Calculate aspect of window
|
// Calculate aspect of window
|
||||||
if( height > 0 )
|
if (height > 0)
|
||||||
{
|
aspect = (double) width / (double) height;
|
||||||
aspect = (double)width / (double)height;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
aspect = 1.0;
|
aspect = 1.0;
|
||||||
}
|
|
||||||
|
|
||||||
// Clear screen
|
// Clear screen
|
||||||
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Enable scissor test
|
// Enable scissor test
|
||||||
glEnable( GL_SCISSOR_TEST );
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
// Enable depth test
|
// Enable depth test
|
||||||
glEnable( GL_DEPTH_TEST );
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc( GL_LEQUAL );
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
|
||||||
|
|
||||||
// ** ORTHOGONAL VIEWS **
|
// ** ORTHOGONAL VIEWS **
|
||||||
|
|
||||||
// For orthogonal views, use wireframe rendering
|
// For orthogonal views, use wireframe rendering
|
||||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
|
|
||||||
// Enable line anti-aliasing
|
// Enable line anti-aliasing
|
||||||
glEnable( GL_LINE_SMOOTH );
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glEnable( GL_BLEND );
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Setup orthogonal projection matrix
|
// Setup orthogonal projection matrix
|
||||||
glMatrixMode( GL_PROJECTION );
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho( -3.0*aspect, 3.0*aspect, -3.0, 3.0, 1.0, 50.0 );
|
glOrtho(-3.0 * aspect, 3.0 * aspect, -3.0, 3.0, 1.0, 50.0);
|
||||||
|
|
||||||
// Upper left view (TOP VIEW)
|
// Upper left view (TOP VIEW)
|
||||||
glViewport( 0, height/2, width/2, height/2 );
|
glViewport(0, height / 2, width / 2, height / 2);
|
||||||
glScissor( 0, height/2, width/2, height/2 );
|
glScissor(0, height / 2, width / 2, height / 2);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 0.0f, 10.0f, 1e-3f, // Eye-position (above)
|
gluLookAt(0.0f, 10.0f, 1e-3f, // Eye-position (above)
|
||||||
0.0f, 0.0f, 0.0f, // View-point
|
0.0f, 0.0f, 0.0f, // View-point
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
0.0f, 1.0f, 0.0f); // Up-vector
|
||||||
drawGrid( 0.5, 12 );
|
drawGrid(0.5, 12);
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// Lower left view (FRONT VIEW)
|
// Lower left view (FRONT VIEW)
|
||||||
glViewport( 0, 0, width/2, height/2 );
|
glViewport(0, 0, width / 2, height / 2);
|
||||||
glScissor( 0, 0, width/2, height/2 );
|
glScissor(0, 0, width / 2, height / 2);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 0.0f, 0.0f, 10.0f, // Eye-position (in front of)
|
gluLookAt(0.0f, 0.0f, 10.0f, // Eye-position (in front of)
|
||||||
0.0f, 0.0f, 0.0f, // View-point
|
0.0f, 0.0f, 0.0f, // View-point
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
0.0f, 1.0f, 0.0f); // Up-vector
|
||||||
drawGrid( 0.5, 12 );
|
drawGrid(0.5, 12);
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// Lower right view (SIDE VIEW)
|
// Lower right view (SIDE VIEW)
|
||||||
glViewport( width/2, 0, width/2, height/2 );
|
glViewport(width / 2, 0, width / 2, height / 2);
|
||||||
glScissor( width/2, 0, width/2, height/2 );
|
glScissor(width / 2, 0, width / 2, height / 2);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 10.0f, 0.0f, 0.0f, // Eye-position (to the right)
|
gluLookAt(10.0f, 0.0f, 0.0f, // Eye-position (to the right)
|
||||||
0.0f, 0.0f, 0.0f, // View-point
|
0.0f, 0.0f, 0.0f, // View-point
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
0.0f, 1.0f, 0.0f); // Up-vector
|
||||||
drawGrid( 0.5, 12 );
|
drawGrid(0.5, 12);
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// Disable line anti-aliasing
|
// Disable line anti-aliasing
|
||||||
glDisable( GL_LINE_SMOOTH );
|
glDisable(GL_LINE_SMOOTH);
|
||||||
glDisable( GL_BLEND );
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
|
||||||
// ** PERSPECTIVE VIEW **
|
// ** PERSPECTIVE VIEW **
|
||||||
|
|
||||||
// For perspective view, use solid rendering
|
// For perspective view, use solid rendering
|
||||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|
||||||
// Enable face culling (faster rendering)
|
// Enable face culling (faster rendering)
|
||||||
glEnable( GL_CULL_FACE );
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace( GL_BACK );
|
glCullFace(GL_BACK);
|
||||||
glFrontFace( GL_CW );
|
glFrontFace(GL_CW);
|
||||||
|
|
||||||
// Setup perspective projection matrix
|
// Setup perspective projection matrix
|
||||||
glMatrixMode( GL_PROJECTION );
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective( 65.0f, aspect, 1.0f, 50.0f );
|
gluPerspective(65.0f, aspect, 1.0f, 50.0f);
|
||||||
|
|
||||||
// Upper right view (PERSPECTIVE VIEW)
|
// Upper right view (PERSPECTIVE VIEW)
|
||||||
glViewport( width/2, height/2, width/2, height/2 );
|
glViewport(width / 2, height / 2, width / 2, height / 2);
|
||||||
glScissor( width/2, height/2, width/2, height/2 );
|
glScissor(width / 2, height / 2, width / 2, height / 2);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt( 3.0f, 1.5f, 3.0f, // Eye-position
|
gluLookAt(3.0f, 1.5f, 3.0f, // Eye-position
|
||||||
0.0f, 0.0f, 0.0f, // View-point
|
0.0f, 0.0f, 0.0f, // View-point
|
||||||
0.0f, 1.0f, 0.0f ); // Up-vector
|
0.0f, 1.0f, 0.0f); // Up-vector
|
||||||
|
|
||||||
// Configure and enable light source 1
|
// Configure and enable light source 1
|
||||||
glLightfv( GL_LIGHT1, GL_POSITION, light_position );
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position);
|
||||||
glLightfv( GL_LIGHT1, GL_AMBIENT, light_ambient );
|
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
|
||||||
glLightfv( GL_LIGHT1, GL_DIFFUSE, light_diffuse );
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
|
||||||
glLightfv( GL_LIGHT1, GL_SPECULAR, light_specular );
|
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
|
||||||
glEnable( GL_LIGHT1 );
|
glEnable(GL_LIGHT1);
|
||||||
glEnable( GL_LIGHTING );
|
glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
// Draw scene
|
// Draw scene
|
||||||
drawScene();
|
drawScene();
|
||||||
|
|
||||||
// Disable lighting
|
// Disable lighting
|
||||||
glDisable( GL_LIGHTING );
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
// Disable face culling
|
// Disable face culling
|
||||||
glDisable( GL_CULL_FACE );
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
// Disable depth test
|
// Disable depth test
|
||||||
glDisable( GL_DEPTH_TEST );
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
// Disable scissor test
|
// Disable scissor test
|
||||||
glDisable( GL_SCISSOR_TEST );
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
|
|
||||||
// Draw a border around the active view
|
// Draw a border around the active view
|
||||||
if( active_view > 0 && active_view != 2 )
|
if (active_view > 0 && active_view != 2)
|
||||||
{
|
{
|
||||||
glViewport( 0, 0, width, height );
|
glViewport(0, 0, width, height);
|
||||||
glMatrixMode( GL_PROJECTION );
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho( 0.0, 2.0, 0.0, 2.0, 0.0, 1.0 );
|
glOrtho(0.0, 2.0, 0.0, 2.0, 0.0, 1.0);
|
||||||
glMatrixMode( GL_MODELVIEW );
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glColor3f( 1.0f, 1.0f, 0.6f );
|
glTranslatef((GLfloat) ((active_view - 1) & 1), (GLfloat) (1 - (active_view - 1) / 2), 0.0f);
|
||||||
glTranslatef( (GLfloat) ((active_view - 1) & 1), (GLfloat) (1 - (active_view - 1) / 2), 0.0f );
|
|
||||||
glBegin( GL_LINE_STRIP );
|
glColor3f(1.0f, 1.0f, 0.6f);
|
||||||
glVertex2i( 0, 0 );
|
|
||||||
glVertex2i( 1, 0 );
|
glBegin(GL_LINE_STRIP);
|
||||||
glVertex2i( 1, 1 );
|
glVertex2i(0, 0);
|
||||||
glVertex2i( 0, 1 );
|
glVertex2i(1, 0);
|
||||||
glVertex2i( 0, 0 );
|
glVertex2i(1, 1);
|
||||||
|
glVertex2i(0, 1);
|
||||||
|
glVertex2i(0, 0);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,7 +355,7 @@ static void drawAllViews( void )
|
|||||||
// Window size callback function
|
// Window size callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void windowSizeFun( GLFWwindow window, int w, int h )
|
static void windowSizeFun(GLFWwindow window, int w, int h)
|
||||||
{
|
{
|
||||||
width = w;
|
width = w;
|
||||||
height = h > 0 ? h : 1;
|
height = h > 0 ? h : 1;
|
||||||
@ -369,7 +367,7 @@ static void windowSizeFun( GLFWwindow window, int w, int h )
|
|||||||
// Window refresh callback function
|
// Window refresh callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void windowRefreshFun( GLFWwindow window )
|
static void windowRefreshFun(GLFWwindow window)
|
||||||
{
|
{
|
||||||
do_redraw = 1;
|
do_redraw = 1;
|
||||||
}
|
}
|
||||||
@ -379,10 +377,10 @@ static void windowRefreshFun( GLFWwindow window )
|
|||||||
// Mouse position callback function
|
// Mouse position callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void mousePosFun( GLFWwindow window, int x, int y )
|
static void mousePosFun(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
// Depending on which view was selected, rotate around different axes
|
// Depending on which view was selected, rotate around different axes
|
||||||
switch( active_view )
|
switch (active_view)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
rot_x += y - ypos;
|
rot_x += y - ypos;
|
||||||
@ -414,25 +412,18 @@ static void mousePosFun( GLFWwindow window, int x, int y )
|
|||||||
// Mouse button callback function
|
// Mouse button callback function
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
static void mouseButtonFun( GLFWwindow window, int button, int action )
|
static void mouseButtonFun(GLFWwindow window, int button, int action)
|
||||||
{
|
{
|
||||||
// Button clicked?
|
if ((button == GLFW_MOUSE_BUTTON_LEFT) && action == GLFW_PRESS)
|
||||||
if( ( button == GLFW_MOUSE_BUTTON_LEFT ) && action == GLFW_PRESS )
|
|
||||||
{
|
{
|
||||||
// Detect which of the four views was clicked
|
// Detect which of the four views was clicked
|
||||||
active_view = 1;
|
active_view = 1;
|
||||||
if( xpos >= width/2 )
|
if (xpos >= width / 2)
|
||||||
{
|
|
||||||
active_view += 1;
|
active_view += 1;
|
||||||
}
|
if (ypos >= height / 2)
|
||||||
if( ypos >= height/2 )
|
|
||||||
{
|
|
||||||
active_view += 2;
|
active_view += 2;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (button == GLFW_MOUSE_BUTTON_LEFT)
|
||||||
// Button released?
|
|
||||||
else if( button == GLFW_MOUSE_BUTTON_LEFT )
|
|
||||||
{
|
{
|
||||||
// Deselect any previously selected view
|
// Deselect any previously selected view
|
||||||
active_view = 0;
|
active_view = 0;
|
||||||
@ -443,51 +434,50 @@ static void mouseButtonFun( GLFWwindow window, int button, int action )
|
|||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// main()
|
// main
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
int main( void )
|
int main(void)
|
||||||
{
|
{
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
|
|
||||||
// Initialise GLFW
|
// Initialise GLFW
|
||||||
if( !glfwInit() )
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||||
exit( EXIT_FAILURE );
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
glfwOpenWindowHint(GLFW_DEPTH_BITS, 16);
|
||||||
|
|
||||||
// Open OpenGL window
|
// Open OpenGL window
|
||||||
window = glfwOpenWindow( 500, 500, GLFW_WINDOWED, "Split view demo", NULL );
|
window = glfwOpenWindow(500, 500, GLFW_WINDOWED, "Split view demo", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed to open GLFW window\n" );
|
fprintf(stderr, "Failed to open GLFW window\n");
|
||||||
glfwTerminate();
|
exit(EXIT_FAILURE);
|
||||||
exit( EXIT_FAILURE );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable vsync
|
// Enable vsync
|
||||||
glfwSwapInterval( 1 );
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
// Enable sticky keys
|
// Enable sticky keys
|
||||||
glfwEnable( window, GLFW_STICKY_KEYS );
|
glfwEnable(window, GLFW_STICKY_KEYS);
|
||||||
|
|
||||||
// Enable mouse cursor (only needed for fullscreen mode)
|
// Enable mouse cursor (only needed for fullscreen mode)
|
||||||
glfwEnable( window, GLFW_MOUSE_CURSOR );
|
glfwEnable(window, GLFW_MOUSE_CURSOR);
|
||||||
|
|
||||||
// Set callback functions
|
// Set callback functions
|
||||||
glfwSetWindowSizeCallback( window, windowSizeFun );
|
glfwSetWindowSizeCallback(window, windowSizeFun);
|
||||||
glfwSetWindowRefreshCallback( window, windowRefreshFun );
|
glfwSetWindowRefreshCallback(window, windowRefreshFun);
|
||||||
glfwSetMousePosCallback( window, mousePosFun );
|
glfwSetMousePosCallback(window, mousePosFun);
|
||||||
glfwSetMouseButtonCallback( window, mouseButtonFun );
|
glfwSetMouseButtonCallback(window, mouseButtonFun);
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Only redraw if we need to
|
// Only redraw if we need to
|
||||||
if( do_redraw )
|
if (do_redraw)
|
||||||
{
|
{
|
||||||
// Draw all views
|
// Draw all views
|
||||||
drawAllViews();
|
drawAllViews();
|
||||||
@ -502,12 +492,12 @@ int main( void )
|
|||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
|
|
||||||
} // Check if the ESC key was pressed or the window was closed
|
} // Check if the ESC key was pressed or the window was closed
|
||||||
while( glfwIsWindow(window) &&
|
while (glfwIsWindow(window) &&
|
||||||
glfwGetKey(window, GLFW_KEY_ESC) != GLFW_PRESS );
|
glfwGetKey(window, GLFW_KEY_ESC) != GLFW_PRESS);
|
||||||
|
|
||||||
// Close OpenGL window and terminate GLFW
|
// Close OpenGL window and terminate GLFW
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
exit( EXIT_SUCCESS );
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user