1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-10-08 07:07:25 -04:00

Replace GLU with linmath.h in examples

This commit is contained in:
Camilla Berglund 2015-08-09 15:44:20 +02:00
parent 1057bd38cf
commit dd01dd7bef
7 changed files with 86 additions and 72 deletions

View File

@ -63,6 +63,8 @@ GLFW bundles a number of dependencies in the `deps/` directory.
## Changelog ## Changelog
- Changed minimum required CMake version to 2.8.12 - Changed minimum required CMake version to 2.8.12
- Replaced GLU with [linmath.h](https://github.com/datenwolf/linmath.h) in
example programs
- Bugfix: Initialization failed on headless systems - Bugfix: Initialization failed on headless systems
- Bugfix: The cached current context could get out of sync - Bugfix: The cached current context could get out of sync
- [Win32] Renamed hybrid GPU override compile-time option to - [Win32] Renamed hybrid GPU override compile-time option to

View File

@ -90,11 +90,10 @@ Once you have Xcode installed, move on to @ref compile_generate.
To compile GLFW for X11, you need to have the X11 and OpenGL header packages To compile GLFW for X11, you need to have the X11 and OpenGL header packages
installed, as well as the basic development tools like GCC and make. For installed, as well as the basic development tools like GCC and make. For
example, on Ubuntu and other distributions based on Debian GNU/Linux, you need example, on Ubuntu and other distributions based on Debian GNU/Linux, you need
to install the `xorg-dev` and `libglu1-mesa-dev` packages. The former pulls in to install the `xorg-dev` and `libgl1-mesa-dev` packages. The former pulls in
all X.org header packages and the latter pulls in the Mesa OpenGL and GLU all X.org header packages and the latter pulls in the Mesa OpenGL development
packages. GLFW itself doesn't need or use GLU, but some of the examples do. packages. Note that using header files and libraries from Mesa during
Note that using header files and libraries from Mesa during compilation compilation _will not_ tie your binaries to the Mesa implementation of OpenGL.
_will not_ tie your binaries to the Mesa implementation of OpenGL.
Once you have installed the necessary packages, move on to @ref Once you have installed the necessary packages, move on to @ref
compile_generate. compile_generate.

View File

@ -1,5 +1,5 @@
link_libraries(glfw "${OPENGL_glu_LIBRARY}") link_libraries(glfw)
if (BUILD_SHARED_LIBS) if (BUILD_SHARED_LIBS)
add_definitions(-DGLFW_DLL) add_definitions(-DGLFW_DLL)

View File

@ -36,9 +36,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <linmath.h>
/***************************************************************************** /*****************************************************************************
* Various declarations and macros * Various declarations and macros
@ -167,28 +168,6 @@ void CrossProduct( vertex_t a, vertex_t b, vertex_t c, vertex_t *n )
n->z = u1 * v2 - v1 * u2; n->z = u1 * v2 - v1 * u2;
} }
/*****************************************************************************
* Calculate the angle to be passed to gluPerspective() so that a scene
* is visible. This function originates from the OpenGL Red Book.
*
* Parms : size
* The size of the segment when the angle is intersected at "dist"
* (ie at the outermost edge of the angle of vision).
*
* dist
* Distance from viewpoint to scene.
*****************************************************************************/
GLfloat PerspectiveAngle( GLfloat size,
GLfloat dist )
{
GLfloat radTheta, degTheta;
radTheta = 2.f * (GLfloat) atan2( size / 2.f, dist );
degTheta = (180.f * radTheta) / (GLfloat) M_PI;
return degTheta;
}
#define BOING_DEBUG 0 #define BOING_DEBUG 0
@ -233,22 +212,25 @@ void display(void)
*****************************************************************************/ *****************************************************************************/
void reshape( GLFWwindow* window, int w, int h ) void reshape( GLFWwindow* window, int w, int h )
{ {
mat4x4 projection, view;
glViewport( 0, 0, (GLsizei)w, (GLsizei)h ); glViewport( 0, 0, (GLsizei)w, (GLsizei)h );
glMatrixMode( GL_PROJECTION ); glMatrixMode( GL_PROJECTION );
glLoadIdentity(); mat4x4_perspective( projection,
2.f * (float) atan2( RADIUS, 200.f ),
gluPerspective( PerspectiveAngle( RADIUS * 2, 200 ), (float)w / (float)h,
(GLfloat)w / (GLfloat)h, 1.f, VIEW_SCENE_DIST );
1.0, glLoadMatrixf((const GLfloat*) projection);
VIEW_SCENE_DIST );
glMatrixMode( GL_MODELVIEW ); glMatrixMode( GL_MODELVIEW );
glLoadIdentity(); {
vec3 eye = { 0.f, 0.f, VIEW_SCENE_DIST };
gluLookAt( 0.0, 0.0, VIEW_SCENE_DIST,/* eye */ vec3 center = { 0.f, 0.f, 0.f };
0.0, 0.0, 0.0, /* center of vision */ vec3 up = { 0.f, -1.f, 0.f };
0.0, -1.0, 0.0 ); /* up vector */ mat4x4_look_at( view, eye, center, up );
}
glLoadMatrixf((const GLfloat*) view);
} }
void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods ) void key_callback( GLFWwindow* window, int key, int scancode, int action, int mods )

