diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Issue326Test1.java | 91 | ||||
-rw-r--r-- | test/Issue326Test2.java | 66 | ||||
-rw-r--r-- | test/Issue344Base.java | 107 | ||||
-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 | ||||
-rwxr-xr-x | test/native/make.sh | 4 |
10 files changed, 439 insertions, 0 deletions
diff --git a/test/Issue326Test1.java b/test/Issue326Test1.java new file mode 100644 index 000000000..217c2819b --- /dev/null +++ b/test/Issue326Test1.java @@ -0,0 +1,91 @@ +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.GL; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCanvas; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.glu.GLU; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.j2d.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) { + GL gl = drawable.getGL(); + gl.glClearColor(0, 0, 0, 0); + gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT); + + + gl.glMatrixMode(GL.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(GL.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; + GL gl = arg0.getGL(); + gl.glViewport(0, 0, width, height); + gl.glMatrixMode(GL.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0.0, 800, 0.0, 200, -100.0, 100.0); + gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glLoadIdentity(); + } + public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {} +} diff --git a/test/Issue326Test2.java b/test/Issue326Test2.java new file mode 100644 index 000000000..10ec4417b --- /dev/null +++ b/test/Issue326Test2.java @@ -0,0 +1,66 @@ +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.*; +import javax.media.opengl.*; +import com.jogamp.opengl.util.j2d.*; + +/** + * 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) { + GL gl = drawable.getGL(); + gl.glClearColor(0, 0, 0, 0); + gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.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) { + GL gl = arg0.getGL(); + gl.glMatrixMode(GL.GL_PROJECTION); + gl.glLoadIdentity(); + gl.glOrtho(0.0, w, 0.0, h, -1, 1); + gl.glMatrixMode(GL.GL_MODELVIEW); + gl.glLoadIdentity(); + } + public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {} +} + diff --git a/test/Issue344Base.java b/test/Issue344Base.java new file mode 100644 index 000000000..6d0c99290 --- /dev/null +++ b/test/Issue344Base.java @@ -0,0 +1,107 @@ +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.Frame; +import java.awt.event.*; +import java.awt.geom.*; + +import javax.media.opengl.*; +import javax.media.opengl.glu.*; +import com.jogamp.opengl.util.*; +import com.jogamp.opengl.util.j2d.*; + +/** 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.show(); + } + + public void init(GLAutoDrawable drawable) + { + GL gl = drawable.getGL(); + + gl.glEnable(GL.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) + { + GL gl = drawable.getGL(); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + gl.glMatrixMode(GL.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) + { + GL gl = drawable.getGL(); + gl.glMatrixMode(GL.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(15, (float) width / (float) height, 5, 15); + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, + boolean deviceChanged) + { + } +} diff --git a/test/Issue344Test1.java b/test/Issue344Test1.java new file mode 100644 index 000000000..c0608ed6e --- /dev/null +++ b/test/Issue344Test1.java @@ -0,0 +1,10 @@ +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 new file mode 100644 index 000000000..b0900438c --- /dev/null +++ b/test/Issue344Test2.java @@ -0,0 +1,10 @@ +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 new file mode 100644 index 000000000..381bf0a1c --- /dev/null +++ b/test/Issue344Test3.java @@ -0,0 +1,10 @@ +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 new file mode 100644 index 000000000..1e077d2fd --- /dev/null +++ b/test/Issue344Test4.java @@ -0,0 +1,10 @@ +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 new file mode 100644 index 000000000..d51453687 --- /dev/null +++ b/test/native/displayMultiple01.c @@ -0,0 +1,18 @@ +#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 new file mode 100644 index 000000000..1bfe95b95 --- /dev/null +++ b/test/native/displayMultiple02.c @@ -0,0 +1,113 @@ +/** + * 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/make.sh b/test/native/make.sh new file mode 100755 index 000000000..2552eddb0 --- /dev/null +++ b/test/native/make.sh @@ -0,0 +1,4 @@ +#! /bin/bash + +gcc -o displayMultiple01 displayMultiple01.c -lX11 -lGL +gcc -o displayMultiple02 displayMultiple02.c -lX11 -lGL |