created mirror

This commit is contained in:
whatever
2026-09-14 20:19:29 -04:00
commit 6764738d92
600 changed files with 87187 additions and 0 deletions

22
Modules/openGL/Makefile Normal file
View File

@@ -0,0 +1,22 @@
# IBMCFLAGS=-Dint64_t="long long" -Dlinux -g
IBMCFLAGS=-Dlinux -g
JAVAC=javac
CC=g++
#CC=/usr/bin/gcc
OFLAGS= -Wall # -O2 -ffast-math -fexpensive-optimizations
INCLUDES= -I/usr/local/java/include -I/usr/local/java/include/linux -I/usr/X11R6/include
LIBS= -L/usr/X11R6/lib -lm -lGL -lGLU -lglut -lX11 -lXext -lXmu -lXt -lXi\
-lSM -lICE -lgltt
# -lSM -lICE -liconv -lgltt
lib:
$(CC) $(IBMCFLAGS) -shared ZZOpenGLGraphics.cc $(INCLUDES) $(LIBS) \
-o libzz3d.so $(OFLAGS)
java:
$(JAVAC) *.java
clean:
-rm *.o *~ *.class javacore.txt
old:
$(CC) -shared Scene_Xlib.cc $(INCLUDES) $(LIBS) \
-o libzz3d.so $(OFLAGS)

View File

@@ -0,0 +1,133 @@
/*
OpenGLCloud.java
*
* Copyright (c) 2000, Ted Nelson, Tuomas Lukka and Vesa Parkkinen
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Vesa Parkkinen
*/
package org.gzigzag.module;
import org.gzigzag.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
/**
* A Simple OpenGL test.
*/
public class OpenGLCloud {
public static final String rcsid = "$Id: OpenGLCloud.java,v 1.4 2000/10/18 14:35:32 tjl Exp $";
public static final boolean dbg = true;
static final void p(String s) { if(dbg) System.out.println(s); }
static final void pa(String s) { System.out.println(s); }
OpenGLCloud(){
}
static public ZZModule module = new ZZModule() {
ZZOpenGLGraphics o;
int xk = -20;
public void action(String id,
ZZCell code,
ZZCell target,
ZZView view, ZZView cview,
String key, Point pt, ZZScene xi) {
ZZCell viewCell = view.getViewcell();
ZZCell viewCursor = ZZCursorReal.get(viewCell);
Object ob = null;
if(pt != null && xi != null)
ob = xi.getObjectAt(pt.x, pt.y);
p("openGL action! '"+id+"' key: "+key);
if(id.equals("TEST")) {
} else if(id.equals("OPENWIN")) {
p("openGL OPENWIN");
o = new ZZOpenGLGraphics();
o.openWindow(400,400);
o.addKeyListener(new KeyListener(){
public void keyTyped(KeyEvent e){
p("****KEY TYPED: " + e);
}
public void keyPressed(KeyEvent e){
p("****KEY PRESSED: " + e);
key( e.getKeyChar() );
}
public void keyReleased(KeyEvent e){
p("****KEY RELEASED: " + e);
}
});
o.putLine(20,20,30,10, "TEST");
o.putText( "Just testing",-20,30);
o.putText( "Another String...",-20,20);
o.putText( "Line ",-20,10);
o.putText( "Last line",-20,0);
o.putArrow(-10, -10, 10,10,new Color(1,0,0),"TEST");
/*
ZZCell c = target;
for( int i = 0; i < 5 ; i++){
o.putCell(c, 0,0 - i*10,25,8,"TEST");
c = c.s("d.2", 1);
if ( c != null ){
o.putLine(12,0-i*10,12,50 - i*10 - 2, "TEST");
}else
break;
}
c = target.s("d.2", -1);;
if( c != null )
for( int i = 1; i < 5 ; i++){
o.putCell(c, 0, i*10,25,8,"TEST");
c = c.s("d.2", -1);
if ( c != null ){
o.putLine(12,i*10+10,12, i*10 + 2, "TEST");
}else
break;
}
*/
o.start();
}
}
public void key(char k){
p("===KEY===");
xk += 10;
o.putText( "" + k ,xk ,-20);
}
public ZZRaster getRaster(String id){
return null;
}
};
}

View File