View File

@ -37,8 +37,8 @@
#include <tinycthread.h> #include <tinycthread.h>
#include <getopt.h> #include <getopt.h>
#include <linmath.h>
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
// Define tokens for GL_EXT_separate_specular_color if not already defined // Define tokens for GL_EXT_separate_specular_color if not already defined
@ -785,17 +785,22 @@ static void draw_scene(GLFWwindow* window, double t)
double xpos, ypos, zpos, angle_x, angle_y, angle_z; double xpos, ypos, zpos, angle_x, angle_y, angle_z;
static double t_old = 0.0; static double t_old = 0.0;
float dt; float dt;
mat4x4 projection;
// Calculate frame-to-frame delta time // Calculate frame-to-frame delta time
dt = (float) (t - t_old); dt = (float) (t - t_old);
t_old = t; t_old = t;
mat4x4_perspective(projection,
65.f * (float) M_PI / 180.f,
aspect_ratio,
1.0, 60.0);
glClearColor(0.1f, 0.1f, 0.1f, 1.f); glClearColor(0.1f, 0.1f, 0.1f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadMatrixf((const GLfloat*) projection);
gluPerspective(65.0, aspect_ratio, 1.0, 60.0);
// Setup camera // Setup camera
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);

View File

@ -10,7 +10,6 @@
// because I am not a friend of orthogonal projections) // because I am not a friend of orthogonal projections)
//======================================================================== //========================================================================
#define GLFW_INCLUDE_GLU
#define GLFW_INCLUDE_GLEXT #define GLFW_INCLUDE_GLEXT
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@ -23,6 +22,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <linmath.h>
//======================================================================== //========================================================================
// Global variables // Global variables
@ -151,6 +152,7 @@ static void drawGrid(float scale, int steps)
{ {
int i; int i;
float x, y; float x, y;
mat4x4 view;
glPushMatrix(); glPushMatrix();
@ -159,10 +161,13 @@ static void drawGrid(float scale, int steps)
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
// Setup modelview matrix (flat XY view) // Setup modelview matrix (flat XY view)
glLoadIdentity(); {
gluLookAt(0.0, 0.0, 1.0, vec3 eye = { 0.f, 0.f, 1.f };
0.0, 0.0, 0.0, vec3 center = { 0.f, 0.f, 0.f };
0.0, 1.0, 0.0); vec3 up = { 0.f, 1.f, 0.f };
mat4x4_look_at(view, eye, center, up);
}
glLoadMatrixf((const GLfloat*) view);
// We don't want to update the Z-buffer // We don't want to update the Z-buffer
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
@ -211,13 +216,14 @@ static void drawAllViews(void)
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};
const GLfloat light_specular[4] = {1.0f, 1.0f, 1.0f, 1.0f}; const GLfloat light_specular[4] = {1.0f, 1.0f, 1.0f, 1.0f};
const GLfloat light_ambient[4] = {0.2f, 0.2f, 0.3f, 1.0f}; const GLfloat light_ambient[4] = {0.2f, 0.2f, 0.3f, 1.0f};
double aspect; float aspect;
mat4x4 view, projection;
// Calculate aspect of window // Calculate aspect of window
if (height > 0) if (height > 0)
aspect = (double) width / (double) height; aspect = (float) width / (float) height;
else else
aspect = 1.0; aspect = 1.f;
// Clear screen // Clear screen
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@ -249,10 +255,13 @@ static void drawAllViews(void)
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(); {
gluLookAt(0.0f, 10.0f, 1e-3f, // Eye-position (above) vec3 eye = { 0.f, 10.f, 1e-3f };
0.0f, 0.0f, 0.0f, // View-point vec3 center = { 0.f, 0.f, 0.f };
0.0f, 1.0f, 0.0f); // Up-vector vec3 up = { 0.f, 1.f, 0.f };
mat4x4_look_at( view, eye, center, up );
}
glLoadMatrixf((const GLfloat*) view);
drawGrid(0.5, 12); drawGrid(0.5, 12);
drawScene(); drawScene();
@ -260,10 +269,13 @@ static void drawAllViews(void)
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(); {
gluLookAt(0.0f, 0.0f, 10.0f, // Eye-position (in front of) vec3 eye = { 0.f, 0.f, 10.f };
0.0f, 0.0f, 0.0f, // View-point vec3 center = { 0.f, 0.f, 0.f };
0.0f, 1.0f, 0.0f); // Up-vector vec3 up = { 0.f, 1.f, 0.f };
mat4x4_look_at( view, eye, center, up );
}
glLoadMatrixf((const GLfloat*) view);
drawGrid(0.5, 12); drawGrid(0.5, 12);
drawScene(); drawScene();
@ -271,10 +283,13 @@ static void drawAllViews(void)
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(); {
gluLookAt(10.0f, 0.0f, 0.0f, // Eye-position (to the right) vec3 eye = { 10.f, 0.f, 0.f };
0.0f, 0.0f, 0.0f, // View-point vec3 center = { 0.f, 0.f, 0.f };
0.0f, 1.0f, 0.0f); // Up-vector vec3 up = { 0.f, 1.f, 0.f };
mat4x4_look_at( view, eye, center, up );
}
glLoadMatrixf((const GLfloat*) view);
drawGrid(0.5, 12); drawGrid(0.5, 12);
drawScene(); drawScene();
@ -294,17 +309,23 @@ static void drawAllViews(void)
// Setup perspective projection matrix // Setup perspective projection matrix
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); mat4x4_perspective(projection,
gluPerspective(65.0f, aspect, 1.0f, 50.0f); 65.f * (float) M_PI / 180.f,
aspect,
1.f, 50.f);
glLoadMatrixf((const GLfloat*) projection);
// 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(); {
gluLookAt(3.0f, 1.5f, 3.0f, // Eye-position vec3 eye = { 3.f, 1.5f, 3.f };
0.0f, 0.0f, 0.0f, // View-point vec3 center = { 0.f, 0.f, 0.f };
0.0f, 1.0f, 0.0f); // Up-vector vec3 up = { 0.f, 1.f, 0.f };
mat4x4_look_at( view, eye, center, up );
}
glLoadMatrixf((const GLfloat*) view);
// 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);

View File

@ -17,9 +17,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <linmath.h>
// Maximum delta T to allow for differential calculations // Maximum delta T to allow for differential calculations
#define MAX_DELTA_T 0.01 #define MAX_DELTA_T 0.01
@ -363,6 +364,7 @@ void scroll_callback(GLFWwindow* window, double x, double y)
void framebuffer_size_callback(GLFWwindow* window, int width, int height) void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{ {
float ratio = 1.f; float ratio = 1.f;
mat4x4 projection;
if (height > 0) if (height > 0)
ratio = (float) width / (float) height; ratio = (float) width / (float) height;
@ -372,8 +374,11 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
// Change to the projection matrix and set our viewing volume // Change to the projection matrix and set our viewing volume
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); mat4x4_perspective(projection,
gluPerspective(60.0, ratio, 1.0, 1024.0); 60.f * (float) M_PI / 180.f,
ratio,
1.f, 1024.f);
glLoadMatrixf((const GLfloat*) projection);
} }