aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw27@cam.ac.uk>2009-04-06 16:55:09 +0100
committerThomas White <taw27@cam.ac.uk>2009-04-06 16:55:09 +0100
commitce5ee78efeee12110ed5df58a9dfa6ad7cae09fa (patch)
treed4608792141ceebc57466efa493fb9df8c120a45
parent1dca13f19111c01204abd7deb3a9f027a7a733a0 (diff)
Remove zero-tilt plane. White background when not shaded. Trailing spaces
-rw-r--r--src/glbits.c299
1 files changed, 149 insertions, 150 deletions
diff --git a/src/glbits.c b/src/glbits.c
index ba03adf..86b710e 100644
--- a/src/glbits.c
+++ b/src/glbits.c
@@ -35,7 +35,7 @@ static GLuint glbits_load_shader(const char *filename, GLenum type) {
FILE *fh;
int l;
GLint status;
-
+
fh = fopen(filename, "r");
if ( fh == NULL ) {
fprintf(stderr, "Couldn't load shader '%s'\n", filename);
@@ -48,7 +48,7 @@ static GLuint glbits_load_shader(const char *filename, GLenum type) {
shader = glCreateShader(type);
glShaderSource(shader, 1, &source, NULL);
glCompileShader(shader);
- glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
+ glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if ( status == GL_FALSE ) {
glGetShaderInfoLog(shader, 4095, &l, text);
if ( l > 0 ) {
@@ -57,13 +57,13 @@ static GLuint glbits_load_shader(const char *filename, GLenum type) {
printf("Shader compilation failed.\n");
}
}
-
+
return shader;
-
+
}
static void glbits_load_shaders(DisplayWindow *dw) {
-
+
/* Lighting-per-fragment */
dw->gl_vshader_lightpp = glbits_load_shader(DATADIR"/dtr/light-pp.vert", GL_VERTEX_SHADER);
dw->gl_fshader_lightpp = glbits_load_shader(DATADIR"/dtr/light-pp.frag", GL_FRAGMENT_SHADER);
@@ -71,7 +71,7 @@ static void glbits_load_shaders(DisplayWindow *dw) {
glAttachShader(dw->gl_program_lightpp, dw->gl_vshader_lightpp);
glAttachShader(dw->gl_program_lightpp, dw->gl_fshader_lightpp);
glLinkProgram(dw->gl_program_lightpp);
-
+
}
static void glbits_delete_shaders(DisplayWindow *dw) {
@@ -93,7 +93,7 @@ static void glbits_delete_shaders(DisplayWindow *dw) {
normals[3*i + 1] = yv; \
normals[3*i + 2] = zv; \
i++;
-
+
#define DRAW_BLOB \
double step = M_PI/(double)BLOB_BITS; \
int is, js; \
@@ -121,13 +121,13 @@ static void glbits_delete_shaders(DisplayWindow *dw) {
ADD_VERTEX \
} \
}
-
+
#define DRAW_POINTER_LINE \
glBegin(GL_LINES); \
glVertex3f(1.0, 0.0, 0.0); \
glVertex3f(0.0, 0.0, 0.0); \
glEnd();
-
+
#define DRAW_POINTER_HEAD \
glPushMatrix(); \
for ( pointer_head_face = 1; pointer_head_face <= 4; pointer_head_face++ ) { \
@@ -162,9 +162,9 @@ void glbits_prepare(DisplayWindow *dw) {
ControlContext *ctx;
GLfloat *vertices;
GLfloat *normals;
-
+
ctx = dw->ctx;
-
+
/* "Measured" reflections */
if ( dw->gl_use_buffers ) {
glGenBuffers(1, &dw->gl_ref_vertex_buffer);
@@ -193,7 +193,7 @@ void glbits_prepare(DisplayWindow *dw) {
i++;
}
reflection = reflection->next;
- };
+ };
if ( dw->gl_use_buffers ) {
glBindBuffer(GL_ARRAY_BUFFER, dw->gl_ref_vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, 3*dw->gl_ref_num_vertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
@@ -206,7 +206,7 @@ void glbits_prepare(DisplayWindow *dw) {
dw->gl_ref_normal_array = normals;
}
}
-
+
/* Marker "reflections" */
if ( dw->gl_use_buffers ) {
glGenBuffers(1, &dw->gl_marker_vertex_buffer);
@@ -230,7 +230,7 @@ void glbits_prepare(DisplayWindow *dw) {
DRAW_BLOB
}
reflection = reflection->next;
- };
+ };
if ( dw->gl_use_buffers ) {
glBindBuffer(GL_ARRAY_BUFFER, dw->gl_marker_vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, 3*dw->gl_marker_num_vertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
@@ -243,7 +243,7 @@ void glbits_prepare(DisplayWindow *dw) {
dw->gl_marker_normal_array = normals;
}
}
-
+
/* Generated reflections */
if ( dw->gl_use_buffers ) {
glGenBuffers(1, &dw->gl_gen_vertex_buffer);
@@ -266,7 +266,7 @@ void glbits_prepare(DisplayWindow *dw) {
double size = 5.0 * log(1+0.1*reflection->intensity);
DRAW_BLOB
reflection = reflection->next;
- };
+ };
if ( dw->gl_use_buffers ) {
glBindBuffer(GL_ARRAY_BUFFER, dw->gl_gen_vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, 3*dw->gl_gen_num_vertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
@@ -283,25 +283,25 @@ void glbits_prepare(DisplayWindow *dw) {
} else {
dw->gl_gen_num_vertices = 0;
}
-
+
/* Indexing lines */
glLineWidth(2.0);
if ( ctx->cell && dw->lines ) {
-
+
int max_ind;
signed int h, k, l;
-
+
max_ind = 10;
dw->gl_line_num_vertices = 3*2*((2*1+1)*(2*1+1));
-
+
if ( dw->gl_use_buffers ) {
glGenBuffers(1, &dw->gl_line_vertex_buffer);
}
reflection = ctx->reflectionlist->reflections;
vertices = malloc(3*dw->gl_line_num_vertices*sizeof(GLfloat));
-
+
i=0;
-
+
/* Lines parallel to a */
for ( k=-1; k<=1; k++ ) {
for ( l=-1; l<=1; l++ ) {
@@ -341,7 +341,7 @@ void glbits_prepare(DisplayWindow *dw) {
i++;
}
}
-
+
if ( dw->gl_use_buffers ) {
glBindBuffer(GL_ARRAY_BUFFER, dw->gl_line_vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, 3*dw->gl_line_num_vertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW);
@@ -349,12 +349,12 @@ void glbits_prepare(DisplayWindow *dw) {
} else {
dw->gl_line_vertex_array = vertices;
}
-
+
}
-
+
dw->gl_list_id = glGenLists(1);
glNewList(dw->gl_list_id, GL_COMPILE);
-
+
#if 0
GLUquadric *quad;
quad = gluNewQuadric();
@@ -364,7 +364,7 @@ void glbits_prepare(DisplayWindow *dw) {
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0);
gluSphere(quad, 10, 32, 32);
#endif
-
+
/* Bounding cube: 100 nm^-1 side length */
if ( dw->cube ) {
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, black);
@@ -380,7 +380,7 @@ void glbits_prepare(DisplayWindow *dw) {
glVertex3f(-50.0, -50.0, 50.0);
glNormal3f(50.0, -50.0, 50.0);
glVertex3f(50.0, -50.0, 50.0);
-
+
glEnd();
glBegin(GL_LINE_LOOP);
glNormal3f(50.0, 50.0, -50.0);
@@ -411,7 +411,7 @@ void glbits_prepare(DisplayWindow *dw) {
glVertex3f(50.0, -50.0, -50.0);
glEnd();
}
-
+
/* x, y, z pointers */
int pointer_head_face;
glPushMatrix();
@@ -427,7 +427,7 @@ void glbits_prepare(DisplayWindow *dw) {
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
DRAW_POINTER_HEAD
glPopMatrix();
-
+
glPushMatrix();
glRotatef(90.0, 0.0, 0.0, 1.0);
glScalef(10.0, 1.0, 1.0);
@@ -442,7 +442,7 @@ void glbits_prepare(DisplayWindow *dw) {
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green);
DRAW_POINTER_HEAD
glPopMatrix();
-
+
glPushMatrix();
glRotatef(-90.0, 0.0, 1.0, 0.0);
glScalef(10.0, 1.0, 1.0);
@@ -457,13 +457,13 @@ void glbits_prepare(DisplayWindow *dw) {
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, bblue);
DRAW_POINTER_HEAD
glPopMatrix();
-
+
/* Plot the other reflections */
reflection = ctx->reflectionlist->reflections;
while ( reflection != NULL ) {
-
+
if ( reflection->type == REFLECTION_VECTOR_MARKER_1 ) {
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
@@ -474,11 +474,11 @@ void glbits_prepare(DisplayWindow *dw) {
glNormal3f(reflection->x/1e9, reflection->y/1e9, reflection->z/1e9);
glVertex3f(reflection->x/1e9, reflection->y/1e9, reflection->z/1e9);
glEnd();
-
+
}
-
+
if ( reflection->type == REFLECTION_VECTOR_MARKER_2 ) {
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
@@ -489,11 +489,11 @@ void glbits_prepare(DisplayWindow *dw) {
glNormal3f(reflection->x/1e9, reflection->y/1e9, reflection->z/1e9);
glVertex3f(reflection->x/1e9, reflection->y/1e9, reflection->z/1e9);
glEnd();
-
+
}
-
+
if ( reflection->type == REFLECTION_VECTOR_MARKER_3 ) {
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
@@ -504,89 +504,89 @@ void glbits_prepare(DisplayWindow *dw) {
glNormal3f(reflection->x/1e9, reflection->y/1e9, reflection->z/1e9);
glVertex3f(reflection->x/1e9, reflection->y/1e9, reflection->z/1e9);
glEnd();
-
+
}
-
+
reflection = reflection->next;
-
+
};
-
+
/* Draw the reciprocal unit cell if one is available */
if ( ctx->cell && !dw->lines ) {
-
+
glBegin(GL_LINES);
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0);
glNormal3f(1.0, 0.0, 0.0);
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, red);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(ctx->cell->a.x/1e9, ctx->cell->a.y/1e9, ctx->cell->a.z/1e9);
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, green);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(ctx->cell->b.x/1e9, ctx->cell->b.y/1e9, ctx->cell->b.z/1e9);
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, bblue);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(ctx->cell->c.x/1e9, ctx->cell->c.y/1e9, ctx->cell->c.z/1e9);
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, purple);
glVertex3f(ctx->cell->a.x/1e9, ctx->cell->a.y/1e9, ctx->cell->a.z/1e9);
glVertex3f(ctx->cell->a.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->a.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->a.z/1e9 + ctx->cell->b.z/1e9);
-
+
glVertex3f(ctx->cell->a.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->a.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->a.z/1e9 + ctx->cell->b.z/1e9);
glVertex3f(ctx->cell->b.x/1e9, ctx->cell->b.y/1e9, ctx->cell->b.z/1e9);
-
+
glVertex3f(ctx->cell->c.x/1e9, ctx->cell->c.y/1e9, ctx->cell->c.z/1e9);
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->a.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->a.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->a.z/1e9);
-
+
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->a.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->a.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->a.z/1e9);
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->a.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->a.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->a.z/1e9 + ctx->cell->b.z/1e9);
-
+
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->a.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->a.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->a.z/1e9 + ctx->cell->b.z/1e9);
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->b.z/1e9);
-
+
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->b.z/1e9);
glVertex3f(ctx->cell->c.x/1e9, ctx->cell->c.y/1e9, ctx->cell->c.z/1e9);
-
+
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->b.z/1e9);
glVertex3f(ctx->cell->b.x/1e9, ctx->cell->b.y/1e9, ctx->cell->b.z/1e9);
-
+
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->a.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->a.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->a.z/1e9 + ctx->cell->b.z/1e9);
glVertex3f(ctx->cell->a.x/1e9 + ctx->cell->b.x/1e9,
ctx->cell->a.y/1e9 + ctx->cell->b.y/1e9,
ctx->cell->a.z/1e9 + ctx->cell->b.z/1e9);
-
+
glVertex3f(ctx->cell->c.x/1e9 + ctx->cell->a.x/1e9,
ctx->cell->c.y/1e9 + ctx->cell->a.y/1e9,
ctx->cell->c.z/1e9 + ctx->cell->a.z/1e9);
glVertex3f(ctx->cell->a.x/1e9, ctx->cell->a.y/1e9, ctx->cell->a.z/1e9);
-
+
glEnd();
-
+
}
/* Tilt axis */
@@ -611,22 +611,22 @@ void glbits_prepare(DisplayWindow *dw) {
DRAW_POINTER_HEAD
glPopMatrix();
}
-
+
/* Zero plane (must be drawn last for transparency to work) */
- glBegin(GL_QUADS);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, glass);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0);
- glNormal3f(0.0, 0.0, 1.0);
- glVertex3f(50.0, 50.0, 0.0);
- glVertex3f(50.0, -50.0, 0.0);
- glVertex3f(-50.0, -50.0, 0.0);
- glVertex3f(-50.0, 50.0, 0.0);
- glEnd();
-
+// glBegin(GL_QUADS);
+// glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
+// glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, glass);
+// glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
+// glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0);
+// glNormal3f(0.0, 0.0, 1.0);
+// glVertex3f(50.0, 50.0, 0.0);
+// glVertex3f(50.0, -50.0, 0.0);
+// glVertex3f(-50.0, -50.0, 0.0);
+// glVertex3f(-50.0, 50.0, 0.0);
+// glEnd();
+
glEndList();
-
+
//printf("DW: Vertex counts: meas:%i, mark:%i, gen:%i\n", dw->gl_ref_num_vertices, dw->gl_marker_num_vertices, dw->gl_gen_num_vertices);
}
@@ -634,7 +634,7 @@ void glbits_prepare(DisplayWindow *dw) {
void glbits_set_ortho(DisplayWindow *dw, GLfloat w, GLfloat h) {
GLfloat aspect = w/h;
-
+
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-aspect*(dw->distance/2.0), aspect*(dw->distance/2.0), -(dw->distance/2.0), (dw->distance/2.0), 0.001, 400.0);
@@ -651,8 +651,8 @@ void glbits_set_perspective(DisplayWindow *dw, GLfloat w, GLfloat h) {
}
-gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw) {
-
+gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
+{
GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);
float m[4][4];
@@ -664,57 +664,57 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
GLfloat light0_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat light0_specular[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat grey[] = { 0.6, 0.6, 0.6, 1.0 };
-
+ GLfloat bg_top[] = { 1.0, 1.0, 1.0, 1.0 };
+ GLfloat bg_bot[] = { 1.0, 1.0, 1.0, 1.0 };
+ GLfloat w = dw->drawing_area->allocation.width;
+ GLfloat h = dw->drawing_area->allocation.height;
+ GLfloat aspect = w/h;
+
if ( !gdk_gl_drawable_gl_begin(gldrawable, glcontext) ) {
return 0;
}
-
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
+
if ( dw->background ) {
-
- GLfloat w = dw->drawing_area->allocation.width;
- GLfloat h = dw->drawing_area->allocation.height;
- GLfloat aspect = w/h;
- GLfloat bg_top[] = { 0.0, 0.3, 1.0, 1.0 };
- GLfloat bg_bot[] = { 0.0, 0.7, 1.0, 1.0 };
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0, 0.0, -20.0);
- /* Draw the background (this is done before setting up rotations) */
- /* Set up "private" projection matrix */
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glOrtho(-aspect*3.0, aspect*3.0, -3.0, 3.0, 0.001, 21.0);
- /* Draw background plane */
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, black);
- glMaterialfv(GL_FRONT, GL_SPECULAR, black);
- glMaterialf(GL_FRONT, GL_SHININESS, 0.0);
- glBegin(GL_QUADS);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, bg_bot);
- glVertex3f(-3.0*aspect, -3.0, 0.0);
- glVertex3f(+3.0*aspect, -3.0, 0.0);
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, bg_top);
- glVertex3f(+3.0*aspect, +3.0, 0.0);
- glVertex3f(-3.0*aspect, +3.0, 0.0);
- glEnd();
- /* Restore the old projection matrix */
- glPopMatrix();
- glClear(GL_DEPTH_BUFFER_BIT); /* Background does not count for depth test purposes */
-
+ bg_top[0] = 0.0; bg_top[1] = 0.3; bg_top[2] = 1.0;
+ bg_bot[0] = 0.0; bg_bot[1] = 0.7; bg_bot[2] = 1.0;
}
-
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(0.0, 0.0, -20.0);
+ /* Draw the background (this is done before setting up rotations) */
+ /* Set up "private" projection matrix */
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho(-aspect*3.0, aspect*3.0, -3.0, 3.0, 0.001, 21.0);
+ /* Draw background plane */
+ glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, black);
+ glMaterialfv(GL_FRONT, GL_SPECULAR, black);
+ glMaterialf(GL_FRONT, GL_SHININESS, 0.0);
+ glBegin(GL_QUADS);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, bg_bot);
+ glVertex3f(-3.0*aspect, -3.0, 0.0);
+ glVertex3f(+3.0*aspect, -3.0, 0.0);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, bg_top);
+ glVertex3f(+3.0*aspect, +3.0, 0.0);
+ glVertex3f(-3.0*aspect, +3.0, 0.0);
+ glEnd();
+ /* Restore the old projection matrix */
+ glPopMatrix();
+ glClear(GL_DEPTH_BUFFER_BIT);
+
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
-
+
/* Set up lighting */
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
-
+
/* The z component of this makes no difference if the projection is orthographic,
* but controls zoom when perspective is used */
glTranslatef(0.0, 0.0, -400.0);
@@ -726,24 +726,24 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
-
+
if ( dw->mode == DW_MAPPED ) {
-
+
/* Draw the "measured" reflections */
if ( dw->gl_ref_num_vertices ) {
-
+
GLfloat att[] = {1.0, 1.0, 0.0};
-
+
glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, att);
glPointSize(20.0);
glEnable(GL_POINT_SMOOTH);
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
glColor3f(0.0, 0.0, 0.0);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0);
-
+
if ( dw->gl_use_buffers ) {
glBindBuffer(GL_ARRAY_BUFFER, dw->gl_ref_vertex_buffer);
glVertexPointer(3, GL_FLOAT, 0, NULL);
@@ -756,20 +756,20 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
glNormalPointer(GL_FLOAT, 0, dw->gl_ref_normal_array);
glDrawArrays(GL_POINTS, 0, dw->gl_ref_num_vertices);
}
-
+
glDisable(GL_POINT_SMOOTH);
-
+
}
-
+
/* Draw marker points */
if ( dw->gl_marker_num_vertices ) {
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0);
glColor3f(0.0, 0.0, 1.0);
-
+
if ( dw->gl_use_buffers ) {
glBindBuffer(GL_ARRAY_BUFFER, dw->gl_marker_vertex_buffer);
glVertexPointer(3, GL_FLOAT, 0, NULL);
@@ -782,20 +782,20 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
glNormalPointer(GL_FLOAT, 0, dw->gl_marker_normal_array);
glDrawArrays(GL_QUADS, 0, dw->gl_marker_num_vertices);
}
-
+
}
-
+
} else {
/* Draw generated reflections */
if ( dw->gl_gen_num_vertices ) {
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, gold);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0);
glColor3f(0.7, 0.7, 0.0);
-
+
if ( dw->gl_use_shaders ) glUseProgram(dw->gl_program_lightpp);
if ( dw->gl_use_buffers ) {
glBindBuffer(GL_ARRAY_BUFFER, dw->gl_gen_vertex_buffer);
@@ -810,19 +810,19 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
glDrawArrays(GL_QUADS, 0, dw->gl_gen_num_vertices);
}
if ( dw->gl_use_shaders ) glUseProgram(0);
-
+
}
-
+
}
glDisable(GL_NORMAL_ARRAY);
-
+
/* Draw indexing lines */
if ( dw->lines && dw->gl_line_num_vertices ) {
-
+
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, grey);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, black);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
-
+
if ( dw->gl_use_buffers ) {
glBindBuffer(GL_ARRAY_BUFFER, dw->gl_line_vertex_buffer);
glVertexPointer(3, GL_FLOAT, 0, NULL);
@@ -833,18 +833,18 @@ gint glbits_expose(GtkWidget *widget, GdkEventExpose *event, DisplayWindow *dw)
glDrawArrays(GL_LINES, 0, dw->gl_line_num_vertices);
}
}
-
+
glPopClientAttrib();
-
+
/* Draw everything else */
glCallList(dw->gl_list_id);
-
+
if ( gdk_gl_drawable_is_double_buffered(gldrawable) ) {
gdk_gl_drawable_swap_buffers(gldrawable);
} else {
glFlush();
}
-
+
gdk_gl_drawable_gl_end(gldrawable);
return TRUE;
@@ -857,29 +857,29 @@ gboolean glbits_configure(GtkWidget *widget, GdkEventConfigure *event, DisplayWi
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);
GLfloat w = widget->allocation.width;
GLfloat h = widget->allocation.height;
-
+
/* Set viewport */
if ( !gdk_gl_drawable_gl_begin(gldrawable, glcontext) ) {
return FALSE;
}
glViewport(0, 0, w, h);
-
+
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_SMOOTH);
glEnable(GL_LINE_SMOOTH);
-
+
/* Nudge the projection matrix routines to preserve the aspect ratio */
if ( dw->view == DW_ORTHO ) {
glbits_set_ortho(dw, w, h);
} else {
glbits_set_perspective(dw, w, h);
}
-
+
gdk_gl_drawable_gl_end(gldrawable);
-
+
return FALSE;
}
@@ -904,7 +904,7 @@ void glbits_free_resources(DisplayWindow *dw) {
if ( dw->gl_line_vertex_array != NULL ) free(dw->gl_line_vertex_array);
}
glDeleteLists(dw->gl_list_id, 1);
-
+
}
void glbits_final_free_resources(DisplayWindow *dw) {
@@ -923,22 +923,21 @@ gint glbits_realise(GtkWidget *widget, DisplayWindow *dw) {
GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);
GLfloat w = widget->allocation.width;
GLfloat h = widget->allocation.height;
-
+
if ( !gdk_gl_drawable_gl_begin(gldrawable, glcontext) ) {
return 0;
}
-
+
/* This has to be done once an OpenGL context has been created */
GLenum glew_err = glewInit();
if (glew_err != GLEW_OK) fprintf(stderr, "GLEW initialisation error: %s\n", glewGetErrorString(glew_err));
-
+
glbits_set_ortho(dw, w, h);
glbits_first_prepare(dw);
dw->realised = 1;
-
+
gdk_gl_drawable_gl_end(gldrawable);
return 0;
}
-