@@ -0,0 +1,474 @@
/****************************************************
* INCLUDES
****************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
// #include <iconv.h>
#include <math.h>
extern "C"{
#include "jni.h"
}
#include "fi_iki_lukka_ZZOpenGLGraphics.h"
#include "gltt/FTEngine.h"
#include "gltt/FTFace.h"
#include "gltt/FTInstance.h"
#include "gltt/FTGlyph.h"
#include "gltt/FTGlyphBitmap.h"
#include "gltt/FTGlyphPixmap.h"
#include "gltt/FTBitmapFont.h"
#include "gltt/GLTTBitmapFont.h"
#include "gltt/GLTTPixmapFont.h"
#include "gltt/GLTTOutlineFont.h"
#include "gltt/GLTTFont.h"
#include "gltt/GLTTGlyphPolygonizer.h"
#include "gltt/GLTTGlyphTriangulator.h"
#include <GL/glx.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <X11/Xatom.h>
#include <X11/Xmu/StdCmap.h>
#include <X11/keysym.h>
/***********************************************
* useful little macros
************************************************/
#define GET_THIS() jclass zzthis = env->GetObjectClass( obj );
#define FIELD_ID(_name, _sig) env->GetFieldID( zzthis, _name, _sig)
#define SET_INT_FIELD(_name, _value) \
env->SetIntField( obj, FIELD_ID(_name, "I"), _value)
#define GET_INT_FIELD(_name) env->GetIntField( obj, FIELD_ID(_name, "I"))
/******************************************************
* GLOBALS
******************************************************/
/* these will be in java class */
Display *disp;
Window win;
/***/
GLboolean db = GL_TRUE; /* doublebuffering */
GLint disp_list = 0;
XSizeHints sizeHints = { 0 };
XEvent event;
GLuint base;
int args[] = { GLX_DOUBLEBUFFER,
GLX_RGBA,
GLX_DEPTH_SIZE,
16,
None };
void makeRasterFont(Display *dpy)
{
XFontStruct *fontInfo;
Font id;
unsigned int first, last;
fontInfo = XLoadQueryFont(dpy,
"-*-courier-medium-r-normal-*-*-100-*-*-m-*-iso8859-1");
if (fontInfo == NULL) {
printf ("no font found\n");
exit (0);
}
id = fontInfo->fid;
first = fontInfo->min_char_or_byte2;
last = fontInfo->max_char_or_byte2;
base = glGenLists(last+1);
if (base == 0) {
printf ("out of display lists\n");
exit (0);
}
glXUseXFont(id, first, last-first+1, base+first);
}
/******************************************************
* printString
******************************************************/
void printString(const char *s)
{
glListBase(base);
glCallLists(strlen(s), GL_UNSIGNED_BYTE, (unsigned char *)s);
}
/******************************************************
* getColormap
******************************************************/
Colormap getColormap ( XVisualInfo *vis){
Status stat;
XStandardColormap *sCm;
Colormap cm;
int i;
int numCmaps;
if ( vis->c_class != TrueColor ){
printf ("No support for TrueColor!");
exit(1);
}
stat = XmuLookupStandardColormap(disp, vis->screen, vis->visualid,
vis->depth,XA_RGB_DEFAULT_MAP, False, True);
if (stat == 1) {
stat = XGetRGBColormaps( disp, RootWindow(disp, vis->screen),
&sCm, &numCmaps,
XA_RGB_DEFAULT_MAP);
if (stat == 1)
for( i = 0; i < numCmaps; i++ )
if( sCm[i].visualid == vis->visualid) {
cm = sCm[i].colormap;
XFree(sCm);
return cm;
}
}
cm = XCreateColormap (disp, RootWindow(disp,vis->screen),
vis->visual, AllocNone);
return cm;
}
/******************************************************
* openWindow
******************************************************/
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_openWindow( JNIEnv *env,
jobject obj,
jint width,
jint height)
{
XVisualInfo *vi;
Colormap cm;
XSetWindowAttributes xswa;
XWMHints *wmHints;
Atom wmDeleteWindow;
GLXContext cx;
char *display = NULL;
/** connect to X server **/
disp = XOpenDisplay(display);
// FIX ME
if ( disp == NULL ) exit(1);
printf("__C__: openWindow\n");
/** check for glx */
if ( ! glXQueryExtension(disp, NULL, NULL))
// maybe should use some constants
return;// 2;
/** visual & colormap **/
vi = glXChooseVisual(disp, DefaultScreen(disp),args );
if ( ! vi ){
// no doublebuffering
vi = glXChooseVisual(disp, DefaultScreen(disp),&args[1] );
if ( ! vi ) exit(1);
db = GL_FALSE;
}
cm = getColormap(vi);
/** GL rendering context **/
cx = glXCreateContext(disp, vi, NULL, GL_TRUE);
if ( cx == NULL )
exit(1);
/* some hints etc */
xswa.colormap = cm;
xswa.border_pixel = 0;
xswa.event_mask = ExposureMask|ButtonPressMask|KeyPressMask;
sizeHints.width = width;
sizeHints.height = height;
sizeHints.x = 10;
sizeHints.y = 10;
win = XCreateWindow(disp, RootWindow(disp,vi->screen),
sizeHints.x, sizeHints.y,
width, height, 0, vi->depth, InputOutput,
vi->visual, CWEventMask|CWBorderPixel|CWColormap, &xswa);
wmDeleteWindow = XInternAtom(disp, "WM_DELETE_WINDOW", False);
XSetWMProtocols(disp, win, &wmDeleteWindow,1);
XSetStandardProperties(disp, win, "test", "Testi",
None, None, None, &sizeHints);
wmHints = XAllocWMHints();
wmHints->initial_state = NormalState;
wmHints->flags = StateHint;
XSetWMHints(disp, win, wmHints);
/* bind context to window */
glXMakeCurrent(disp, win, cx);
glEnable ( GL_DEPTH_TEST );
glEnable ( GL_ALPHA_TEST );
glDisable ( GL_DITHER );
glDisable ( GL_LIGHTING );
glDisable ( GL_FOG );
glDisable ( GL_TEXTURE_2D );
glDisable ( GL_CULL_FACE );
glDisable ( GL_SCISSOR_TEST );
glDisable ( GL_STENCIL_TEST );
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65, (GLfloat) width
/ (GLfloat) height, 1, 1000);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluLookAt(0, 0, 100, 0, 0, 0, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
XMapWindow(disp,win);
glXSwapBuffers(disp, win);
makeRasterFont(disp);
}
/******************************************************
* drawLine
******************************************************/
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_drawLine(JNIEnv *env, jobject obj,
jint x1, jint y1,
jint x2, jint y2){
printf("__C__: drawLine\n");
glBegin(GL_LINES);
glVertex3d( x1, y1, 0 );
glVertex3d( x2, y2, 0 );
glEnd();
}
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_drawRect(JNIEnv *env, jobject obj,
jint x, jint y,
jint width, jint height){
printf("__C__: drawRect\n");
glBegin(GL_QUADS);
glVertex3d( x, y, 0 );
glVertex3d( x, y+height, 0 );
glVertex3d( x+width, y+height, 0 );
glVertex3d( x+width, y, 0 );
glEnd();
}
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_drawPoint(JNIEnv *env, jobject obj,
jint x, jint y);
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_drawText(JNIEnv *env, jobject obj,
jint x, jint y,
jstring text, jint size){
int s;
//int l;
const char *str = (const char *)env->GetStringUTFChars( text, 0 );
printf("str = %s\n", str);
s = env->GetStringLength( text);
// Check the size
printf("s = %d\n", s);
glLoadIdentity();
/*
//
// glut stroke fonts
glTranslatef(x,y,0);
glScalef(0.03,0.03,0.03);
for(l = 0; l < s; l++){
glutStrokeCharacter(GLUT_STROKE_ROMAN , str[l]);
glTranslatef(glutStrokeWidth(GLUT_STROKE_ROMAN,str[l]),0,0);
}
*/
printf("__C__: drawText\n");
//glColor3f(1,1,1);
glLoadIdentity();
FTFace face;
if( ! face.open("/dos/winnt/Fonts/couri.ttf") ){
printf("unable to open ttf file");
return ;
}
GLTTOutlineFont font(&face);
int point_size= size;
if( ! font.create(point_size) ){
printf("unable to create outline font");
return ;
}
glTranslatef(x,y,0);
//glRotatef(45,0,1,0);
//font.setPrecision(4);
font.output( str );
// bitmap fonts
//printString(str);
glLoadIdentity();
env->ReleaseStringUTFChars( text, 0);
}
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_drawingColor(JNIEnv *env, jobject obj,
jdouble r, jdouble g,
jdouble b, jdouble a){
glColor4d(r,g,b,a);
}
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_drawArrow(JNIEnv *env, jobject obj,
jint x, jint y,
jint dx, jint dy,
jint dz){
glLoadIdentity();
glScalef(dx,dy,dz);
glBegin(GL_LINES);
glVertex3f(x,y,0);
glVertex3f(x,y-1,0);
glVertex3f(x,y,0);
glVertex3f(x+2,y-2,0);
glVertex3f(x,y,0);
glVertex3f(x+1,y,0);
glEnd();
glLoadIdentity();
}
/******************************************************
* swapBuffers
******************************************************/
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_swapBuffers(JNIEnv *env,
jobject obj){
printf("__C__: swapBuffers\n");
glXSwapBuffers(disp,win);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
}
/******************************************************
* checkEvents
******************************************************/
JNIEXPORT void JNICALL
Java_fi_iki_lukka_ZZOpenGLGraphics_checkEvents( JNIEnv *env, jobject obj){
XKeyEvent *e_key;
XButtonEvent *e_but;
XConfigureEvent *e_conf;
jclass cls = env->GetObjectClass( obj );
jmethodID key_id = env->GetMethodID( cls,
"addKeyEvent", "(II)V");
jmethodID button_id = env->GetMethodID( cls,
"addButtonEvent", "(IIII)V");
jmethodID conf_id = env->GetMethodID( cls,
"configureEvent", "(II)V");
printf("__C__: Check events\n");
if ( button_id == 0 || key_id == 0 ) {
printf ("no method id\n");
return ;
}
do{
int ch;
int type = 0;
XEvent event;
XNextEvent(disp, &event);
switch ( event.type ){
case ConfigureNotify:
printf("ConfNotify");
env->CallVoidMethod( obj, conf_id,
e_conf->width, e_conf->height);
break;
case ButtonPress:
e_but = (XButtonEvent *) &event;
env->CallVoidMethod( obj, button_id,
e_but->button, e_but->x, e_but->y, 0);
break;
case KeyPress:
e_key = (XKeyEvent *) &event;
ch = (int )XLookupKeysym(e_key,0);
env->CallVoidMethod( obj, key_id, ch, type);
break;
default:
;
}
} while( XPending( disp ) );
return ;
}

