aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--samples/OpenGL/frustum/frustum.c12
-rw-r--r--samples/OpenGL/qt_terr/Makefile2
-rw-r--r--samples/OpenGL/qt_terr/main.cpp38
-rw-r--r--samples/OpenGL/qt_terr/quad.h2
-rw-r--r--samples/OpenGL/qt_terr/terragen.cpp2
-rw-r--r--samples/OpenGL/qt_terr/terragen.h4
-rw-r--r--samples/OpenGL/qt_terr/terrain.cpp29
-rw-r--r--samples/OpenGL/qt_terr/terrain.h13
-rw-r--r--samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c45
9 files changed, 95 insertions, 52 deletions
diff --git a/samples/OpenGL/frustum/frustum.c b/samples/OpenGL/frustum/frustum.c
index 51efb7e..c5732c8 100644
--- a/samples/OpenGL/frustum/frustum.c
+++ b/samples/OpenGL/frustum/frustum.c
@@ -11,6 +11,8 @@
#include <GL/glu.h>
#include <GL/glut.h>
+#include "linmath.h"
+
#if defined(GLUT_MULTISAMPLE) && defined(GL_MULTISAMPLE)
#define OPTION_GLUT_MULTISAMPLE GLUT_MULTISAMPLE
#define OPTION_MULTISAMPLE 1
@@ -208,6 +210,16 @@ void draw_arrow(
}
}
+void draw_arc(
+ vec3 center,
+ vec3 a, vec3 b,
+ float ah, float bh,
+ char const * const annotation,
+ float annot_size )
+{
+ a[0] = b[2];
+}
+
void draw_frustum(
float l, float r, float b, float t,
float n, float f )
diff --git a/samples/OpenGL/qt_terr/Makefile b/samples/OpenGL/qt_terr/Makefile
index 1f9c52b..22ecad9 100644
--- a/samples/OpenGL/qt_terr/Makefile
+++ b/samples/OpenGL/qt_terr/Makefile
@@ -1,6 +1,6 @@
CC = gcc
CPP = g++
-OBJS += main.o quad.o terragen.o terrain.o vecmath.o
+OBJS += quad.o terragen.o terrain.o vecmath.o main.o
qt_terr: $(OBJS)
$(CPP) -o qt_terr $(OBJS) -lm -lGL -lGLU -lGLEW -lglut -lIL -lILU -lILUT
diff --git a/samples/OpenGL/qt_terr/main.cpp b/samples/OpenGL/qt_terr/main.cpp
index 64c4327..e8bf78e 100644
--- a/samples/OpenGL/qt_terr/main.cpp
+++ b/samples/OpenGL/qt_terr/main.cpp
@@ -20,7 +20,8 @@ using namespace std;
#include "terragen.h"
#include "terrain.h"
-Terrain Q;
+std::vector<double> terraindata;
+Terrain Q(&terraindata);
double const water_level=-1.0;
@@ -92,7 +93,7 @@ int main(int argc, char **argv)
std::string img_filename( terrain_filename );
img_filename.replace(img_filename.length()-5, 4, ".png");
- texID=ilutGLLoadImage(img_filename.c_str());
+ texID = ilutGLLoadImage((char*)img_filename.c_str());
glBindTexture(GL_TEXTURE_2D, texID);
int x, y;
@@ -174,12 +175,6 @@ void assign_elevations(Terrain *pT, double *buffer, int width, int height, doubl
pT->z[1][1]=( buffer[ PEL(right+top*width) ] -t )*k;
pT->z[1][0]=( buffer[ PEL(left+top*width) ] -t )*k;
- pT->z_mean=(
- pT->z[0][0]+
- pT->z[0][1]+
- pT->z[1][1]+
- pT->z[1][0])*0.25;
-
if(pT->is_split())
{
assign_elevations((Terrain*)pT->quads[0][0], buffer, width, height, t, k,
@@ -291,7 +286,7 @@ void keyboard(unsigned char key, int x, int y)
glutPostRedisplay();
}
-void draw_quad(Terrain *pQ, int LOD=0, double z1=0, double z2=0, double z3=0, double z4=0);
+void draw_quad(Quad *pQ, int LOD=0, double z1=0, double z2=0, double z3=0, double z4=0);
GLdouble cam_pos[3];//={68.0f*scale[0], 44.0f*scale[1], 47.7*scale[2]*0.5};
double cam_la[3];
@@ -328,8 +323,8 @@ void display()
cam_pos[0]=dx*width*scale[0];
cam_pos[1]=dy*height*scale[1];
- cam_pos[2]=max(dz*scale[2]*width*3, (20.0f+((Terrain*)Q.get_at(dx, dy))->z_mean)*scale[2]);
- //cam_pos[2]=(20.0f+((Terrain*)Q.get_at(dx, dy))->z_mean)*scale[2];
+ cam_pos[2]=max(dz*scale[2]*width*3, (20.0f+((Terrain*)Q.get_at(dx, dy))->z_mean())*scale[2]);
+ //cam_pos[2]=(20.0f+((Terrain*)Q.get_at(dx, dy))->z_mean())*scale[2];
cam_la[0]=width*scale[0]*0.5;
cam_la[1]=height*scale[1]*0.5;
@@ -420,16 +415,17 @@ bool in_view(double a[3])
return false;
}
-void draw_quad(Terrain *pT, int LOD, double z1, double z2, double z3, double z4)
+void draw_quad(Quad *pQ, int LOD, double z1, double z2, double z3, double z4)
{
+ Terrain *pT = dynamic_cast<Terrain*>(pQ);
bool bRefine=true;
bool bInFront=true;
- double Q[3]={pT->x_mid*width*scale[0], pT->y_mid*height*scale[1], pT->z_mean*scale[2]};
- double Q1[3]={pT->x1*width*scale[0], pT->y1*height*scale[1], pT->z[0][0]*scale[2]};
- double Q2[3]={pT->x2*width*scale[0], pT->y1*height*scale[1], pT->z[0][1]*scale[2]};
- double Q3[3]={pT->x2*width*scale[0], pT->y2*height*scale[1], pT->z[1][1]*scale[2]};
- double Q4[3]={pT->x1*width*scale[0], pT->y2*height*scale[1], pT->z[1][0]*scale[2]};
+ double Q[3] ={(*pT->x_mid())*width*scale[0], (*pT->y_mid())*height*scale[1], (pT->z_mean())*scale[2]};
+ double Q1[3]={(*pT->x1())*width*scale[0], (*pT->y1())*height*scale[1], (pT->z[0][0])*scale[2]};
+ double Q2[3]={(*pT->x2())*width*scale[0], (*pT->y1())*height*scale[1], (pT->z[0][1])*scale[2]};
+ double Q3[3]={(*pT->x2())*width*scale[0], (*pT->y2())*height*scale[1], (pT->z[1][1])*scale[2]};
+ double Q4[3]={(*pT->x1())*width*scale[0], (*pT->y2())*height*scale[1], (pT->z[1][0])*scale[2]};
double Qt[3];
double dir[3];
@@ -563,19 +559,19 @@ void draw_quad(Terrain *pT, int LOD, double z1, double z2, double z3, double z4)
else
glColor3f(1,1,1);
//LUM(one_minus_lod_scale[0]);
- glTexCoord2f(pT->x1, pT->y1);
+ glTexCoord2f(*pT->x1(), *pT->y1());
glVertex3dv(Q1);
//LUM(one_minus_lod_scale[1]);
- glTexCoord2f(pT->x2, pT->y1);
+ glTexCoord2f(*pT->x2(), *pT->y1());
glVertex3dv(Q2);
//LUM(one_minus_lod_scale[2]);
- glTexCoord2f(pT->x2, pT->y2);
+ glTexCoord2f(*pT->x2(), *pT->y2());
glVertex3dv(Q3);
//LUM(one_minus_lod_scale[3]);
- glTexCoord2f(pT->x1, pT->y2);
+ glTexCoord2f(*pT->x1(), *pT->y2());
glVertex3dv(Q4);
}
}
diff --git a/samples/OpenGL/qt_terr/quad.h b/samples/OpenGL/qt_terr/quad.h
index 1c6549a..36850e6 100644
--- a/samples/OpenGL/qt_terr/quad.h
+++ b/samples/OpenGL/qt_terr/quad.h
@@ -39,9 +39,9 @@ public:
virtual void track_down(double x, double y, int levels);
virtual Quad *get_at(double x, double y, int max_level=0, int level=0);
-protected:
virtual void set_range(double nx1, double nx2, double ny1, double ny2);
+protected:
Quad(std::vector<double>*);
std::vector<double> * const V;
};
diff --git a/samples/OpenGL/qt_terr/terragen.cpp b/samples/OpenGL/qt_terr/terragen.cpp
index 3b922a4..73c6eaa 100644
--- a/samples/OpenGL/qt_terr/terragen.cpp
+++ b/samples/OpenGL/qt_terr/terragen.cpp
@@ -16,7 +16,7 @@ typedef uint8_t OCTET[8];
#define DUET_TO_NUMBER(duet) ((duet[0]|duet[1]<<8))
#define QUARTET_TO_NUMBER(quartet) ((quartet[0])|(quartet[1]<<8)|(quartet[2]<<16)|(quartet[3]<<24))
-int read_terrain(char *filename, double **pbuffer, int *width, int *height, double *scale)
+int read_terrain(char const *filename, double **pbuffer, int *width, int *height, double *scale)
// [in] filename: path to the file to be read in
// [out] pbuffer: address of new allocated data buffer
// [out] width: width of the terrain
diff --git a/samples/OpenGL/qt_terr/terragen.h b/samples/OpenGL/qt_terr/terragen.h
index 5037a08..a63bc34 100644
--- a/samples/OpenGL/qt_terr/terragen.h
+++ b/samples/OpenGL/qt_terr/terragen.h
@@ -1,6 +1,6 @@
#ifndef TERRAGEN_H
#define TERRAGEN_H
-int read_terrain(char *filename, double **pbuffer, int *width, int *height, double *scale);
+int read_terrain(char const *filename, double **pbuffer, int *width, int *height, double *scale);
-#endif/*TERRAGEN*/ \ No newline at end of file
+#endif/*TERRAGEN*/
diff --git a/samples/OpenGL/qt_terr/terrain.cpp b/samples/OpenGL/qt_terr/terrain.cpp
index d08d345..e18efe4 100644
--- a/samples/OpenGL/qt_terr/terrain.cpp
+++ b/samples/OpenGL/qt_terr/terrain.cpp
@@ -1,10 +1,5 @@
#include "terrain.h"
-Terrain::Terrain()
-{
- z_mean=0.0;
-}
-
void Terrain::split()
{
if(is_split())
@@ -15,29 +10,27 @@ void Terrain::split()
quads[1][0] = new Terrain(V);
quads[1][1] = new Terrain(V);
- quads[0][0]->set_range(x1, x_mid, y1, y_mid);
- quads[0][1]->set_range(x_mid, x2, y1, y_mid);
- quads[1][0]->set_range(x1, x_mid, y_mid, y2);
- quads[1][1]->set_range(x_mid, x2, y_mid, y2);
+ quads[0][0]->set_range(*x1(), *x_mid(), *y1(), *y_mid());
+ quads[0][1]->set_range(*x_mid(), *x2(), *y1(), *y_mid());
+ quads[1][0]->set_range(*x1(), *x_mid(), *y_mid(), *y2());
+ quads[1][1]->set_range(*x_mid(), *x2(), *y_mid(), *y2());
}
void Terrain::track_down(double x, double y, double nz, int levels)
{
- if(levels>0)
- {
- int a=(x<x_mid)?0:1;
- int b=(y<y_mid)?0:1;
+ if( levels > 0 ) {
+ int a = ( x < *x_mid() ) ? 0 : 1;
+ int b = ( y < *y_mid() ) ? 0 : 1;
- if(!is_split())
+ if( !is_split() )
split();
- quads[b][a]->track_down(x, y, nz, levels-1);
+ dynamic_cast<Terrain*>(quads[b][a])->track_down(x, y, nz, levels-1);
}
- else
- {
+ else {
z[0][0]=
z[0][1]=
z[1][1]=
- z[1][0]=z_mean=nz;
+ z[1][0] = z_mean_ = nz;
}
}
diff --git a/samples/OpenGL/qt_terr/terrain.h b/samples/OpenGL/qt_terr/terrain.h
index 0197380..3382a4c 100644
--- a/samples/OpenGL/qt_terr/terrain.h
+++ b/samples/OpenGL/qt_terr/terrain.h
@@ -4,17 +4,24 @@
#include "quad.h"
#include <vector>
+#include <math.h>
class Terrain : public Quad
{
public:
- double * const z_mean() {
-
+ double z_mean_;
+ double z_mean() {
+ if( isnan(z_mean_) ) {
+ return z_mean_ =
+ ( z[0][0] + z[0][1] +
+ z[1][0] + z[1][1] ) / 4.;
+ }
+ return z_mean_;
};
double z[2][2];
public:
- Terrain();
+ Terrain(std::vector<double>* V_) : Quad(V_) { z_mean_ = NAN; }
virtual void split();
virtual void track_down(double x, double y, double nz, int levels);
diff --git a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
index d918f0b..3c5908b 100644
--- a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
+++ b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c
@@ -311,16 +311,51 @@ static void createTheRenderContext()
fatalError("OpenGL not supported by X server\n");
}
- render_context = glXCreateNewContext(Xdisplay, fbconfig, GLX_RGBA_TYPE, 0, True);
- if (!render_context) {
- fatalError("Failed to create a GL context\n");
+#if USE_GLX_CREATE_CONTEXT_ATTRIB
+ #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
+ #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
+ render_context = NULL;
+ if( isExtensionSupported( glXQueryExtensionsString(Xdisplay, DefaultScreen(Xdisplay)), "GLX_ARB_create_context" ) ) {
+ typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
+ glXCreateContextAttribsARBProc glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
+ if( glXCreateContextAttribsARB ) {
+ int context_attribs[] =
+ {
+ GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+ GLX_CONTEXT_MINOR_VERSION_ARB, 0,
+ //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
+ None
+ };
+
+ int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler);
+
+ render_context = glXCreateContextAttribsARB( Xdisplay, fbconfig, 0, True, context_attribs );
+
+ XSync( Xdisplay, False );
+ XSetErrorHandler( oldHandler );
+
+ fputs("glXCreateContextAttribsARB failed", stderr);
+ } else {
+ fputs("glXCreateContextAttribsARB could not be retrieved", stderr);
+ }
+ } else {
+ fputs("glXCreateContextAttribsARB not supported", stderr);
+ }
+
+ if(!render_context)
+ {
+#else
+ {
+#endif
+ render_context = glXCreateNewContext(Xdisplay, fbconfig, GLX_RGBA_TYPE, 0, True);
+ if (!render_context) {
+ fatalError("Failed to create a GL context\n");
+ }
}
if (!glXMakeContextCurrent(Xdisplay, glX_window_handle, glX_window_handle, render_context)) {
fatalError("glXMakeCurrent failed for window\n");
}
-
- glewInit();
}
static int updateTheMessageQueue()