Hello,
I think I worked out why I had trouble getting a sample with two GLX
contexts to work: the bug in Mesa-3.1beta2 is actually more severe
than I thought. The adapted `isosurf.c' sample below shows just a
black first window with Mesa-3.1beta2. At first I thought this was
due to my missing glut knowledge, but it seems to run just fine simply
by setting LD_LIBRARY_PATH=/pkg/Mesa-3.0/lib on my Linux PC (standard
X11 Mesa driver): two windows containing the isosurface side by side,
and independently rotatable.
Sorry for the somewhat long attachment...
Regards,
Wolfram.
/*
* Display an isosurface of 3-D wind speed volume. Use arrow keys to
* rotate, S toggles smooth shading, L toggles lighting
* Brian Paul This file in public domain.
*/
/*
* Added second window (WG Sep 1999)
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "GL/glut.h"
GLboolean use_vertex_arrays = GL_FALSE;
GLboolean doubleBuffer = GL_TRUE;
GLboolean smooth = GL_TRUE;
GLboolean lighting = GL_TRUE;
#define MAXVERTS 10000
static GLfloat verts[MAXVERTS][3];
static GLfloat norms[MAXVERTS][3];
static GLint numverts;
struct win_state {
GLfloat xrot;
GLfloat yrot;
};
struct win_state ws1, ws2;
int debug = 0;
static void read_surface( char *filename )
{
FILE *f;
f = fopen(filename,"r");
if (!f) {
printf("couldn't read %s\n", filename);
exit(1);
}
numverts = 0;
while (!feof(f) && numverts<MAXVERTS) {
fscanf( f, "%f %f %f %f %f %f",
&verts[numverts][0], &verts[numverts][1], &verts[numverts][2],
&norms[numverts][0], &norms[numverts][1], &norms[numverts][2] );
numverts++;
}
numverts--;
printf("%d vertices, %d triangles\n", numverts, numverts-2);
fclose(f);
}
static void draw_surface( void )
{
GLuint i;
#ifdef GL_EXT_vertex_array
if (use_vertex_arrays) {
glDrawArraysEXT( GL_TRIANGLE_STRIP, 0, numverts );
}
else {
#endif
glBegin( GL_TRIANGLE_STRIP );
for (i=0;i<numverts;i++) {
glNormal3fv( norms[i] );
glVertex3fv( verts[i] );
}
glEnd();
#ifdef GL_EXT_vertex_array
}
#endif
}
static void
Display(const struct win_state* ws)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glRotatef( ws->yrot, 0.0, 1.0, 0.0 );
glRotatef( ws->xrot, 1.0, 0.0, 0.0 );
draw_surface();
glPopMatrix();
glFlush();
if (doubleBuffer) {
glutSwapBuffers();
}
}
static void Display1(void)
{
if(debug)
printf("D1\n");
Display(&ws1);
}
static void Display2(void)
{
if(debug)
printf("D2\n");
Display(&ws2);
}
static void Benchmark( void )
{
int startTime, endTime;
int draws;
double seconds, fps, triPerSecond;
printf("Benchmarking...\n");
draws = 0;
startTime = glutGet(GLUT_ELAPSED_TIME);
ws1.xrot = 0.0;
do {
Display1();
ws1.xrot += 5.0;
draws++;
endTime = glutGet(GLUT_ELAPSED_TIME);
} while (endTime - startTime < 5000); /* 5 seconds */
/* Results */
seconds = (double) (endTime - startTime) / 1000.0;
triPerSecond = (numverts - 2) * draws / seconds;
fps = draws / seconds;
printf("Result: triangles/sec: %g fps: %g\n", triPerSecond, fps);
}
static void InitMaterials(void)
{
static float ambient[] = {0.1, 0.1, 0.1, 1.0};
static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
static float position0[] = {0.0, 0.0, 20.0, 0.0};
static float position1[] = {0.0, 0.0, -20.0, 0.0};
static float front_mat_shininess[] = {60.0};
static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
static float lmodel_twoside[] = {GL_FALSE};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
glEnable(GL_LIGHT1);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
glEnable(GL_LIGHTING);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_mat_shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_mat_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, front_mat_diffuse);
}
static void Init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
InitMaterials();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum( -1.0, 1.0, -1.0, 1.0, 5, 25 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef( 0.0, 0.0, -6.0 );
#ifdef GL_EXT_vertex_array
if (use_vertex_arrays) {
glVertexPointerEXT( 3, GL_FLOAT, 0, numverts, verts );
glNormalPointerEXT( GL_FLOAT, 0, numverts, norms );
glEnable( GL_VERTEX_ARRAY_EXT );
glEnable( GL_NORMAL_ARRAY_EXT );
}
#endif
}
static void Reshape(int width, int height)
{
glViewport(0, 0, (GLint)width, (GLint)height);
}
static void Key( unsigned char key, int x, int y )
{
switch (key) {
case 27:
exit(0);
case 's':
smooth = !smooth;
if (smooth) {
glShadeModel(GL_SMOOTH);
}
else {
glShadeModel(GL_FLAT);
}
break;
case 'l':
lighting = !lighting;
if (lighting) {
glEnable(GL_LIGHTING);
}
else {
glDisable(GL_LIGHTING);
}
break;
case 'b':
Benchmark();
break;
}
glutPostRedisplay();
}
static void SpecialKey(struct win_state* ws, int key, int x, int y)
{
switch (key) {
case GLUT_KEY_LEFT:
ws->yrot -= 15.0;
break;
case GLUT_KEY_RIGHT:
ws->yrot += 15.0;
break;
case GLUT_KEY_UP:
ws->xrot += 15.0;
break;
case GLUT_KEY_DOWN:
ws->xrot -= 15.0;
break;
}
glutPostRedisplay();
}
static void
SpecialKey1(int key, int x, int y)
{
if(debug)
printf("S1\n");
SpecialKey(&ws1, key, x, y);
}
static void
SpecialKey2(int key, int x, int y)
{
if(debug)
printf("S2\n");
SpecialKey(&ws2, key, x, y);
}
static GLenum Args(int argc, char **argv)
{
GLint i;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-sb") == 0) {
doubleBuffer = GL_FALSE;
}
else if (strcmp(argv[i], "-db") == 0) {
doubleBuffer = GL_TRUE;
}
else if (strcmp(argv[i], "-va") == 0) {
use_vertex_arrays = GL_TRUE;
}
else {
printf("%s (Bad option).\n", argv[i]);
return GL_FALSE;
}
}
return GL_TRUE;
}
int main(int argc, char **argv)
{
GLenum type;
char *extensions;
read_surface( "isosurf.dat" );
if (Args(argc, argv) == GL_FALSE) {
exit(0);
}
type = GLUT_DEPTH;
type |= GLUT_RGB;
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
glutInitDisplayMode(type);
glutInitWindowPosition(0, 0);
glutInitWindowSize(400, 400);
if (glutCreateWindow("Isosurface1") <= 0) {
exit(0);
}
/* Make sure server supports the vertex array extension */
extensions = (char *) glGetString( GL_EXTENSIONS );
if (!strstr( extensions, "GL_EXT_vertex_array" )) {
use_vertex_arrays = GL_FALSE;
}
Init();
glutKeyboardFunc(Key);
glutSpecialFunc(SpecialKey1);
glutDisplayFunc(Display1);
#if 1
glutInitWindowPosition(400, 0);
glutInitWindowSize(400, 400);
if (glutCreateWindow("Isosurface2") <= 0) {
exit(0);
}
Init();
glutKeyboardFunc(Key);
glutSpecialFunc(SpecialKey2);
glutDisplayFunc(Display2);
#endif
glutMainLoop();
return 0;
}
--
`Surf the sea, not double-u three...'
[EMAIL PROTECTED]
_______________________________________________
Mesa-dev maillist - [EMAIL PROTECTED]
http://lists.mesa3d.org/mailman/listinfo/mesa-dev