From adfa666208bbf720e0dd33602661384b146e5268 Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sun, 19 Feb 2012 17:46:50 +0100 Subject: FBO example added --- samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c') diff --git a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c index 643c0ca..d918f0b 100644 --- a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c +++ b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c @@ -62,7 +62,7 @@ static const GLchar *fragment_shader_source = " vec2 mod_texcoord = gl_TexCoord[0].st*vec2(1., 2.) + vec2(0, -0.5 + 0.5*sin(T + 1.5*ts*pi));\n" " if( mod_texcoord.t < 0. || mod_texcoord.t > 1. ) { discard; }\n" " gl_FragColor = -texture2D(texCMYK, mod_texcoord) + texture2D(texRGB, gl_TexCoord[0].st);\n" -" gl_FragColor.a = -0.5;\n" +" gl_FragColor.a = 1.;\n" "}\n\0"; GLuint shaderFragment = 0; -- cgit v1.3.1 From 4842cb28522a89c0a6d800139b934001484fadbe Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Fri, 26 Jul 2013 11:14:54 +0200 Subject: ... --- samples/OpenGL/frustum/frustum.c | 12 ++++++ samples/OpenGL/qt_terr/Makefile | 2 +- samples/OpenGL/qt_terr/main.cpp | 38 ++++++++---------- samples/OpenGL/qt_terr/quad.h | 2 +- samples/OpenGL/qt_terr/terragen.cpp | 2 +- samples/OpenGL/qt_terr/terragen.h | 4 +- samples/OpenGL/qt_terr/terrain.cpp | 29 ++++++-------- samples/OpenGL/qt_terr/terrain.h | 13 +++++-- .../x11argb_opengl_glsl/x11argb_opengl_glsl.c | 45 +++++++++++++++++++--- 9 files changed, 95 insertions(+), 52 deletions(-) (limited to 'samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c') 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 #include +#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 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(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*); std::vector * 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 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(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 +#include 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* 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() -- cgit v1.3.1 From de232895ac390d09ed242deaadbccbe4812b15bd Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Fri, 26 Jul 2013 11:23:13 +0200 Subject: added glXCreateContextAttrib to x11argb_opengl_glsl example --- samples/OpenGL/x11argb_opengl_glsl/Makefile | 9 ++++- .../x11argb_opengl_glsl/x11argb_opengl_glsl.c | 39 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c') diff --git a/samples/OpenGL/x11argb_opengl_glsl/Makefile b/samples/OpenGL/x11argb_opengl_glsl/Makefile index b59feea..62e3496 100644 --- a/samples/OpenGL/x11argb_opengl_glsl/Makefile +++ b/samples/OpenGL/x11argb_opengl_glsl/Makefile @@ -1,3 +1,10 @@ +.PHONY: all + +all: x11argb_opengl_glsl x11argb_opengl_glsl3 + x11argb_opengl_glsl: x11argb_opengl_glsl.c Makefile - clang -std=c99 -g3 -o x11argb_opengl_glsl x11argb_opengl_glsl.c -lX11 -lXrender -lGLEW -lm + cc -std=c99 -g3 -o x11argb_opengl_glsl x11argb_opengl_glsl.c -lX11 -lXrender -lGLEW -lm + +x11argb_opengl_glsl3: x11argb_opengl_glsl.c Makefile + cc -std=c99 -g3 -o x11argb_opengl_glsl3 -D USE_GLX_CREATE_CONTEXT_ATTRIB x11argb_opengl_glsl.c -lX11 -lXrender -lGLEW -lm diff --git a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c index 3c5908b..b658f5c 100644 --- a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c +++ b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c @@ -130,6 +130,37 @@ static void fatalError(const char *why) exit(0x666); } +static int isExtensionSupported(const char *extList, const char *extension) +{ + + const char *start; + const char *where, *terminator; + + /* Extension names should not have spaces. */ + where = strchr(extension, ' '); + if ( where || *extension == '\0' ) + return 0; + + /* It takes a bit of care to be fool-proof about parsing the + OpenGL extensions string. Don't be fooled by sub-strings, + etc. */ + for ( start = extList; ; ) { + where = strstr( start, extension ); + + if ( !where ) + break; + + terminator = where + strlen( extension ); + + if ( where == start || *(where - 1) == ' ' ) + if ( *terminator == ' ' || *terminator == '\0' ) + return 1; + + start = terminator; + } + return 0; +} + static int Xscreen; static Atom del_atom; static Colormap cmap; @@ -304,6 +335,12 @@ static void createTheWindow() } } +static int ctxErrorHandler( Display *dpy, XErrorEvent *ev ) +{ + fputs("Error at context creation", stderr); + return 0; +} + static void createTheRenderContext() { int dummy; @@ -356,6 +393,8 @@ static void createTheRenderContext() if (!glXMakeContextCurrent(Xdisplay, glX_window_handle, glX_window_handle, render_context)) { fatalError("glXMakeCurrent failed for window\n"); } + + glewInit(); } static int updateTheMessageQueue() -- cgit v1.3.1 From 987f70c8e9b1bab87647d4ed20df79900d6c0c9e Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sat, 14 Sep 2013 15:59:51 +0200 Subject: X11 clobberable window added --- samples/OpenGL/x11argb_opengl/x11argb_opengl.c | 10 ++ .../x11argb_opengl_glsl/x11argb_opengl_glsl.c | 14 ++ samples/X11/clobberme/Makefile | 3 + samples/X11/clobberme/clobberme.c | 171 +++++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 samples/X11/clobberme/Makefile create mode 100644 samples/X11/clobberme/clobberme.c (limited to 'samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c') diff --git a/samples/OpenGL/x11argb_opengl/x11argb_opengl.c b/samples/OpenGL/x11argb_opengl/x11argb_opengl.c index 1c1e2e0..723c6ae 100644 --- a/samples/OpenGL/x11argb_opengl/x11argb_opengl.c +++ b/samples/OpenGL/x11argb_opengl/x11argb_opengl.c @@ -23,12 +23,16 @@ \_____/ FTB. ------------------------------------------------------------------------*/ +#define _GNU_SOURCE #include #include #include #include +#include +#include + #include #include #include @@ -461,7 +465,13 @@ static void redrawTheWindow() b = fmod(b+0.5, 360.); c = fmod(c+0.25, 360.); + struct timespec Ta, Tb; + + clock_gettime(CLOCK_MONOTONIC_RAW, &Ta); glXSwapBuffers(Xdisplay, glX_window_handle); + clock_gettime(CLOCK_MONOTONIC_RAW, &Tb); + + fprintf(stderr, "glXSwapBuffers returned after %f ms\n", 1e3*((double)Tb.tv_sec + 1e-6*(double)Tb.tv_nsec) - 1e3*((double)Ta.tv_sec + 1e-6*(double)Ta.tv_nsec)); } int main(int argc, char *argv[]) diff --git a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c index b658f5c..0852cbc 100644 --- a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c +++ b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c @@ -24,12 +24,17 @@ ------------------------------------------------------------------------*/ +#define _GNU_SOURCE + #include #include #include #include #include +#include +#include + #include #include #include @@ -571,7 +576,16 @@ static void redrawTheWindow(double T) draw_cube(); popModelview(); + struct timespec Ta, Tb; + + clock_gettime(CLOCK_MONOTONIC_RAW, &Ta); glXSwapBuffers(Xdisplay, glX_window_handle); + glXWaitGL(); + clock_gettime(CLOCK_MONOTONIC_RAW, &Tb); + + fprintf(stderr, "glXSwapBuffers + glXWaitGL returned after %f ms\n", + 1e3*( (double)Tb.tv_sec + 1e-9*(double)Tb.tv_nsec ) - + 1e3*( (double)Ta.tv_sec + 1e-9*(double)Ta.tv_nsec ) ); } static double getftime(void) { diff --git a/samples/X11/clobberme/Makefile b/samples/X11/clobberme/Makefile new file mode 100644 index 0000000..52dfca8 --- /dev/null +++ b/samples/X11/clobberme/Makefile @@ -0,0 +1,3 @@ +clobberme: clobberme.c Makefile + $(CC) -o clobberme -lX11 clobberme.c + diff --git a/samples/X11/clobberme/clobberme.c b/samples/X11/clobberme/clobberme.c new file mode 100644 index 0000000..ac58dc5 --- /dev/null +++ b/samples/X11/clobberme/clobberme.c @@ -0,0 +1,171 @@ +/*------------------------------------------------------------------------ + * A demonstration of a clobberable X11 window, i.e. a window that will + * assume the contents of whatever was visible above it, without clearing + * or tidying up itself. + * + * (c) 2013 by Wolfgang 'datenwolf' Draxinger + + * License agreement: This source code is provided "as is". You + * can use this source code however you want for your own personal + * use. If you give this source code to anybody else then you must + * leave this message in it. +------------------------------------------------------------------------*/ +#define _GNU_SOURCE + +#include +#include +#include +#include + +#include +#include + +#include +#include + +static void fatalError(const char *why) +{ + fprintf(stderr, "%s", why); + exit(0x666); +} + +static int Xscreen; +static Atom del_atom; +static Colormap cmap; +static Display *Xdisplay; +static Visual *Xvisual; +static Window Xroot, window_handle; +static int width, height; + +static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg) +{ + return d && e && arg && (e->type == MapNotify) && (e->xmap.window == *(Window*)arg); +} + +static void createTheWindow() +{ + XEvent event; + int x,y, attr_mask; + XSizeHints hints; + XWMHints *startup_state; + XTextProperty textprop; + XSetWindowAttributes attr = {0,}; + static char *title = "FTB's little OpenGL example - ARGB extension by WXD"; + + Xdisplay = XOpenDisplay(NULL); + if (!Xdisplay) { + fatalError("Couldn't connect to X server\n"); + } + Xscreen = DefaultScreen(Xdisplay); + Xroot = RootWindow(Xdisplay, Xscreen); + Xvisual = DefaultVisual(Xdisplay, Xscreen); + + /* Create a colormap - only needed on some X clients, eg. IRIX */ + cmap = XCreateColormap(Xdisplay, Xroot, Xvisual, AllocNone); + + attr.colormap = cmap; + attr.background_pixmap = None; + attr.border_pixmap = None; + attr.border_pixel = 0; + attr.event_mask = + StructureNotifyMask | + EnterWindowMask | + LeaveWindowMask | + ExposureMask | + ButtonPressMask | + ButtonReleaseMask | + OwnerGrabButtonMask | + KeyPressMask | + KeyReleaseMask; + + attr_mask = 0 + // | CWBackPixmap + | CWColormap + // | CWBorderPixel + | CWEventMask ; + + width = DisplayWidth(Xdisplay, DefaultScreen(Xdisplay))/2; + height = DisplayHeight(Xdisplay, DefaultScreen(Xdisplay))/2; + x=width/2, y=height/2; + + window_handle = XCreateWindow( Xdisplay, + Xroot, + x, y, width, height, + 0, + CopyFromParent, + InputOutput, + Xvisual, + attr_mask, &attr); + + if( !window_handle ) { + fatalError("Couldn't create the window\n"); + } + + textprop.value = (unsigned char*)title; + textprop.encoding = XA_STRING; + textprop.format = 8; + textprop.nitems = strlen(title); + + hints.x = x; + hints.y = y; + hints.width = width; + hints.height = height; + hints.flags = USPosition|USSize; + + startup_state = XAllocWMHints(); + startup_state->initial_state = NormalState; + startup_state->flags = StateHint; + + XSetWMProperties(Xdisplay, window_handle,&textprop, &textprop, + NULL, 0, + &hints, + startup_state, + NULL); + + XFree(startup_state); + + XMapWindow(Xdisplay, window_handle); + XIfEvent(Xdisplay, &event, WaitForMapNotify, (char*)&window_handle); + + if ((del_atom = XInternAtom(Xdisplay, "WM_DELETE_WINDOW", 0)) != None) { + XSetWMProtocols(Xdisplay, window_handle, &del_atom, 1); + } +} + +static int updateTheMessageQueue() +{ + XEvent event; + XConfigureEvent *xc; + + while (XPending(Xdisplay)) + { + XNextEvent(Xdisplay, &event); + switch (event.type) + { + case ClientMessage: + if (event.xclient.data.l[0] == del_atom) + { + return 0; + } + break; + + case ConfigureNotify: + xc = &(event.xconfigure); + width = xc->width; + height = xc->height; + break; + } + } + return 1; +} + +int main(int argc, char *argv[]) +{ + createTheWindow(); + + while (updateTheMessageQueue()) { + } + + return 0; +} + -- cgit v1.3.1 From 4542fdb44ae7525b2806233b1d499b1c0202fbf7 Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sat, 26 Apr 2014 18:21:56 +0200 Subject: rotateable observer --- .gitmodules | 3 +++ extra/linmath.h | 1 + samples/OpenGL/frustum/frustum.c | 23 ++++++++++++++++++++-- samples/OpenGL/minimal_glsl/minimal_glsl.c | 2 +- .../x11argb_opengl_glsl/x11argb_opengl_glsl.c | 8 +------- 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 .gitmodules create mode 160000 extra/linmath.h (limited to 'samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c') diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d03f608 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "extra/linmath.h"] + path = extra/linmath.h + url = git@github.com:datenwolf/linmath.h.git diff --git a/extra/linmath.h b/extra/linmath.h new file mode 160000 index 0000000..f7418fa --- /dev/null +++ b/extra/linmath.h @@ -0,0 +1 @@ +Subproject commit f7418faa1bffa56a5754f98dcc628fcfbf8606c5 diff --git a/samples/OpenGL/frustum/frustum.c b/samples/OpenGL/frustum/frustum.c index c5732c8..2728cee 100644 --- a/samples/OpenGL/frustum/frustum.c +++ b/samples/OpenGL/frustum/frustum.c @@ -412,6 +412,23 @@ struct { float near, far; } frustum = {-1, 1, -1, 1, 1, 4}; +struct { + struct { + float phi, theta; + } rot; +} observer; + +void observer_motion(int x, int y) +{ + int const win_width = glutGet(GLUT_WINDOW_WIDTH); + int const win_height = glutGet(GLUT_WINDOW_HEIGHT); + + observer.rot.phi = -180.f + 360.f * (float)x / (float)win_width; + observer.rot.theta = -90.f + 180.f * (float)y / (float)win_height; + + glutPostRedisplay(); +} + void display_observer(float frustum_aspect) { int const win_width = glutGet(GLUT_WINDOW_WIDTH); @@ -434,8 +451,8 @@ void display_observer(float frustum_aspect) glLoadIdentity(); if(1) { glTranslatef(0, 0, -10); - glRotatef(15, 1, 0, 0); - glRotatef(-15, 0, 1, 0); + glRotatef(observer.rot.theta, 1, 0, 0); + glRotatef(observer.rot.phi, 0, 1, 0); glTranslatef(0, 0, 2.5); } else { gluLookAt(3, 1, -5, 0, 0, -2.5, 0, 1, 0); @@ -536,6 +553,8 @@ int main(int argc, char *argv[]) window_observer = glutCreateWindow("Observer"); glutDisplayFunc(display); + glutMotionFunc(observer_motion); + glutPassiveMotionFunc(observer_motion); window_view = glutCreateWindow("Frustum View"); glutDisplayFunc(display); diff --git a/samples/OpenGL/minimal_glsl/minimal_glsl.c b/samples/OpenGL/minimal_glsl/minimal_glsl.c index 2d1b0fa..72ba3ff 100644 --- a/samples/OpenGL/minimal_glsl/minimal_glsl.c +++ b/samples/OpenGL/minimal_glsl/minimal_glsl.c @@ -38,7 +38,7 @@ static const GLchar *fragment_shader_source = "uniform sampler2D texRGB;" "void main()" "{" -" gl_FragColor = -texture2D(texCMYK, gl_TexCoord[0].st) + texture2D(texRGB, gl_TexCoord[0].st);" +" gl_FragColor = -texture2D(texCMYK, gl_TexCoord[0].st) + texture2D(texRGB, gl_TexCoord[0].st); " "}\0"; GLuint shaderFragment = 0; diff --git a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c index 0852cbc..7aae5a8 100644 --- a/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c +++ b/samples/OpenGL/x11argb_opengl_glsl/x11argb_opengl_glsl.c @@ -578,14 +578,8 @@ static void redrawTheWindow(double T) struct timespec Ta, Tb; - clock_gettime(CLOCK_MONOTONIC_RAW, &Ta); glXSwapBuffers(Xdisplay, glX_window_handle); - glXWaitGL(); - clock_gettime(CLOCK_MONOTONIC_RAW, &Tb); - - fprintf(stderr, "glXSwapBuffers + glXWaitGL returned after %f ms\n", - 1e3*( (double)Tb.tv_sec + 1e-9*(double)Tb.tv_nsec ) - - 1e3*( (double)Ta.tv_sec + 1e-9*(double)Ta.tv_nsec ) ); + glXWaitGL(); } static double getftime(void) { -- cgit v1.3.1