diff options
author | Sven Gothel <[email protected]> | 2010-12-13 02:26:48 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-12-13 02:26:48 +0100 |
commit | 84a76425dd10933a7ad033920a1e0ce12a2a107b (patch) | |
tree | 3f4b1c3d61edb539232bf6bbcf1e673cc011b1d4 /test | |
parent | 519776330c78e296d9868e959ddc64d00acac496 (diff) |
Cleanup test/junit structure. com.jogamp.test -> com.jogamp.opengl.text; Compile posted Issue* Bug* snippets
Diffstat (limited to 'test')
-rw-r--r-- | test/Issue326Test1.java | 92 | ||||
-rw-r--r-- | test/Issue326Test2.java | 71 | ||||
-rw-r--r-- | test/Issue344Base.java | 105 | ||||
-rw-r--r-- | test/Issue344Test1.java | 10 | ||||
-rw-r--r-- | test/Issue344Test2.java | 10 | ||||
-rw-r--r-- | test/Issue344Test3.java | 10 | ||||
-rw-r--r-- | test/Issue344Test4.java | 10 | ||||
-rw-r--r-- | test/native/displayMultiple01.c | 18 | ||||
-rw-r--r-- | test/native/displayMultiple02.c | 113 | ||||
-rw-r--r-- | test/native/glExtensionsListGL2.c | 95 | ||||
-rw-r--r-- | test/native/glExtensionsListGL3.c | 300 | ||||
-rwxr-xr-x | test/native/make.sh | 6 |
12 files changed, 0 insertions, 840 deletions
diff --git a/test/Issue326Test1.java b/test/Issue326Test1.java deleted file mode 100644 index adf2861d0..000000000 --- a/test/Issue326Test1.java +++ /dev/null @@ -1,92 +0,0 @@ -import java.awt.Frame; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Random; - -import javax.media.opengl.GL2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.awt.GLCanvas; -import javax.media.opengl.glu.GLU; - -import com.jogamp.opengl.util.Animator; -import com.jogamp.opengl.util.awt.TextRenderer; - -/** - * Demonstrates corruption with older versions of TextRenderer. Two - * problems: errors when punting from glyph-based renderer to - * string-by-string renderer, and failure of glyph-based renderer when - * backing store was NPOT using GL_ARB_texture_rectangle. - * - * @author emzic - */ - -public class Issue326Test1 extends Frame implements GLEventListener { - - int width, height; - - public static void main(String[] args) { - new Issue326Test1(); - } - - GLCanvas canvas; - TextRenderer tr ; - - public Issue326Test1() { - super("TextTest"); - this.setSize(800, 800); - canvas = new GLCanvas(); - canvas.addGLEventListener(this); - add(canvas); - - setVisible(true); - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); - } - - public void display(GLAutoDrawable drawable) { - GL2 gl = drawable.getGL().getGL2(); - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT); - - - gl.glMatrixMode(GL2.GL_PROJECTION); - gl.glLoadIdentity(); - //new GLU().gluPerspective(45f, (float)width/(float)height, 0.1f, 1000f); - gl.glOrtho(0.0, 800, 0.0, 800, -100.0, 100.0); - gl.glMatrixMode(GL2.GL_MODELVIEW); - gl.glLoadIdentity(); - - tr.beginRendering(800,800); - tr.draw( "die Marktwirtschaft. Da regelt sich � angeblich", 16, 32); - tr.draw( "Hello World! This text is scrambled", 16, 16); - tr.endRendering(); - - } - - public void init(GLAutoDrawable arg0) { - tr = new TextRenderer(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 12), true, false, null, false); - tr.setColor(1, 1, 1 ,1); - } - - public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { - width = arg3; - height = arg4; - GL2 gl = arg0.getGL().getGL2(); - gl.glViewport(0, 0, width, height); - gl.glMatrixMode(GL2.GL_PROJECTION); - gl.glLoadIdentity(); - gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0); - gl.glMatrixMode(GL2.GL_MODELVIEW); - gl.glLoadIdentity(); - } - - public void dispose(GLAutoDrawable drawable) {} -} diff --git a/test/Issue326Test2.java b/test/Issue326Test2.java deleted file mode 100644 index b87eee21b..000000000 --- a/test/Issue326Test2.java +++ /dev/null @@ -1,71 +0,0 @@ -import java.awt.Font; -import java.awt.Frame; -import java.awt.event.*; -import javax.media.opengl.GL2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.awt.GLCanvas; - -import com.jogamp.opengl.util.awt.*; - -/** - * Another test case demonstrating corruption with older version of - * TextRenderer when glyphs were too big for backing store. Font and - * text courtesy of Patrick Murris. Adapted from Issue326Test1. - */ - -public class Issue326Test2 extends Frame implements GLEventListener { - - int width, height; - - public static void main(String[] args) { - new Issue326Test2(); - } - - GLCanvas canvas; - TextRenderer tr; - - public Issue326Test2() { - super(""); - this.setSize(800, 800); - canvas = new GLCanvas(); - canvas.addGLEventListener(this); - add(canvas); - - setVisible(true); - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); - } - - public void display(GLAutoDrawable drawable) { - GL2 gl = drawable.getGL().getGL2(); - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL2.GL_COLOR_BUFFER_BIT|GL2.GL_DEPTH_BUFFER_BIT); - - tr.beginRendering(drawable.getWidth(), drawable.getHeight()); - tr.draw("LA CLAPI\u00c8RE \nAlt: 1100-1700m \nGlissement de terrain majeur", 16, 80); - tr.draw("dans la haute Tin\u00e9e, sur un flanc du Parc du Mercantour.", 16, 16); - tr.endRendering(); - - } - - public void init(GLAutoDrawable arg0) { - tr = new TextRenderer(Font.decode("Arial-BOLD-64")); - tr.setColor(1, 1, 1 ,1); - } - - public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) { - GL2 gl = arg0.getGL().getGL2(); - gl.glMatrixMode(GL2.GL_PROJECTION); - gl.glLoadIdentity(); - gl.glOrtho(0.0, w, 0.0, h, -1, 1); - gl.glMatrixMode(GL2.GL_MODELVIEW); - gl.glLoadIdentity(); - } - - public void dispose(GLAutoDrawable drawable) {} -} - diff --git a/test/Issue344Base.java b/test/Issue344Base.java deleted file mode 100644 index 8d0c3b0e1..000000000 --- a/test/Issue344Base.java +++ /dev/null @@ -1,105 +0,0 @@ -import java.awt.BorderLayout; -import java.awt.Font; -import java.awt.Frame; -import java.awt.event.*; -import java.awt.geom.*; - -import javax.media.opengl.GL2; -import javax.media.opengl.GLAutoDrawable; -import javax.media.opengl.GLEventListener; -import javax.media.opengl.awt.GLCanvas; -import javax.media.opengl.glu.*; -import com.jogamp.opengl.util.awt.TextRenderer; - -/** Test Code adapted from TextCube.java (in JOGL demos) - * - * @author spiraljetty - * @author kbr - */ - -public abstract class Issue344Base implements GLEventListener -{ - GLU glu = new GLU(); - TextRenderer renderer; - - float textScaleFactor; - Font font; - boolean useMipMaps; - - protected Issue344Base() { - font = new Font("default", Font.PLAIN, 200); - useMipMaps = true; //false - } - - protected abstract String getText(); - - protected void run(String[] args) { - Frame frame = new Frame(getClass().getName()); - frame.setLayout(new BorderLayout()); - - GLCanvas canvas = new GLCanvas(); - canvas.addGLEventListener(this); - frame.add(canvas, BorderLayout.CENTER); - - frame.setSize(512, 512); - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - new Thread(new Runnable() { - public void run() { - System.exit(0); - } - }).start(); - } - }); - frame.setVisible(true); - } - - public void init(GLAutoDrawable drawable) - { - GL2 gl = drawable.getGL().getGL2(); - - gl.glEnable(GL2.GL_DEPTH_TEST); - - renderer = new TextRenderer(font, useMipMaps); - - Rectangle2D bounds = renderer.getBounds(getText()); - float w = (float) bounds.getWidth(); - float h = (float) bounds.getHeight(); - textScaleFactor = 2.0f / (w * 1.1f); - gl.setSwapInterval(0); - } - - public void display(GLAutoDrawable drawable) - { - GL2 gl = drawable.getGL().getGL2(); - gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); - - gl.glMatrixMode(GL2.GL_MODELVIEW); - gl.glLoadIdentity(); - glu.gluLookAt(0, 0, 10, - 0, 0, 0, - 0, 1, 0); - - renderer.begin3DRendering(); - Rectangle2D bounds = renderer.getBounds(getText()); - float w = (float) bounds.getWidth(); - float h = (float) bounds.getHeight(); - renderer.draw3D(getText(), - w / -2.0f * textScaleFactor, - h / -2.0f * textScaleFactor, - 3f, - textScaleFactor); - - renderer.end3DRendering(); - } - - public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) - { - GL2 gl = drawable.getGL().getGL2(); - gl.glMatrixMode(GL2.GL_PROJECTION); - gl.glLoadIdentity(); - glu.gluPerspective(15, (float) width / (float) height, 5, 15); - } - - public void dispose(GLAutoDrawable drawable) {} -} diff --git a/test/Issue344Test1.java b/test/Issue344Test1.java deleted file mode 100644 index c0608ed6e..000000000 --- a/test/Issue344Test1.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Issue344Test1 extends Issue344Base { - protected String getText() { - // test 1 - weird artifacts appear with a large font & long string - return "abcdefghijklmnopqrstuvwxyz1234567890"; - } - - public static void main(String[] args) { - new Issue344Test1().run(args); - } -} diff --git a/test/Issue344Test2.java b/test/Issue344Test2.java deleted file mode 100644 index b0900438c..000000000 --- a/test/Issue344Test2.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Issue344Test2 extends Issue344Base { - protected String getText() { - // test 2 - unicode hangs program with a large font & long string - return "\u201Cabcdefghijklmnopqrstuvwxyz\u201D"; - } - - public static void main(String[] args) { - new Issue344Test2().run(args); - } -} diff --git a/test/Issue344Test3.java b/test/Issue344Test3.java deleted file mode 100644 index 381bf0a1c..000000000 --- a/test/Issue344Test3.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Issue344Test3 extends Issue344Base { - protected String getText() { - // test 3 - slight rendering artifacts around very large letters - return "abcde"; - } - - public static void main(String[] args) { - new Issue344Test3().run(args); - } -} diff --git a/test/Issue344Test4.java b/test/Issue344Test4.java deleted file mode 100644 index 1e077d2fd..000000000 --- a/test/Issue344Test4.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Issue344Test4 extends Issue344Base { - protected String getText() { - // test 4 - unicode letter as second-to-last is rendered incorrectly - return "\u201CGreetings\u201D!"; - } - - public static void main(String[] args) { - new Issue344Test4().run(args); - } -} diff --git a/test/native/displayMultiple01.c b/test/native/displayMultiple01.c deleted file mode 100644 index d51453687..000000000 --- a/test/native/displayMultiple01.c +++ /dev/null @@ -1,18 +0,0 @@ -#include <X11/X.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <GL/glx.h> -#include <stdio.h> - -int main(int nargs, char **vargs) { - int major, minor; - Display *disp = XOpenDisplay(NULL); - glXQueryVersion(disp, &major, &minor); - fprintf(stderr, "%p: %d.%d\n", disp, major, minor); - XCloseDisplay(disp); - disp = XOpenDisplay(NULL); - glXQueryVersion(disp, &major, &minor); - fprintf(stderr, "%p: %d.%d\n", disp, major, minor); - XCloseDisplay(disp); - return 0; -} diff --git a/test/native/displayMultiple02.c b/test/native/displayMultiple02.c deleted file mode 100644 index 1bfe95b95..000000000 --- a/test/native/displayMultiple02.c +++ /dev/null @@ -1,113 +0,0 @@ -/** - * compile with: gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL - */ - -#include <stdio.h> -#include <X11/X.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <GL/glx.h> -#include <GL/gl.h> - -static void testOrder(int reverseDestroyOrder, const char * msg); - -int main(int nargs, char **vargs) { - testOrder(0, "Normal order"); - testOrder(1, "Reverse order"); - return 0; -} - -static void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx); -static void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height); - -void testOrder(int reverseDestroyOrder, const char * msg) { - int major, minor; - Display *disp1; - Window win1; - GLXContext ctx1; - - Display *disp2; - Window win2; - GLXContext ctx2; - - fprintf(stderr, "%s: Create #1\n", msg); - disp1 = XOpenDisplay(NULL); - createGLWin(disp1, 200, 200, &win1, &ctx1); - useGL(disp1, win1, ctx1, 200, 200); - - fprintf(stderr, "%s: Create #2\n", msg); - disp2 = XOpenDisplay(NULL); - createGLWin(disp2, 300, 300, &win2, &ctx2); - useGL(disp2, win2, ctx2, 300, 300); - - if(reverseDestroyOrder) { - fprintf(stderr, "%s: Destroy #2\n", msg); - glXMakeCurrent(disp2, 0, 0); - glXDestroyContext(disp2, ctx2); - XCloseDisplay(disp2); - - fprintf(stderr, "%s: Destroy #1\n", msg); - glXMakeCurrent(disp1, 0, 0); - glXDestroyContext(disp1, ctx1); - XCloseDisplay(disp1); - } else { - fprintf(stderr, "%s: Destroy #1\n", msg); - glXMakeCurrent(disp1, 0, 0); - glXDestroyContext(disp1, ctx1); - XCloseDisplay(disp1); - - fprintf(stderr, "%s: Destroy #2\n", msg); - glXMakeCurrent(disp2, 0, 0); - glXDestroyContext(disp2, ctx2); - XCloseDisplay(disp2); - - } - - fprintf(stderr, "%s: Success - no bug\n", msg); -} - -/* attributes for a double buffered visual in RGBA format with at least - * 4 bits per color and a 16 bit depth buffer */ -static int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_RED_SIZE, 4, - GLX_GREEN_SIZE, 4, - GLX_BLUE_SIZE, 4, - GLX_DEPTH_SIZE, 16, - None }; - -void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx) -{ - int screen = DefaultScreen(dpy); - XVisualInfo *vi = glXChooseVisual(dpy, screen, attrListDbl); - Colormap cmap; - XSetWindowAttributes attr; - - /* create a GLX context */ - *rCtx = glXCreateContext(dpy, vi, 0, GL_TRUE); - /* create a color map */ - cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); - attr.colormap = cmap; - attr.border_pixel = 0; - - /* create a window in window mode*/ - attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | - StructureNotifyMask; - *rWin = XCreateWindow(dpy, RootWindow(dpy, vi->screen), - 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, - CWBorderPixel | CWColormap | CWEventMask, &attr); - - XMapRaised(dpy, *rWin); -} - -void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height) -{ - glXMakeCurrent(dpy, win, ctx); - glShadeModel(GL_SMOOTH); - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClearDepth(1.0f); - glViewport(0, 0, width, height); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glXSwapBuffers(dpy, win); - glXMakeCurrent(dpy, 0, 0); -} - diff --git a/test/native/glExtensionsListGL2.c b/test/native/glExtensionsListGL2.c deleted file mode 100644 index 89815e9c0..000000000 --- a/test/native/glExtensionsListGL2.c +++ /dev/null @@ -1,95 +0,0 @@ -/** - * compile with: gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL - */ - -#include <stdio.h> -#include <X11/X.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <GL/glx.h> -#include <GL/gl.h> - -static void testExtensions(); - -int main(int nargs, char **vargs) { - testExtensions(); - return 0; -} - -static void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx); -static void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height); - -void testExtensions() { - int major, minor; - Display *disp1; - Window win1; - GLXContext ctx1; - - disp1 = XOpenDisplay(NULL); - createGLWin(disp1, 200, 200, &win1, &ctx1); - if(0 != win1 && 0 != ctx1) { - useGL(disp1, win1, ctx1, 200, 200); - - glXMakeCurrent(disp1, 0, 0); - glXDestroyContext(disp1, ctx1); - } - XCloseDisplay(disp1); -} - -/* attributes for a double buffered visual in RGBA format with at least - * 4 bits per color and a 16 bit depth buffer */ -static int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER, - GLX_RED_SIZE, 4, - GLX_GREEN_SIZE, 4, - GLX_BLUE_SIZE, 4, - GLX_DEPTH_SIZE, 16, - None }; - -void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx) -{ - int screen = DefaultScreen(dpy); - XVisualInfo *vi = glXChooseVisual(dpy, screen, attrListDbl); - Colormap cmap; - XSetWindowAttributes attr; - - /* create a GLX context */ - *rCtx = glXCreateContext(dpy, vi, 0, GL_TRUE); - /* create a color map */ - cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone); - attr.colormap = cmap; - attr.border_pixel = 0; - - /* create a window in window mode*/ - attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | - StructureNotifyMask; - *rWin = XCreateWindow(dpy, RootWindow(dpy, vi->screen), - 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, - CWBorderPixel | CWColormap | CWEventMask, &attr); - - XMapRaised(dpy, *rWin); -} - -void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height) -{ - PFNGLGETSTRINGIPROC glGetStringi = 0; - int i, n; - - glXMakeCurrent(dpy, win, ctx); - - fprintf(stderr, "GL_VENDOR: %s\n", glGetString(GL_VENDOR)); - - glGetIntegerv(GL_NUM_EXTENSIONS, &n); - fprintf(stderr, "GL_NUM_EXTENSIONS: %d\n", n); - - glGetStringi = (PFNGLGETSTRINGIPROC)glXGetProcAddressARB("glGetStringi"); - if(NULL==glGetStringi) { - return; - } - - for (i=0; i<n; i++) { - const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i); - fprintf(stderr, "GL_EXTENSION %d/%d: %s\n", (i+1), n, extension); - } - -} - diff --git a/test/native/glExtensionsListGL3.c b/test/native/glExtensionsListGL3.c deleted file mode 100644 index c531577e8..000000000 --- a/test/native/glExtensionsListGL3.c +++ /dev/null @@ -1,300 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <GL/gl.h> -#include <GL/glext.h> -#include <GL/glx.h> -#include <GL/glxext.h> - -typedef int bool; -#define true 1; -#define false 0; - -// Helper to check for extension string presence. Adapted from: -// http://www.opengl.org/resources/features/OGLextensions/ -static bool 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 false; - - /* 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 true; - - start = terminator; - } - - return false; -} - -static bool ctxErrorOccurred = false; -static int ctxErrorHandler( Display *dpy, XErrorEvent *ev ) -{ - ctxErrorOccurred = true; - return 0; -} - -void dumpGLExtension() { - PFNGLGETSTRINGIPROC glGetStringi = 0; - int i, n; - - fprintf(stderr, "GL_VENDOR: %s\n", glGetString(GL_VENDOR)); - - glGetIntegerv(GL_NUM_EXTENSIONS, &n); - fprintf(stderr, "GL_NUM_EXTENSIONS: %d\n", n); - - glGetStringi = (PFNGLGETSTRINGIPROC)glXGetProcAddressARB("glGetStringi"); - if(NULL==glGetStringi) { - return; - } - - for (i=0; i<n; i++) { - const char* extension = (const char*)glGetStringi(GL_EXTENSIONS, i); - fprintf(stderr, "GL_EXTENSION %d/%d: %s\n", (i+1), n, extension); - } - -} - -int main (int argc, char ** argv) -{ - Display *display = XOpenDisplay(0); - - if ( !display ) - { - printf( "Failed to open X display\n" ); - exit(1); - } - - // Get a matching FB config - static int visual_attribs[] = - { - GLX_X_RENDERABLE , True, - GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, - GLX_RENDER_TYPE , GLX_RGBA_BIT, - GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, - GLX_RED_SIZE , 8, - GLX_GREEN_SIZE , 8, - GLX_BLUE_SIZE , 8, - GLX_ALPHA_SIZE , 8, - GLX_DEPTH_SIZE , 24, - GLX_STENCIL_SIZE , 8, - GLX_DOUBLEBUFFER , True, - //GLX_SAMPLE_BUFFERS , 1, - //GLX_SAMPLES , 4, - None - }; - - int glx_major, glx_minor; - - // FBConfigs were added in GLX version 1.3. - if ( !glXQueryVersion( display, &glx_major, &glx_minor ) || - ( ( glx_major == 1 ) && ( glx_minor < 3 ) ) || ( glx_major < 1 ) ) - { - printf( "Invalid GLX version" ); - exit(1); - } - - printf( "Getting matching framebuffer configs\n" ); - int fbcount; - GLXFBConfig *fbc = glXChooseFBConfig( display, DefaultScreen( display ), - visual_attribs, &fbcount ); - if ( !fbc ) - { - printf( "Failed to retrieve a framebuffer config\n" ); - exit(1); - } - printf( "Found %d matching FB configs.\n", fbcount ); - - // Pick the FB config/visual with the most samples per pixel - printf( "Getting XVisualInfos\n" ); - int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999; - - int i; - for ( i = 0; i < fbcount; i++ ) - { - XVisualInfo *vi = glXGetVisualFromFBConfig( display, fbc[i] ); - if ( vi ) - { - int samp_buf, samples; - glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf ); - glXGetFBConfigAttrib( display, fbc[i], GLX_SAMPLES , &samples ); - - printf( " Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d," - " SAMPLES = %d\n", - (int)i, (int)( vi -> visualid), samp_buf, samples ); - - if ( best_fbc < 0 || samp_buf && samples > best_num_samp ) - best_fbc = i, best_num_samp = samples; - if ( worst_fbc < 0 || !samp_buf || samples < worst_num_samp ) - worst_fbc = i, worst_num_samp = samples; - } - XFree( vi ); - } - - GLXFBConfig bestFbc = fbc[ best_fbc ]; - - // Be sure to free the FBConfig list allocated by glXChooseFBConfig() - XFree( fbc ); - - // Get a visual - XVisualInfo *vi = glXGetVisualFromFBConfig( display, bestFbc ); - printf( "Chosen visual ID = 0x%x\n", (int) vi->visualid ); - - printf( "Creating colormap\n" ); - XSetWindowAttributes swa; - Colormap cmap; - swa.colormap = cmap = XCreateColormap( display, - RootWindow( display, vi->screen ), - vi->visual, AllocNone ); - swa.background_pixmap = None ; - swa.border_pixel = 0; - swa.event_mask = StructureNotifyMask; - - printf( "Creating window\n" ); - Window win = XCreateWindow( display, RootWindow( display, vi->screen ), - 0, 0, 100, 100, 0, vi->depth, InputOutput, - vi->visual, - CWBorderPixel|CWColormap|CWEventMask, &swa ); - if ( !win ) - { - printf( "Failed to create window.\n" ); - exit(1); - } - - // Done with the visual info data - XFree( vi ); - - XStoreName( display, win, "GL 3.0 Window" ); - - printf( "Mapping window\n" ); - XMapWindow( display, win ); - - // Get the default screen's GLX extension list - const char *glxExts = glXQueryExtensionsString( display, - DefaultScreen( display ) ); - - // NOTE: It is not necessary to create or make current to a context before - // calling glXGetProcAddressARB - PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = 0; - glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) - glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); - - GLXContext ctx = 0; - - // Install an X error handler so the application won't exit if GL 3.0 - // context allocation fails. - // - // Note this error handler is global. All display connections in all threads - // of a process use the same error handler, so be sure to guard against other - // threads issuing X commands while this code is running. - ctxErrorOccurred = false; - int (*oldHandler)(Display*, XErrorEvent*) = - XSetErrorHandler(&ctxErrorHandler); - - // Check for the GLX_ARB_create_context extension string and the function. - // If either is not present, use GLX 1.3 context creation method. - if ( !isExtensionSupported( glxExts, "GLX_ARB_create_context" ) || - !glXCreateContextAttribsARB ) - { - printf( "glXCreateContextAttribsARB() not found" - " ... using old-style GLX context\n" ); - ctx = glXCreateNewContext( display, bestFbc, GLX_RGBA_TYPE, 0, True ); - } - - // If it does, try to get a GL 3.0 context! - else - { - int context_attribs[] = - { - GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - GLX_CONTEXT_MINOR_VERSION_ARB, 0, - GLX_RENDER_TYPE , GLX_RGBA_TYPE, - GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, - None - }; - - printf( "Creating context\n" ); - ctx = glXCreateContextAttribsARB( display, bestFbc, 0, - True, context_attribs ); - - // Sync to ensure any errors generated are processed. - XSync( display, False ); - if ( !ctxErrorOccurred && ctx ) { - printf( "Created GL 3.0 context\n" ); - } else - { - // Couldn't create GL 3.0 context. Fall back to old-style 2.x context. - // When a context version below 3.0 is requested, implementations will - // return the newest context version compatible with OpenGL versions less - // than version 3.0. - // GLX_CONTEXT_MAJOR_VERSION_ARB = 1 - context_attribs[1] = 1; - // GLX_CONTEXT_MINOR_VERSION_ARB = 0 - context_attribs[3] = 0; - - ctxErrorOccurred = false; - - printf( "Failed to create GL 3.0 context" - " ... using old-style GLX context\n" ); - ctx = glXCreateContextAttribsARB( display, bestFbc, 0, - True, context_attribs ); - } - } - - // Sync to ensure any errors generated are processed. - XSync( display, False ); - - // Restore the original error handler - XSetErrorHandler( oldHandler ); - - if ( ctxErrorOccurred || !ctx ) - { - printf( "Failed to create an OpenGL context\n" ); - exit(1); - } - - // Verifying that context is a direct context - if ( ! glXIsDirect ( display, ctx ) ) - { - printf( "Indirect GLX rendering context obtained\n" ); - } - else - { - printf( "Direct GLX rendering context obtained\n" ); - } - - printf( "Making context current\n" ); - glXMakeCurrent( display, win, ctx ); - - dumpGLExtension(); - - glXMakeCurrent( display, 0, 0 ); - glXDestroyContext( display, ctx ); - - XDestroyWindow( display, win ); - XFreeColormap( display, cmap ); - XCloseDisplay( display ); - - return 0; -} - diff --git a/test/native/make.sh b/test/native/make.sh deleted file mode 100755 index 20bd49e4a..000000000 --- a/test/native/make.sh +++ /dev/null @@ -1,6 +0,0 @@ -#! /bin/bash - -gcc -o displayMultiple01 displayMultiple01.c -lX11 -lGL -gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL -gcc -o glExtensionsListGL2 glExtensionsListGL2.c -lX11 -lGL -gcc -o glExtensionsListGL3 glExtensionsListGL3.c -lX11 -lGL |