View File

@@ -0,0 +1,606 @@
/*
ZZGraphics.java
*
* Copyright (c) 2000, Ted Nelson, Tuomas Lukka and Vesa Parkkinen
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
* file for more details.
*
*/
/*
* Written by Vesa Parkkinen
*/
package org.gzigzag;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
/** A class that implements the ZZGraphics interface using OpenGL.
* Tjl's comments:
* <ul>
* <li> You DON'T want to derive everything from OGLColorThing: that
* slows down rendering. Note how it's done in ZZCanvas: there's
* a ColorThing which sets the foreground/background color which
* is then used.
*
* A state machine... Well, whatever you want.
* Doesn't that somewhat dictate the ordering of drawing,
* what if for some reason (optimization etc.) I want to
* draw the in different order ? I admit it slows rendering,
* but I still would like to have objects with color, not just
* global pens to use in drawing, at least in the object level.
* The implementation of rendering is a completely different thing,
* and shouldn't dictate design issues.
* The actual rendering is unbeliavably simple at the moment,
* but i just wanted to get the java-C-java pipeline to work. /vp
*
* Tjl: In that case, put in a reference to a reusable OGLColorThing
* (in Design Patterns, this is called a flyweight).
* the order of drawing is an excellent point: I was still thinking
* in terms of java.awt.Graphics where order is visible; if we have
* a Z-buffer, that's right. However, if we don't use a Z-buffer, the
* order of rendering is really important.
*
* OTOH: for drawing order, using the color makes sense since in
* some cases changing the color (or material) in OpenGL
* can be one of the slowest operations.
*
* vp: That's why I would like to have attributes of objects to be
* within objects, so i could _easily_ handle them in the order
* that makes most sense at that moment.
*
* <li> For Colors, extend java.awt.Color with alpha - in Java1.2, this
* is already done.
*
* Why ? I just need 4 doubles. Of course there will be methods
* to use Color, but internally i'd like to keep color as
* doubles /vp
*
* Tjl: double = 8 bytes. 4 doubles = 32 bytes. java.awt.Color = 4 bytes.
* first of all, we want to avoid float arithmetic so using bytes or
* an integer would be better. glColor3b can be much faster.
*
* vp: well it's pretty much same to me if it is a byte, float
* or double, but I would like to put it to the format it is used
* at creation time rather than in rendering time.
*
* <li> Why does colorthing have coordinates?
*
* Because a Thing is always in space somewhere. They are objects,
* not just some global "pen swithes". /vp
*
* Tjl: see above for how to handle ColorThing - that way it doesn't
* have coordinates.
*
* One big question is: *DO* we really want actual "models" or just
* drawing things?
* Both the layer above and the layer below are about drawing with a
* pen - why have a layer with models in between?
*
* vp: As long as we already have objects why don't use them.
* It gives much more flexibility when trying to do more complex
* things. BTW, What is the layer above that is about drawing with a
* pen?
* If we would strip the awt from zzcanvas, and added a simple way
* to use any ZZGraphics, then this wouldn't be an issue: you could
* do it the way you wanted in ZZCanvas. And that is the way I think
* it should be done.
*
*
* <li> Basically, check out how ZZCanvas does things and do the same.
* Actually, we might want to think about separating the class
* structure in a way as to have an abstract base class for graphic
* beams and then two implementations, one for opengl and the other
* for awt. Or even have things implement ZZOpenGLThing interface.
* ZZCanvas is pretty abstract.
*
* I don't think so, ZZCanvas is way
* too tightly connected to awt. If one could bring his own graphics,
* with some basic methods, drawCell, drawLink etc., then it would
* be good. In fact that is the way I think it should be done. /vp
*
* Tjl: Explain further. The connection to awt is actually limited to
* the methods render*.
*
* vp: Exactly. We should have ZZCanvas(zzgraphics g), so we could use
* zzcanvas with any graphics we would like to implement. All rendering
* would go through that zzgraphics. So every render method
* should have something like g.drawLine, where g is zzgraphics not
* graphics.
*
* <li> if you extend Component, do you need addKeyListener and
* addMouseListener?
*
* If I want to throw my own keyevents, yes./vp
*
* they are already implemented there.
*
* Is there somewhere a method to fire your own key & mouse events? /vp
*
* Alternatively, not deriving from Component might be good.
*
* I know, I should have added a Component and used that to fire
* those events... /vp
*
* java.awt.Component.processEvent(KeyEvent) /vp
*
* </ul>
*/
public class ZZOpenGLGraphics extends Component implements ZZGraphics, Runnable {
String rcsid = "$Id: ZZOpenGLGraphics.java,v 1.9 2000/11/05 12:49:39 tjl Exp $";
public static final boolean dbg = true;
static final void p(String s) { if(dbg) System.out.println(s); }
static final void pa(String s) { System.out.println(s); }
KeyListener actionListener = null;
public void addKeyListener(KeyListener l) {
actionListener = AWTEventMulticaster.add(actionListener, l);
}
public void removeKeyListener(KeyListener l) {
actionListener = AWTEventMulticaster.remove(actionListener, l);
}
public void processKeyEvent(KeyEvent e) {
if (actionListener != null) {
actionListener.keyPressed(e);
}
}
MouseListener mouseListener = null;
public void addMouseListener(MouseListener l) {
mouseListener = AWTEventMulticaster.add(mouseListener, l);
}
public void removeMouseListener(MouseListener l) {
mouseListener = AWTEventMulticaster.remove(mouseListener, l);
}
public void processMouseEvent(MouseEvent e) {
if (mouseListener != null){
mouseListener.mouseClicked(e);
}
}
int GLcontext = 0;
int window = 0;
int display = 0;
int font_Size = 10;
/* just testing */
int cx = 0;
int cy = 0;
int cz = 50;
Vector things = new Vector();
public abstract class OGLThing {
int x;
int y;
OGLThing(int x, int y ){
this.x = x;
this.y = y;
}
OGLThing( ){
x = 0;
y = 0;
}
public void coords(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() { return x; }
public int getYs() { return y; }
// rendes to this context
public abstract void render();
}
public class OGLColorThing extends OGLThing{
float r;
float g;
float b;
float a;
OGLColorThing(int x, int y, float r, float g, float b, float a){
super(x,y);
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
OGLColorThing(){
super();
this.r = 1;
this.g = 1;
this.b = 1;
this.a = 1;
}
OGLColorThing(int x, int y){
super(x,y);
this.r = 1;
this.g = 1;
this.b = 1;
this.a = 1;
}
OGLColorThing(Color c){
super(0,0);
setColor(c);
}
public void setColor(Color c){
}
public void setColor(int r, int g, int b, int a){
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
public void render(){
p("COLOR: RENDER\n");
/* this is just a temporary solution,
add checking of color */
drawingColor(r,g,b,a);
}
}
public abstract class OGLCell extends OGLColorThing{
ZZCell c;
public OGLCell(){
super();
c = null;
}
public OGLCell(int x, int y, ZZCell c){
super(x,y);
this.c = c;
}
public OGLCell( ZZCell c ){
super();
this.c = c;
}
}
public class OGL2DCell extends OGLCell {
int width;
int height;
public OGL2DCell(){
super();
width = 0;
height = 0;
}
public OGL2DCell(int x, int y, int width, int height, ZZCell cell){
super(x,y,cell);
this.width = width;
this.height = height;
}
public void render(){
super.render();
p("CELL: RENDER" + x + " " +y);
drawRect(x,y,width,height);
if( c != null ) {
drawingColor(0,0,0,1);
drawText(x+2, y+2, c.getText(),10);
}
}
}
public class OGLText extends OGLColorThing{
int size;
String text;
public OGLText(int x, int y, String txt){
super(x,y);
text = txt;
size = 10;
}
public void render(){
//super.render();
drawText(x, y, text, size );
}
}
public class OGLLink extends OGLColorThing{
int x2;
int y2;
OGLLink(int x1, int y1, int x2, int y2){
super(x1,y1);
this.x2 = x2;
this.y2 = y2;
}
public void render(){
super.render();
drawLine(super.x,super.y, x2, y2);
}
}
public class OGLLine extends OGLColorThing{
int x2;
int y2;
OGLLine(int x1, int y1, int x2, int y2){
super(x1,y1);
this.x2 = x2;
this.y2 = y2;
}
public void render(){
super.render();
drawLine(super.x,super.y, x2, y2);
}
}
public class OGLMark extends OGLColorThing{
ZZCell c;
int h;
OGLMark(int x1, int y1, int h, ZZCell c){
super(x1,y1);
this.c = c;
this.h = h;
}
public void render(){
super.render();
drawLine(super.x,super.y, x, y+h);
}
}
class OGLArrow extends OGLColorThing{
// Hmm...
int dir_x;
int dir_y;
int dir_z;
public OGLArrow(int x, int y){
super(x,y);
dir_x = 2;
dir_y = 2;
dir_z = 1;
}
public void render(){
super.render();
drawArrow(super.x,super.y, dir_x, dir_y, dir_z);
}
}
public Dimension getSize(){
return null;
}
public Dimension getDefaultCellSize(ZZCell c){
return null;
}
public void putCell(ZZCell c, int x, int y, int w, int h, String style){
things.addElement(new OGL2DCell(x,y,w,h,c));
}
public void putLinks(String dim, float dx, float dy){
}
// public void putBeams(ZZCanvasTextSpanSet set1, ZZCanvasTextSpanSet set2){
//
// }
public void setColor(Color c){}
public int getDefaultFontSize(){ return 0;}
public FontMetrics getFontMetrics(Font f){ return null;}
public void setFont(Font f){}
public void putPolyLine(int x1, int y1, int x2, int y2, String style){}
public void putText(String s, int x, int y){
things.addElement(new OGLText(x,y,s));
}
public void putText(String s, int x, int y, int size){
things.addElement(new OGLText(x,y,s));
}
/*
public void putText(String s, int x, int y, int z){
things.addElement(new OGLText(x,y,z,s));
}
*/
public Object putSpan(Span s, String str, ZZCell c, int x, int y,
int w, int h, int xoffs, int yoffs,
ZZCanvasTextSpanSet collect,
Object prev,
Font f, FontMetrics fm){
return null;}
public void putTextMark(int x, int y, int h, ZZCell mkc){
things.addElement(new OGLMark(x,y,h, mkc));
}
public void putLine(int x1, int y1, int x2, int y2, String style){
//drawLine(x1, y1, x2, y2);
things.addElement(new OGLLine(x1,y1,x2,y2));
}
public void putCoordNames(String[] names){}
public void putArrow( int x1, int y1,
int x2, int y2,
Color intern, String style){
things.addElement(new OGLArrow(x1,y1));
}
// public void putDragCursor(ZZGraphics.DragCursor dc, int x, int y){}
// public class OpenGLDragCursor implements ZZGraphics.DragCursor {
// public boolean accept(Object o){ return false; }
// }
static {
System.loadLibrary("zz3d");
}
public void render(){
p("RENDER:");
for (Enumeration e = things.elements() ; e.hasMoreElements() ;) {
((OGLThing)e.nextElement()).render();
}
swapBuffers();
}
private Thread thread = null;
public void start() {
if (thread == null) {
thread = new Thread(this, "render");
thread.start();
}
}
public void run() {
Thread myThread = Thread.currentThread();
p("RUN:");
while (thread == myThread) {
checkEvents();
render();
try {
Thread.sleep(100);
} catch (InterruptedException e){
// the VM doesn't want us to sleep anymore,
// so get back to work
}
}
}
void addKeyEvent(int key, int type){
p("KEY_EVENT: " + (char)key + " " + type);
// XXX add missing info: time, modifiers ...
processKeyEvent(new KeyEvent(this,1000,1,0,key,(char)key));
}
void addButtonEvent(int button, int x, int y, int modifiers){
p("BUTTON_EVENT: " + button + " " + x + y);
processMouseEvent(new MouseEvent(this,1001,1,0,x,y,1,false));
}
void configureEvent(int x, int y){
p("CONFIGURE_EVENT:" + x + " " + y);
}
/******************/
/* NATIVE METHODS */
/******************/
/**
* This is supposed to create a native window, put right values
* to variales in this class, create glx context...
*
*/
public native void openWindow( int width, int height );
public native void drawLine( int x1, int y1, int x2, int y2 );
public native void draw3DLine( int x1, int y1, int z1,
int x2, int y2, int z2 );
public native void drawRect( int x, int y, int width, int height );
public native void draw2DPoint( int x, int y );
public native void draw3DPoint( int x, int y, int z );
public native void drawText( int x, int y, String text, int size );
public native void draw3DText( int x, int y, int z,
String text, int size );
public native void drawingColor( double r, double g, double b, double a );
public native void drawArrow(int x, int y,
int dir_x, int dir_y, int dir_z);
public native void draw3DArrow(int x, int y, int z,
int dir_x, int dir_y, int dir_z);
public native void swapBuffers();
public native void checkEvents();
public native void setCamera( int x, int y, int z,
int ex, int ey, int ez,
int lx, int ly, int lz );
}

View File

@@ -0,0 +1,125 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class fi_iki_lukka_ZZOpenGLGraphics */
#ifndef _Included_fi_iki_lukka_ZZOpenGLGraphics
#define _Included_fi_iki_lukka_ZZOpenGLGraphics
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: openWindow
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_openWindow
(JNIEnv *, jobject, jint, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: drawLine
* Signature: (IIII)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_drawLine
(JNIEnv *, jobject, jint, jint, jint, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: draw3DLine
* Signature: (IIIIII)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_draw3DLine
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: drawRect
* Signature: (IIII)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_drawRect
(JNIEnv *, jobject, jint, jint, jint, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: draw2DPoint
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_draw2DPoint
(JNIEnv *, jobject, jint, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: draw3DPoint
* Signature: (III)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_draw3DPoint
(JNIEnv *, jobject, jint, jint, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: drawText
* Signature: (IILjava/lang/String;I)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_drawText
(JNIEnv *, jobject, jint, jint, jstring, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: draw3DText
* Signature: (IIILjava/lang/String;I)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_draw3DText
(JNIEnv *, jobject, jint, jint, jint, jstring, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: drawingColor
* Signature: (DDDD)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_drawingColor
(JNIEnv *, jobject, jdouble, jdouble, jdouble, jdouble);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: drawArrow
* Signature: (IIIII)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_drawArrow
(JNIEnv *, jobject, jint, jint, jint, jint, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: draw3DArrow
* Signature: (IIIIII)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_draw3DArrow
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jint);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: swapBuffers
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_swapBuffers
(JNIEnv *, jobject);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: checkEvents
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_checkEvents
(JNIEnv *, jobject);
/*
* Class: fi_iki_lukka_ZZOpenGLGraphics
* Method: setCamera
* Signature: (IIIIIIIII)V
*/
JNIEXPORT void JNICALL Java_fi_iki_lukka_ZZOpenGLGraphics_setCamera
(JNIEnv *, jobject, jint, jint, jint, jint, jint, jint, jint, jint, jint);
#ifdef __cplusplus
}
#endif
#endif