diff options
author | Sven Gothel <[email protected]> | 2012-10-07 12:43:16 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-10-07 12:43:16 +0200 |
commit | 747589b5c3267835c36138afded38f607ba6e04e (patch) | |
tree | 04ce175309fdfa993584e8bab132b252239bfb22 | |
parent | 0eba8e26ff1426d4fb2b6b58e9825f72def4c8f3 (diff) |
Simple JOGL2 port
- Remove _very_ old JOGL port (net.java.games.jogl.GL)
- Rename Jsr231* -> Jogl*
- Port Jsr231 to Jogl2:
- package rename of jogl/joal
- use AWT GLCanvas derivation instead of partially reimplementing it in JoglDriver
- drop some EXT suffixes
- name driver 'jogl2'
-rw-r--r-- | .classpath | 9 | ||||
-rw-r--r-- | Jake2.bat | 9 | ||||
-rw-r--r-- | Jake2.sh | 9 | ||||
-rw-r--r-- | build.xml | 571 | ||||
-rw-r--r-- | src/jake2/render/JoglRenderer.java | 483 | ||||
-rw-r--r-- | src/jake2/render/Jsr231Renderer.java | 253 | ||||
-rw-r--r-- | src/jake2/render/Renderer.java | 20 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglDriver.java | 453 | ||||
-rw-r--r-- | src/jake2/render/opengl/JoglGL.java | 152 | ||||
-rw-r--r-- | src/jake2/render/opengl/Jsr231Driver.java | 487 | ||||
-rw-r--r-- | src/jake2/render/opengl/Jsr231GL.java | 317 | ||||
-rw-r--r-- | src/jake2/sound/S.java | 2 | ||||
-rw-r--r-- | src/jake2/sound/joal/Channel.java | 12 | ||||
-rw-r--r-- | src/jake2/sound/joal/JOALSoundImpl.java | 8 | ||||
-rw-r--r-- | test/jake2/render/TestMap.java | 2 | ||||
-rw-r--r-- | test/jake2/render/TestRenderer.java | 4 | ||||
-rw-r--r-- | webstart/jake2_jogl.jnlp (renamed from webstart/jake2_jsr231.jnlp) | 4 | ||||
-rw-r--r-- | webstart/jake2_online.jnlp | 2 |
18 files changed, 849 insertions, 1948 deletions
@@ -2,13 +2,8 @@ <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="test"/> - <classpathentry kind="lib" path="lib/joal/joal.jar"/> - <classpathentry kind="lib" path="lib/jogl/jogl.jar"/> - <classpathentry kind="lib" path="lib/jsr231/jogl.jar"/> - <classpathentry kind="lib" path="lib/jsr231/gluegen-rt.jar"/> - <classpathentry kind="lib" path="lib/lwjgl/lwjgl_util.jar"/> - <classpathentry kind="lib" path="lib/lwjgl/lwjgl.jar"/> <classpathentry kind="lib" path="resources"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6"/> + <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/jogamp"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="build"/> </classpath> @@ -1,10 +1,5 @@ @echo off -REM for lwjgl -REM SET LIB=lib/lwjgl/windows -REM SET CP=build;resources;lib/lwjgl/lwjgl.jar;lib/lwjgl/lwjgl_util.jar - REM for jogl and joal -SET LIB=lib/jsr231/windows;lib/joal/windows -SET CP=build;resources;lib/jsr231/jogl.jar;lib/joal/joal.jar;lib/jsr231/gluegen-rt.jar -java -Xmx100M -Dsun.java2d.noddraw=true -Djava.library.path=%LIB% -cp %CP% jake2.Jake2
\ No newline at end of file +SET CP=lib/jogl/gluegen-rt.jar;lib/joal/joal.jar;lib/jogl/jogl-all.jar;dist/lib/jake2.jar +java -Xmx100M -Dsun.java2d.noddraw=true -Djava.library.path=%LIB% -cp %CP% jake2.Jake2 @@ -2,12 +2,7 @@ cd `dirname $0` -# for lwjgl -#LIB=lib/lwjgl/linux -#CP=build:resources:lib/lwjgl/lwjgl.jar:lib/lwjgl/lwjgl_util.jar - # for jogl and joal -LIB=lib/jsr231/linux:lib/joal/linux -CP=build:resources:lib/jsr231/jogl.jar:lib/joal/joal.jar:lib/jsr231/gluegen-rt.jar +CP=lib/jogl/gluegen-rt.jar:lib/joal/joal.jar:lib/jogl/jogl-all.jar:dist/lib/jake2.jar -exec java -Xmx100M -Djava.library.path=$LIB -cp $CP jake2.Jake2 $* +exec java -Xmx100M -cp $CP jake2.Jake2 $* @@ -1,314 +1,283 @@ <!-- Buildfile --> <project name="jake2" default="usage" basedir="."> - <taskdef name="proguard" classname="proguard.ant.ProGuardTask"> - <classpath> - <pathelement location="lib/proguard/proguard.jar"/> - </classpath> - </taskdef> - + <taskdef name="proguard" classname="proguard.ant.ProGuardTask"> + <classpath> + <pathelement location="lib/proguard/proguard.jar"/> + </classpath> + </taskdef> + - <taskdef name="izpack" classpath="lib/izpack/standalone-compiler.jar" + <taskdef name="izpack" classpath="lib/izpack/standalone-compiler.jar" classname="com.izforge.izpack.ant.IzPackTask"/> - <!-- properties --> - <property name="version" value="cvs"/> - <property name="src" location="src"/> - <property name="test" location="test"/> - <property name="build" location="build"/> - <property name="dist" location="dist"/> + <!-- properties --> + <property name="version" value="cvs"/> + <property name="src" location="src"/> + <property name="test" location="test"/> + <property name="build" location="build"/> + <property name="dist" location="dist"/> - <!-- different classpaths --> - <path id="build.class.path"> - <pathelement location="lib/jogl/jogl.jar"/> - <pathelement location="lib/jsr231/jogl.jar"/> - <pathelement location="lib/jsr231/gluegen-rt.jar"/> - <pathelement location="lib/joal/joal.jar"/> - <pathelement location="lib/lwjgl/lwjgl.jar"/> - <pathelement location="lib/lwjgl/lwjgl_util.jar"/> - <pathelement location="${java.home}/lib/plugin.jar"/> - </path> - - <!-- usage --> - <target name="usage"> - <echo message="command line arguments for build.sh or build.bat"/> - <echo message=""/> - <echo message="installer build installer"/> - <echo message="bindist build .tar.gz and .zip binary distribution"/> - <echo message="srcdist build only source distribution"/> - <echo message="all build everything"/> - <echo message="clean delete classfiles keep distribution files"/> - <echo message="distclean delete all generated files"/> - <echo message="jar build only dist/lib/jake2.jar"/> - <echo message=""/> - </target> + <!-- different classpaths --> + <path id="build.class.path"> + <pathelement location="lib/jogl/gluegen-rt.jar"/> + <pathelement location="lib/jogl/jogl-all.jar"/> + <pathelement location="lib/joal/joal.jar"/> + <pathelement location="lib/lwjgl/lwjgl.jar"/> + <pathelement location="lib/lwjgl/lwjgl_util.jar"/> + <pathelement location="${java.home}/lib/plugin.jar"/> + </path> + + <!-- usage --> + <target name="usage"> + <echo message="command line arguments for build.sh or build.bat"/> + <echo message=""/> + <echo message="installer build installer"/> + <echo message="bindist build .tar.gz and .zip binary distribution"/> + <echo message="srcdist build only source distribution"/> + <echo message="all build everything"/> + <echo message="clean delete classfiles keep distribution files"/> + <echo message="distclean delete all generated files"/> + <echo message="jar build only dist/lib/jake2.jar"/> + <echo message=""/> + </target> - <!-- initialize directories --> - <target name="init"> - <mkdir dir="${build}"/> - <mkdir dir="${dist}/lib"/> - </target> + <!-- initialize directories --> + <target name="init"> + <mkdir dir="${build}"/> + <mkdir dir="${dist}/lib"/> + </target> - <!-- compile --> - <target name="compile" depends="init"> - <javac destdir="${build}" optimize="off" debug="on" source="1.4"> - <src path="${src}"/> - <include name="jake2/**"/> - <classpath refid="build.class.path"/> - </javac> - </target> - - <!-- copy resources --> - <target name="copyres" depends="init"> - <copy todir="${build}"> - <fileset dir="resources"> - <include name="**/*"/> - </fileset> - </copy> - </target> - - <!-- copy files --> - <target name="copy"> - <copy todir="${dist}/lib"> - <fileset dir="lib/jogl"> - <include name="*.jar"/> - </fileset> - <fileset dir="lib/joal"> - <include name="*.jar"/> - </fileset> - <fileset dir="lib/lwjgl"> - <include name="*.jar"/> - </fileset> - </copy> - <copy todir="${dist}/lib/linux"> - <fileset dir="lib/jogl/linux"> - <include name="*"/> - </fileset> - <fileset dir="lib/joal/linux"> - <include name="*"/> - </fileset> - </copy> - <copy todir="${dist}/lib/linux/lwjgl"> - <fileset dir="lib/lwjgl/linux"> - <include name="*"/> - </fileset> - </copy> - <copy todir="${dist}/lib/windows"> - <fileset dir="lib/jogl/windows"> - <include name="*"/> - </fileset> - <fileset dir="lib/joal/windows"> - <include name="*"/> - </fileset> - </copy> - <copy todir="${dist}/lib/windows/lwjgl"> - <fileset dir="lib/lwjgl/windows"> - <include name="*"/> - </fileset> - </copy> - <copy todir="${dist}/lib/osx"> - <fileset dir="lib/jogl/osx"> - <include name="*"/> - </fileset> - <fileset dir="lib/joal/osx"> - <include name="*"/> - </fileset> - </copy> - <copy todir="${dist}/lib/osx/lwjgl"> - <fileset dir="lib/lwjgl/osx"> - <include name="*"/> - </fileset> - </copy> - <copy todir="${dist}"> - <fileset dir="scripts"> - <include name="Jake2*"/> - </fileset> - <fileset dir="."> - <include name="ChangeLog"/> - <include name="LICENSE"/> - <include name="README"/> - <include name="readme.id"/> - </fileset> - </copy> - <chmod perm="755"> - <fileset dir="${dist}"> - <include name="*.sh"/> - </fileset> - </chmod> - <fixcrlf srcdir="${dist}" - eol="crlf" - includes="*.bat" - /> - <fixcrlf srcdir="${dist}" - eol="lf" - includes="*.sh" - /> - </target> - - <!-- jar --> - <target name="jar" depends="compile,copyres"> - <jar destfile="${dist}/lib/jake2.jar" basedir="${build}"> - <include name="jake2/**"/> - <include name="*.png"/> - <include name="mirrors"/> - </jar> - <property name="classes" value="${java.home}/lib/rt.jar"/> - <property name="plugin" value="${java.home}/lib/plugin.jar"/> + <!-- compile --> + <target name="compile" depends="init"> + <javac destdir="${build}" optimize="off" debug="on" source="1.6"> + <src path="${src}"/> + <include name="jake2/**"/> + <classpath refid="build.class.path"/> + </javac> + </target> + + <!-- copy resources --> + <target name="copyres" depends="init"> + <copy todir="${build}"> + <fileset dir="resources"> + <include name="**/*"/> + </fileset> + </copy> + </target> + + <!-- copy files --> + <target name="copy"> + <copy todir="${dist}/lib"> + <fileset dir="lib/lwjgl"> + <include name="*.jar"/> + </fileset> + </copy> + <copy todir="${dist}/lib/linux/lwjgl"> + <fileset dir="lib/lwjgl/linux"> + <include name="*"/> + </fileset> + </copy> + <copy todir="${dist}/lib/windows/lwjgl"> + <fileset dir="lib/lwjgl/windows"> + <include name="*"/> + </fileset> + </copy> + <copy todir="${dist}/lib/osx/lwjgl"> + <fileset dir="lib/lwjgl/osx"> + <include name="*"/> + </fileset> + </copy> + + <copy todir="${dist}"> + <fileset dir="scripts"> + <include name="Jake2*"/> + </fileset> + <fileset dir="."> + <include name="ChangeLog"/> + <include name="LICENSE"/> + <include name="README"/> + <include name="readme.id"/> + </fileset> + </copy> + <chmod perm="755"> + <fileset dir="${dist}"> + <include name="*.sh"/> + </fileset> + </chmod> + <fixcrlf srcdir="${dist}" + eol="crlf" + includes="*.bat" + /> + <fixcrlf srcdir="${dist}" + eol="lf" + includes="*.sh" + /> + </target> + + <!-- jar --> + <target name="jar" depends="compile,copyres"> + <jar destfile="${dist}/lib/jake2.jar" basedir="${build}"> + <include name="jake2/**"/> + <include name="*.png"/> + <include name="mirrors"/> + </jar> + <property name="classes" value="${java.home}/lib/rt.jar"/> + <property name="plugin" value="${java.home}/lib/plugin.jar"/> <condition property="classes" value="${java.home}/../Classes/classes.jar"> <os name="Mac OS X"/> - </condition> - <!-- proguard printseeds="on" printusage="off" outjar="${dist}/lib/jake2.jar" - defaultpackage="" overloadaggressively="off" printmapping="jake2.map"> - <injar name="jake2.jar"/> - <libraryjar name="lib/jogl/jogl.jar"/> - <libraryjar name="lib/jsr231/jogl.jar"/> - <libraryjar name="lib/joal/joal.jar"/> - <libraryjar name="lib/joal/gluegen-rt.jar"/> - <libraryjar name="${classes}"/> - <libraryjar name="${plugin}"/> - <keep access="public" name="jake2.Jake2"> - <method name="main(java.lang.String[])"/> - </keep> - </proguard --> - </target> - - <target name="patch" depends="copy"> - <!-- performance patch for lwjgl --> - <javac destdir="${build}" optimize="off" debug="on" source="1.4"> - <src path="lib/lwjgl/patch"/> - <include name="org/lwjgl/**"/> - <classpath refid="build.class.path"/> - </javac> - <!-- update original lwjgl.jar --> - <jar destfile="${dist}/lib/lwjgl.jar" basedir="${build}" update="true"> - <include name="org/lwjgl/**"/> - </jar> - </target> - - <!-- everything --> - <target name="all" depends="installer,bindist,srcdist"> - </target> + </condition> + <!-- proguard printseeds="on" printusage="off" outjar="${dist}/lib/jake2.jar" + defaultpackage="" overloadaggressively="off" printmapping="jake2.map"> + <injar name="jake2.jar"/> + <libraryjar name="lib/jogl/jogl-all.jar"/> + <libraryjar name="lib/joal/joal.jar"/> + <libraryjar name="lib/joal/gluegen-rt.jar"/> + <libraryjar name="${classes}"/> + <libraryjar name="${plugin}"/> + <keep access="public" name="jake2.Jake2"> + <method name="main(java.lang.String[])"/> + </keep> + </proguard --> + </target> + + <target name="patch" depends="copy"> + <!-- performance patch for lwjgl --> + <javac destdir="${build}" optimize="off" debug="on" source="1.6"> + <src path="lib/lwjgl/patch"/> + <include name="org/lwjgl/**"/> + <classpath refid="build.class.path"/> + </javac> + <!-- update original lwjgl.jar --> + <jar destfile="${dist}/lib/lwjgl.jar" basedir="${build}" update="true"> + <include name="org/lwjgl/**"/> + </jar> + </target> + + <!-- everything --> + <target name="all" depends="installer,bindist,srcdist"> + </target> - <!-- dist --> - <target name="dist" depends="jar,copy,patch"> - </target> - - <!-- binary distribution --> - <target name="bindist" depends="dist"> - <tar destfile="jake2-${version}.tar.gz" compression="gzip"> - <tarfileset dir="${dist}" prefix="Jake2" mode="755"> - <include name="*.sh"/> - </tarfileset> - <tarfileset dir="${dist}" prefix="Jake2"> - <include name="**"/> - <exclude name="*.sh"/> - </tarfileset> - </tar> - <zip destfile="jake2-${version}.zip"> - <zipfileset dir="${dist}" prefix="Jake2"> - <include name="**"/> - </zipfileset> - </zip> - </target> - - <!-- source distribution --> - <target name="srcdist"> - <tar destfile="jake2src-${version}.tar.gz" compression="gzip"> - <tarfileset dir="." prefix="Jake2" mode="755"> - <include name="scripts/*.*"/> - <include name="build.sh"/> - </tarfileset> - <tarfileset dir="." prefix="Jake2"> - <include name="src/jake2/**"/> - <include name="resources/**"/> - <include name="lib/**"/> - <include name="build.xml"/> - <include name="build.bat"/> - <include name="ChangeLog"/> - <include name="LICENSE"/> - <include name="README*"/> - <include name="install.xml"/> - <include name="readme.id"/> - <include name="Jake2_Eclipse_Setup.txt"/> - </tarfileset> - </tar> - <zip destfile="jake2src-${version}.zip"> - <zipfileset dir="." prefix="Jake2"> - <include name="src/jake2/**"/> - <include name="resources/**"/> - <include name="scripts/*.*"/> - <include name="lib/**"/> - <include name="build.xml"/> - <include name="build.sh"/> - <include name="build.bat"/> - <include name="ChangeLog"/> - <include name="LICENSE"/> - <include name="README*"/> - <include name="install.xml"/> - <include name="readme.id"/> - <include name="Jake2_Eclipse_Setup.txt"/> - </zipfileset> - </zip> - </target> - - <!-- standalone installer --> - <target name="installer" depends="dist"> - <izpack input="${basedir}/install.xml" - output="${basedir}/Jake2-${version}-install.jar" - installerType="standard" - basedir="${dist}" - izPackDir="${basedir}/lib/izpack"/> - </target> - - <!-- webstart --> - <target name="webstart" depends="dist"> - <mkdir dir="webstart/lib"/> - <copy todir="webstart/lib"> - <fileset dir="${dist}/lib"> - <include name="**/*.jar"/> - <exclude name="jogl.jar"/> - <exclude name="joal.jar"/> - <exclude name="gluegen-rt.jar"/> - </fileset> - </copy> + <!-- dist --> + <target name="dist" depends="jar,copy,patch"> + </target> + + <!-- binary distribution --> + <target name="bindist" depends="dist"> + <tar destfile="jake2-${version}.tar.gz" compression="gzip"> + <tarfileset dir="${dist}" prefix="Jake2" mode="755"> + <include name="*.sh"/> + </tarfileset> + <tarfileset dir="${dist}" prefix="Jake2"> + <include name="**"/> + <exclude name="*.sh"/> + </tarfileset> + </tar> + <zip destfile="jake2-${version}.zip"> + <zipfileset dir="${dist}" prefix="Jake2"> + <include name="**"/> + </zipfileset> + </zip> + </target> + + <!-- source distribution --> + <target name="srcdist"> + <tar destfile="jake2src-${version}.tar.gz" compression="gzip"> + <tarfileset dir="." prefix="Jake2" mode="755"> + <include name="scripts/*.*"/> + <include name="build.sh"/> + </tarfileset> + <tarfileset dir="." prefix="Jake2"> + <include name="src/jake2/**"/> + <include name="resources/**"/> + <include name="lib/**"/> + <include name="build.xml"/> + <include name="build.bat"/> + <include name="ChangeLog"/> + <include name="LICENSE"/> + <include name="README*"/> + <include name="install.xml"/> + <include name="readme.id"/> + <include name="Jake2_Eclipse_Setup.txt"/> + </tarfileset> + </tar> + <zip destfile="jake2src-${version}.zip"> + <zipfileset dir="." prefix="Jake2"> + <include name="src/jake2/**"/> + <include name="resources/**"/> + <include name="scripts/*.*"/> + <include name="lib/**"/> + <include name="build.xml"/> + <include name="build.sh"/> + <include name="build.bat"/> + <include name="ChangeLog"/> + <include name="LICENSE"/> + <include name="README*"/> + <include name="install.xml"/> + <include name="readme.id"/> + <include name="Jake2_Eclipse_Setup.txt"/> + </zipfileset> + </zip> + </target> + + <!-- standalone installer --> + <target name="installer" depends="dist"> + <izpack input="${basedir}/install.xml" + output="${basedir}/Jake2-${version}-install.jar" + installerType="standard" + basedir="${dist}" + izPackDir="${basedir}/lib/izpack"/> + </target> + + <!-- webstart --> + <target name="webstart" depends="dist"> + <mkdir dir="webstart/lib"/> + <copy todir="webstart/lib"> + <fileset dir="${dist}/lib"> + <include name="**/*.jar"/> + <exclude name="joal.jar"/> + <exclude name="gluegen-rt.jar"/> + <exclude name="jogl-all.jar"/> + </fileset> + </copy> - <mkdir dir="webstart/lib/linux"/> - <jar destfile="webstart/lib/linux/lwjgl-native.jar" basedir="${dist}/lib/linux/lwjgl"> - <include name="*.so"/> - </jar> - <mkdir dir="webstart/lib/osx"/> - <jar destfile="webstart/lib/osx/lwjgl-native.jar" basedir="${dist}/lib/osx/lwjgl"> - <include name="liblwjgl.jnilib"/> - <include name="openal.dylib"/> - </jar> - <mkdir dir="webstart/lib/windows"/> - <jar destfile="webstart/lib/windows/lwjgl-native.jar" basedir="${dist}/lib/windows/lwjgl"> - <include name="lwjgl.dll"/> - <include name="OpenAL32.dll"/> - </jar> - <signjar keystore="${user.home}/bytonic" alias="bytonic" storepass="${bytonic.pass}"> - <fileset dir="webstart/lib"> - <include name="**/*.jar"/> - </fileset> - </signjar> - </target> - - <!-- clean --> - <target name="clean"> - <delete dir="${build}"/> - </target> - - <!-- distclean --> - <target name="distclean" depends="clean"> - <delete dir="${dist}"/> - <delete dir="webstart/lib"/> - <delete> - <fileset dir="."> - <include name="*.tar.gz"/> - <include name="*.zip"/> - <include name="*.map"/> - <include name="*.jar"/> - </fileset> - </delete> - </target> -</project>
\ No newline at end of file + <mkdir dir="webstart/lib/linux"/> + <jar destfile="webstart/lib/linux/lwjgl-native.jar" basedir="${dist}/lib/linux/lwjgl"> + <include name="*.so"/> + </jar> + <mkdir dir="webstart/lib/osx"/> + <jar destfile="webstart/lib/osx/lwjgl-native.jar" basedir="${dist}/lib/osx/lwjgl"> + <include name="liblwjgl.jnilib"/> + <include name="openal.dylib"/> + </jar> + <mkdir dir="webstart/lib/windows"/> + <jar destfile="webstart/lib/windows/lwjgl-native.jar" basedir="${dist}/lib/windows/lwjgl"> + <include name="lwjgl.dll"/> + <include name="OpenAL32.dll"/> + </jar> + <signjar keystore="${user.home}/bytonic" alias="bytonic" storepass="${bytonic.pass}"> + <fileset dir="webstart/lib"> + <include name="**/*.jar"/> + </fileset> + </signjar> + </target> + + <!-- clean --> + <target name="clean"> + <delete dir="${build}"/> + </target> + + <!-- distclean --> + <target name="distclean" depends="clean"> + <delete dir="${dist}"/> + <delete dir="webstart/lib"/> + <delete> + <fileset dir="."> + <include name="*.tar.gz"/> + <include name="*.zip"/> + <include name="*.map"/> + <include name="*.jar"/> + </fileset> + </delete> + </target> +</project> diff --git a/src/jake2/render/JoglRenderer.java b/src/jake2/render/JoglRenderer.java index 88f4296..19e1888 100644 --- a/src/jake2/render/JoglRenderer.java +++ b/src/jake2/render/JoglRenderer.java @@ -1,8 +1,7 @@ /* * JoglRenderer.java - * Copyright (C) 2003 + * Copyright (C) 2004 * - * $Id: JoglRenderer.java,v 1.10 2006-12-12 13:02:25 cawe Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -22,13 +21,12 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ + */ package jake2.render; import jake2.Defines; import jake2.client.refdef_t; import jake2.client.refexport_t; -import jake2.qcommon.xcommand_t; import jake2.render.opengl.JoglDriver; import jake2.sys.JOGLKBD; import jake2.sys.KBD; @@ -38,290 +36,217 @@ import java.awt.Dimension; /** * JoglRenderer * - * @author cwei + * @author dsanders/cwei */ final class JoglRenderer extends JoglDriver implements refexport_t, Ref { - public static final String DRIVER_NAME = "jogl"; - - private KBD kbd = new JOGLKBD(); + public static final String DRIVER_NAME = "jogl2"; - // is set from Renderer factory - private RenderAPI impl; + private KBD kbd = new JOGLKBD(); - static { - Renderer.register(new JoglRenderer()); - }; + // is set from Renderer factory + private RenderAPI impl; - private JoglRenderer() { - // singleton - } + static { + Renderer.register(new JoglRenderer()); + }; - // ============================================================================ - // public interface for Renderer implementations - // - // refexport_t (ref.h) - // ============================================================================ + private JoglRenderer() { + // singleton + } + // ============================================================================ + // public interface for Renderer implementations + // + // refexport_t (ref.h) + // ============================================================================ - private boolean post_init = false; - /** - * @see jake2.client.refexport_t#Init() - */ - public boolean Init(int vid_xpos, int vid_ypos) { + * @see jake2.client.refexport_t#Init() + */ + public boolean Init(int vid_xpos, int vid_ypos) { // init the OpenGL drivers impl.setGLDriver(this); - // pre init - if (!impl.R_Init(vid_xpos, vid_ypos)) return false; - // calls the R_Init2() internally - updateScreen(new xcommand_t() { - public void execute() { - JoglRenderer.this.post_init = impl.R_Init2(); - } - }); - // the result from R_Init2() - return post_init; - } - - /** - * @see jake2.client.refexport_t#Shutdown() - */ - public void Shutdown() { - impl.R_Shutdown(); - } - - /** - * @see jake2.client.refexport_t#BeginRegistration(java.lang.String) - */ - public void BeginRegistration(final String map) { - if (contextInUse) { - impl.R_BeginRegistration(map); - } else { - updateScreen(new xcommand_t() { - public void execute() { - impl.R_BeginRegistration(map); - } - }); - } - } - - private model_t model = null; - - /** - * @see jake2.client.refexport_t#RegisterModel(java.lang.String) - */ - public model_t RegisterModel(final String name) { - if (contextInUse) { - return impl.R_RegisterModel(name); - } else { - updateScreen(new xcommand_t() { - public void execute() { - JoglRenderer.this.model = impl.R_RegisterModel(name); - } - }); - return model; - } - } - - private image_t image = null; - - /** - * @see jake2.client.refexport_t#RegisterSkin(java.lang.String) - */ - public image_t RegisterSkin(final String name) { - if (contextInUse) { - return impl.R_RegisterSkin(name); - } else { - updateScreen(new xcommand_t() { - public void execute() { - JoglRenderer.this.image = impl.R_RegisterSkin(name); - } - }); - return image; - } - } - - /** - * @see jake2.client.refexport_t#RegisterPic(java.lang.String) - */ - public image_t RegisterPic(final String name) { - if (contextInUse) { - return impl.Draw_FindPic(name); - } else { - updateScreen(new xcommand_t() { - public void execute() { - JoglRenderer.this.image = impl.Draw_FindPic(name); - } - }); - return image; - } - } - - /** - * @see jake2.client.refexport_t#SetSky(java.lang.String, float, float[]) - */ - public void SetSky(final String name, final float rotate, final float[] axis) { - if (contextInUse) { - impl.R_SetSky(name, rotate, axis); - } else { - updateScreen(new xcommand_t() { - public void execute() { - impl.R_SetSky(name, rotate, axis); - } - }); - } - } - - /** - * @see jake2.client.refexport_t#EndRegistration() - */ - public void EndRegistration() { - if (contextInUse) { - impl.R_EndRegistration(); - } else { - updateScreen(new xcommand_t() { - public void execute() { - impl.R_EndRegistration(); - } - }); - } - } - - /** - * @see jake2.client.refexport_t#RenderFrame(jake2.client.refdef_t) - */ - public void RenderFrame(refdef_t fd) { - impl.R_RenderFrame(fd); - } - - /** - * @see jake2.client.refexport_t#DrawGetPicSize(java.awt.Dimension, java.lang.String) - */ - public void DrawGetPicSize(Dimension dim, String name) { - impl.Draw_GetPicSize(dim, name); - } - - /** - * @see jake2.client.refexport_t#DrawPic(int, int, java.lang.String) - */ - public void DrawPic(int x, int y, String name) { - impl.Draw_Pic(x, y, name); - } - - /** - * @see jake2.client.refexport_t#DrawStretchPic(int, int, int, int, java.lang.String) - */ - public void DrawStretchPic(int x, int y, int w, int h, String name) { - impl.Draw_StretchPic(x, y, w, h, name); - } - - /** - * @see jake2.client.refexport_t#DrawChar(int, int, int) - */ - public void DrawChar(final int x, final int y, final int num) { - if (contextInUse) { - impl.Draw_Char(x, y, num);; - } else { - updateScreen(new xcommand_t() { - public void execute() { - impl.Draw_Char(x, y, num); - } - }); - } - } - - /** - * @see jake2.client.refexport_t#DrawTileClear(int, int, int, int, java.lang.String) - */ - public void DrawTileClear(int x, int y, int w, int h, String name) { - impl.Draw_TileClear(x, y, w, h, name); - } - - /** - * @see jake2.client.refexport_t#DrawFill(int, int, int, int, int) - */ - public void DrawFill(int x, int y, int w, int h, int c) { - impl.Draw_Fill(x, y, w, h, c); - } - - /** - * @see jake2.client.refexport_t#DrawFadeScreen() - */ - public void DrawFadeScreen() { - impl.Draw_FadeScreen(); - } - - /** - * @see jake2.client.refexport_t#DrawStretchRaw(int, int, int, int, int, int, byte[]) - */ - public void DrawStretchRaw(int x, int y, int w, int h, int cols, int rows, byte[] data) { - impl.Draw_StretchRaw(x, y, w, h, cols, rows, data); - } - - /** - * @see jake2.client.refexport_t#CinematicSetPalette(byte[]) - */ - public void CinematicSetPalette(byte[] palette) { - impl.R_SetPalette(palette); - } - - /** - * @see jake2.client.refexport_t#BeginFrame(float) - */ - public void BeginFrame(float camera_separation) { - impl.R_BeginFrame(camera_separation); - } - - /** - * @see jake2.client.refexport_t#EndFrame() - */ - public void EndFrame() { - endFrame(); - } - - /** - * @see jake2.client.refexport_t#AppActivate(boolean) - */ - public void AppActivate(boolean activate) { - appActivate(activate); - } - - public void screenshot() { - if (contextInUse) { - impl.GL_ScreenShot_f(); - } else { - updateScreen(new xcommand_t() { - public void execute() { - impl.GL_ScreenShot_f(); - } - }); - } - } - - public int apiVersion() { - return Defines.API_VERSION; - } - - public KBD getKeyboardHandler() { - return kbd; - } - - // ============================================================================ - // Ref interface - // ============================================================================ - - public String getName() { - return DRIVER_NAME; - } - - public String toString() { - return DRIVER_NAME; - } - - public refexport_t GetRefAPI(RenderAPI renderer) { - this.impl = renderer; - return this; - } - -}
\ No newline at end of file + // pre init + if (!impl.R_Init(vid_xpos, vid_ypos)) return false; + // activates the OpenGL context + activate(); + // post init + return impl.R_Init2(); + } + + /** + * @see jake2.client.refexport_t#Shutdown() + */ + public void Shutdown() { + impl.R_Shutdown(); + } + + /** + * @see jake2.client.refexport_t#BeginRegistration(java.lang.String) + */ + public final void BeginRegistration(String map) { + activate(); + impl.R_BeginRegistration(map); + } + + /** + * @see jake2.client.refexport_t#RegisterModel(java.lang.String) + */ + public final model_t RegisterModel(String name) { + activate(); + return impl.R_RegisterModel(name); + } + + /** + * @see jake2.client.refexport_t#RegisterSkin(java.lang.String) + */ + public final image_t RegisterSkin(String name) { + activate(); + return impl.R_RegisterSkin(name); + } + + /** + * @see jake2.client.refexport_t#RegisterPic(java.lang.String) + */ + public final image_t RegisterPic(String name) { + activate(); + return impl.Draw_FindPic(name); + } + /** + * @see jake2.client.refexport_t#SetSky(java.lang.String, float, float[]) + */ + public final void SetSky(String name, float rotate, float[] axis) { + activate(); + impl.R_SetSky(name, rotate, axis); + } + + /** + * @see jake2.client.refexport_t#EndRegistration() + */ + public final void EndRegistration() { + activate(); + impl.R_EndRegistration(); + } + + /** + * @see jake2.client.refexport_t#RenderFrame(jake2.client.refdef_t) + */ + public final void RenderFrame(refdef_t fd) { + impl.R_RenderFrame(fd); + } + + /** + * @see jake2.client.refexport_t#DrawGetPicSize(java.awt.Dimension, java.lang.String) + */ + public final void DrawGetPicSize(Dimension dim, String name) { + impl.Draw_GetPicSize(dim, name); + } + + /** + * @see jake2.client.refexport_t#DrawPic(int, int, java.lang.String) + */ + public final void DrawPic(int x, int y, String name) { + impl.Draw_Pic(x, y, name); + } + + /** + * @see jake2.client.refexport_t#DrawStretchPic(int, int, int, int, java.lang.String) + */ + public final void DrawStretchPic(int x, int y, int w, int h, String name) { + impl.Draw_StretchPic(x, y, w, h, name); + } + + /** + * @see jake2.client.refexport_t#DrawChar(int, int, int) + */ + public final void DrawChar(int x, int y, int num) { + activate(); + impl.Draw_Char(x, y, num); + } + + /** + * @see jake2.client.refexport_t#DrawTileClear(int, int, int, int, java.lang.String) + */ + public final void DrawTileClear(int x, int y, int w, int h, String name) { + impl.Draw_TileClear(x, y, w, h, name); + } + + /** + * @see jake2.client.refexport_t#DrawFill(int, int, int, int, int) + */ + public final void DrawFill(int x, int y, int w, int h, int c) { + impl.Draw_Fill(x, y, w, h, c); + } + + /** + * @see jake2.client.refexport_t#DrawFadeScreen() + */ + public final void DrawFadeScreen() { + impl.Draw_FadeScreen(); + } + + /** + * @see jake2.client.refexport_t#DrawStretchRaw(int, int, int, int, int, int, byte[]) + */ + public final void DrawStretchRaw(int x, int y, int w, int h, int cols, int rows, byte[] data) { + impl.Draw_StretchRaw(x, y, w, h, cols, rows, data); + } + + /** + * @see jake2.client.refexport_t#CinematicSetPalette(byte[]) + */ + public final void CinematicSetPalette(byte[] palette) { + impl.R_SetPalette(palette); + } + + /** + * @see jake2.client.refexport_t#BeginFrame(float) + */ + public final void BeginFrame(float camera_separation) { + impl.R_BeginFrame(camera_separation); + } + + /** + * @see jake2.client.refexport_t#EndFrame() + */ + public final void EndFrame() { + endFrame(); + } + + /** + * @see jake2.client.refexport_t#AppActivate(boolean) + */ + public final void AppActivate(boolean activate) { + appActivate(activate); + } + + public void screenshot() { + activate(); + impl.GL_ScreenShot_f(); + } + + public final int apiVersion() { + return Defines.API_VERSION; + } + + public KBD getKeyboardHandler() { + return kbd; + } + // ============================================================================ + // Ref interface + // ============================================================================ + + public final String getName() { + return DRIVER_NAME; + } + + public final String toString() { + return DRIVER_NAME; + } + + public final refexport_t GetRefAPI(RenderAPI renderer) { + this.impl = renderer; + return this; + } +} diff --git a/src/jake2/render/Jsr231Renderer.java b/src/jake2/render/Jsr231Renderer.java deleted file mode 100644 index 4c32648..0000000 --- a/src/jake2/render/Jsr231Renderer.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Jsr231Renderer.java - * Copyright (C) 2004 - * - * $Id: Jsr231Renderer.java,v 1.3 2006-11-22 15:05:39 cawe Exp $ - */ -/* -Copyright (C) 1997-2001 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program 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 GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -package jake2.render; - -import jake2.Defines; -import jake2.client.refdef_t; -import jake2.client.refexport_t; -import jake2.render.opengl.Jsr231Driver; -import jake2.sys.JOGLKBD; -import jake2.sys.KBD; - -import java.awt.Dimension; - -/** - * Jsr231Renderer - * - * @author dsanders/cwei - */ -final class Jsr231Renderer extends Jsr231Driver implements refexport_t, Ref { - - public static final String DRIVER_NAME = "jsr231"; - - private KBD kbd = new JOGLKBD(); - - // is set from Renderer factory - private RenderAPI impl; - - static { - Renderer.register(new Jsr231Renderer()); - }; - - private Jsr231Renderer() { - // singleton - } - - // ============================================================================ - // public interface for Renderer implementations - // - // refexport_t (ref.h) - // ============================================================================ - - /** - * @see jake2.client.refexport_t#Init() - */ - public boolean Init(int vid_xpos, int vid_ypos) { - // init the OpenGL drivers - impl.setGLDriver(this); - // pre init - if (!impl.R_Init(vid_xpos, vid_ypos)) return false; - // activates the OpenGL context - activate(); - // post init - return impl.R_Init2(); - } - - /** - * @see jake2.client.refexport_t#Shutdown() - */ - public void Shutdown() { - impl.R_Shutdown(); - } - - /** - * @see jake2.client.refexport_t#BeginRegistration(java.lang.String) - */ - public final void BeginRegistration(String map) { - activate(); - impl.R_BeginRegistration(map); - } - - /** - * @see jake2.client.refexport_t#RegisterModel(java.lang.String) - */ - public final model_t RegisterModel(String name) { - activate(); - return impl.R_RegisterModel(name); - } - - /** - * @see jake2.client.refexport_t#RegisterSkin(java.lang.String) - */ - public final image_t RegisterSkin(String name) { - activate(); - return impl.R_RegisterSkin(name); - } - - /** - * @see jake2.client.refexport_t#RegisterPic(java.lang.String) - */ - public final image_t RegisterPic(String name) { - activate(); - return impl.Draw_FindPic(name); - } - /** - * @see jake2.client.refexport_t#SetSky(java.lang.String, float, float[]) - */ - public final void SetSky(String name, float rotate, float[] axis) { - activate(); - impl.R_SetSky(name, rotate, axis); - } - - /** - * @see jake2.client.refexport_t#EndRegistration() - */ - public final void EndRegistration() { - activate(); - impl.R_EndRegistration(); - } - - /** - * @see jake2.client.refexport_t#RenderFrame(jake2.client.refdef_t) - */ - public final void RenderFrame(refdef_t fd) { - impl.R_RenderFrame(fd); - } - - /** - * @see jake2.client.refexport_t#DrawGetPicSize(java.awt.Dimension, java.lang.String) - */ - public final void DrawGetPicSize(Dimension dim, String name) { - impl.Draw_GetPicSize(dim, name); - } - - /** - * @see jake2.client.refexport_t#DrawPic(int, int, java.lang.String) - */ - public final void DrawPic(int x, int y, String name) { - impl.Draw_Pic(x, y, name); - } - - /** - * @see jake2.client.refexport_t#DrawStretchPic(int, int, int, int, java.lang.String) - */ - public final void DrawStretchPic(int x, int y, int w, int h, String name) { - impl.Draw_StretchPic(x, y, w, h, name); - } - - /** - * @see jake2.client.refexport_t#DrawChar(int, int, int) - */ - public final void DrawChar(int x, int y, int num) { - activate(); - impl.Draw_Char(x, y, num); - } - - /** - * @see jake2.client.refexport_t#DrawTileClear(int, int, int, int, java.lang.String) - */ - public final void DrawTileClear(int x, int y, int w, int h, String name) { - impl.Draw_TileClear(x, y, w, h, name); - } - - /** - * @see jake2.client.refexport_t#DrawFill(int, int, int, int, int) - */ - public final void DrawFill(int x, int y, int w, int h, int c) { - impl.Draw_Fill(x, y, w, h, c); - } - - /** - * @see jake2.client.refexport_t#DrawFadeScreen() - */ - public final void DrawFadeScreen() { - impl.Draw_FadeScreen(); - } - - /** - * @see jake2.client.refexport_t#DrawStretchRaw(int, int, int, int, int, int, byte[]) - */ - public final void DrawStretchRaw(int x, int y, int w, int h, int cols, int rows, byte[] data) { - impl.Draw_StretchRaw(x, y, w, h, cols, rows, data); - } - - /** - * @see jake2.client.refexport_t#CinematicSetPalette(byte[]) - */ - public final void CinematicSetPalette(byte[] palette) { - impl.R_SetPalette(palette); - } - - /** - * @see jake2.client.refexport_t#BeginFrame(float) - */ - public final void BeginFrame(float camera_separation) { - impl.R_BeginFrame(camera_separation); - } - - /** - * @see jake2.client.refexport_t#EndFrame() - */ - public final void EndFrame() { - endFrame(); - } - - /** - * @see jake2.client.refexport_t#AppActivate(boolean) - */ - public final void AppActivate(boolean activate) { - appActivate(activate); - } - - public void screenshot() { - activate(); - impl.GL_ScreenShot_f(); - } - - public final int apiVersion() { - return Defines.API_VERSION; - } - - public KBD getKeyboardHandler() { - return kbd; - } - // ============================================================================ - // Ref interface - // ============================================================================ - - public final String getName() { - return DRIVER_NAME; - } - - public final String toString() { - return DRIVER_NAME; - } - - public final refexport_t GetRefAPI(RenderAPI renderer) { - this.impl = renderer; - return this; - } -}
\ No newline at end of file diff --git a/src/jake2/render/Renderer.java b/src/jake2/render/Renderer.java index ea5d449..a283640 100644 --- a/src/jake2/render/Renderer.java +++ b/src/jake2/render/Renderer.java @@ -39,17 +39,11 @@ public class Renderer { static RenderAPI fastRenderer = new jake2.render.fast.Misc(); static RenderAPI basicRenderer = new jake2.render.basic.Misc(); - static Vector drivers = new Vector(3); + static Vector drivers = new Vector(2); static { try { try { - Class.forName("net.java.games.jogl.GL"); - Class.forName("jake2.render.JoglRenderer"); - } catch (ClassNotFoundException e) { - // ignore the old jogl driver if runtime not in classpath - } - try { Class.forName("org.lwjgl.opengl.GL11"); Class.forName("jake2.render.LwjglRenderer"); } catch (ClassNotFoundException e) { @@ -57,9 +51,10 @@ public class Renderer { } try { Class.forName("javax.media.opengl.GL"); - Class.forName("jake2.render.Jsr231Renderer"); + Class.forName("jake2.render.JoglRenderer"); } catch (ClassNotFoundException e) { // ignore the new jogl driver if runtime not in classpath + e.printStackTrace(); } } catch (Throwable e) { e.printStackTrace(); @@ -72,6 +67,8 @@ public class Renderer { "Ref implementation can't be null"); } if (!drivers.contains(impl)) { + System.err.println("Add driver: "+impl+", "+impl.getName()); + Thread.dumpStack(); drivers.add(impl); } } @@ -115,8 +112,9 @@ public class Renderer { } public static String[] getDriverNames() { - if (drivers.isEmpty()) - return null; + if (drivers.isEmpty()) { + return new String[0]; + } int count = drivers.size(); String[] names = new String[count]; @@ -126,4 +124,4 @@ public class Renderer { return names; } -}
\ No newline at end of file +} diff --git a/src/jake2/render/opengl/JoglDriver.java b/src/jake2/render/opengl/JoglDriver.java index 45ab03e..d4141ed 100644 --- a/src/jake2/render/opengl/JoglDriver.java +++ b/src/jake2/render/opengl/JoglDriver.java @@ -1,8 +1,7 @@ /* - * JoglCommon.java + * JoglDriver.java * Copyright (C) 2004 * - * $Id: JoglDriver.java,v 1.3 2006-11-22 15:05:39 cawe Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -27,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package jake2.render.opengl; import jake2.Defines; +import jake2.Globals; +import jake2.SizeChangeListener; import jake2.client.VID; import jake2.qcommon.Cbuf; import jake2.qcommon.xcommand_t; @@ -38,55 +39,34 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.LinkedList; +import javax.media.opengl.*; +import javax.media.opengl.awt.GLCanvas; import javax.swing.ImageIcon; -import javax.swing.JFrame; - -import net.java.games.jogl.*; /** * JoglCommon */ -public abstract class JoglDriver extends JoglGL implements GLDriver, GLEventListener { - +public abstract class JoglDriver extends JoglGL implements GLDriver { + protected JoglDriver() { - // see JoglRenderer + // singleton } - + private GraphicsDevice device; private DisplayMode oldDisplayMode; - private GLCanvas canvas; - JFrame window; + private volatile Display display; + private volatile Frame window; + + // This is either the above Window reference or the global + // applet if we're running in applet mode + private volatile Container container; // window position on the screen int window_xpos, window_ypos; - // handles the post initialization with JoglRenderer - protected boolean post_init = false; - protected boolean contextInUse = false; - - protected final xcommand_t INIT_CALLBACK = new xcommand_t() { - public void execute() { - // only used for the first run (initialization) - // clear the screen - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // - // check the post init process - // - if (!post_init) { - VID.Printf(Defines.PRINT_ALL, "Missing multi-texturing for FastJOGL renderer\n"); - } - - endFrame(); - } - }; - - xcommand_t callback = INIT_CALLBACK; - public DisplayMode[] getModeList() { DisplayMode[] modes = device.getDisplayModes(); - LinkedList l = new LinkedList(); + LinkedList<DisplayMode> l = new LinkedList<DisplayMode>(); l.add(oldDisplayMode); for (int i = 0; i < modes.length; i++) { @@ -156,152 +136,234 @@ public abstract class JoglDriver extends JoglGL implements GLDriver, GLEventList */ public int setMode(Dimension dim, int mode, boolean fullscreen) { - Dimension newDim = new Dimension(); + final Dimension newDim = new Dimension(); VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n"); VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); + if (Globals.appletMode && container == null) { + container = (Container) Globals.applet; + } + /* - * fullscreen handling + * full screen handling */ - GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); - device = env.getDefaultScreenDevice(); - - if (oldDisplayMode == null) { - oldDisplayMode = device.getDisplayMode(); - } - - if (!VID.GetModeInfo(newDim, mode)) { - VID.Printf(Defines.PRINT_ALL, " invalid mode\n"); - return Base.rserr_invalid_mode; + if (device == null) { + GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); + device = env.getDefaultScreenDevice(); } + + if (oldDisplayMode == null) { + oldDisplayMode = device.getDisplayMode(); + } + + if (!VID.GetModeInfo(newDim, mode)) { + VID.Printf(Defines.PRINT_ALL, " invalid mode\n"); + return Base.rserr_invalid_mode; + } + + VID.Printf(Defines.PRINT_ALL, " " + newDim.width + " " + newDim.height + '\n'); + + if (!Globals.appletMode) { + // destroy the existing window + if (window != null) shutdown(); + + window = new Frame("Jake2 (jogl2)"); + container = window; + ImageIcon icon = new ImageIcon(getClass().getResource("/icon-small.png")); + window.setIconImage(icon.getImage()); + window.setLayout(new GridBagLayout()); + // register event listener + window.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); + } + }); + } + + if (Globals.appletMode) { + // Destroy the previous display if there is one + shutdown(); + + // We don't support full-screen mode + fullscreen = false; + + // We need to feed the container to the JOGL + // keyboard class manually because we'll never get + // a component shown event for it + JOGLKBD.Init(container); + } + + Display canvas = new Display(new GLCapabilities(GLProfile.get(GLProfile.GL2))); + // we want keypressed events for TAB key + canvas.setFocusTraversalKeysEnabled(false); + canvas.setSize(newDim.width, newDim.height); + + // the OpenGL canvas grows and shrinks with the window + final GridBagConstraints gbc = new GridBagConstraints(); + gbc.fill = GridBagConstraints.BOTH; + gbc.weightx = gbc.weighty = 1; + + // D I F F E R E N T J A K E 2 E V E N T P R O C E S S I N G + container.addComponentListener(JOGLKBD.listener); + canvas.addKeyListener(JOGLKBD.listener); + canvas.addMouseListener(JOGLKBD.listener); + canvas.addMouseMotionListener(JOGLKBD.listener); + canvas.addMouseWheelListener(JOGLKBD.listener); + + if (fullscreen) { - VID.Printf(Defines.PRINT_ALL, " " + newDim.width + " " + newDim.height + '\n'); - - // destroy the existing window - shutdown(); + container.add(canvas, gbc); - window = new JFrame("Jake2 (jogl)"); - ImageIcon icon = new ImageIcon(getClass().getResource("/icon-small.png")); - window.setIconImage(icon.getImage()); - - GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities()); + DisplayMode displayMode = findDisplayMode(newDim); - // we want keypressed events for TAB key - canvas.setFocusTraversalKeysEnabled(false); - - // TODO Use debug pipeline - //canvas.setGL(new DebugGL(canvas.getGL())); + newDim.width = displayMode.getWidth(); + newDim.height = displayMode.getHeight(); + window.setUndecorated(true); + window.setResizable(false); - canvas.setNoAutoRedrawMode(true); - canvas.setAutoSwapBufferMode(false); - - canvas.addGLEventListener(this); + device.setFullScreenWindow(window); - window.getContentPane().add(canvas); - canvas.setSize(newDim.width, newDim.height); + if (device.isFullScreenSupported()) + device.setDisplayMode(displayMode); - // register event listener - window.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); - } - }); - - // D I F F E R E N T J A K E 2 E V E N T P R O C E S S I N G - window.addComponentListener(JOGLKBD.listener); - canvas.addKeyListener(JOGLKBD.listener); - canvas.addMouseListener(JOGLKBD.listener); - canvas.addMouseMotionListener(JOGLKBD.listener); - canvas.addMouseWheelListener(JOGLKBD.listener); - - if (fullscreen) { - - DisplayMode displayMode = findDisplayMode(newDim); - - newDim.width = displayMode.getWidth(); - newDim.height = displayMode.getHeight(); - window.setUndecorated(true); - window.setResizable(false); - - device.setFullScreenWindow(window); - - if (device.isFullScreenSupported()) - device.setDisplayMode(displayMode); - - window.setLocation(0, 0); - window.setSize(displayMode.getWidth(), displayMode.getHeight()); - canvas.setSize(displayMode.getWidth(), displayMode.getHeight()); + window.setLocation(0, 0); + window.setSize(displayMode.getWidth(), displayMode.getHeight()); + canvas.setSize(displayMode.getWidth(), displayMode.getHeight()); - VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + getModeString(displayMode) + '\n'); + VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + getModeString(displayMode) + '\n'); } else { - window.setLocation(window_xpos, window_ypos); - window.pack(); - window.setResizable(false); - window.setVisible(true); + if (!Globals.appletMode) { + container.add(canvas, gbc); + final Frame f2 = window; + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + //f2.setLocation(window_xpos, window_ypos); + f2.pack(); + f2.setResizable(false); + f2.setVisible(true); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } else { + final Display fd = canvas; + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + container.add(fd, BorderLayout.CENTER); + // Notify the size listener about the change + SizeChangeListener listener = Globals.sizeChangeListener; + if (listener != null) { + listener.sizeChanged(newDim.width, newDim.height); + } + fd.setSize(newDim.width, newDim.height); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } } - while (!canvas.isDisplayable()) { + if (!Globals.appletMode) { + while (!canvas.isDisplayable() || !window.isDisplayable()) { try { - Thread.sleep(50); + Thread.sleep(100); } catch (InterruptedException e) {} - } + } + } canvas.requestFocus(); - this.canvas = canvas; - - Base.setVid(newDim.width, newDim.height); - - // let the sound and input subsystems know about the new window - VID.NewWindow(newDim.width, newDim.height); + this.display = canvas; + setGL(display.getGL()); + init(0, 0); + return Base.rserr_ok; } public void shutdown() { - if (oldDisplayMode != null && device.getFullScreenWindow() != null) { - try { - if (device.isFullScreenSupported()) - device.setDisplayMode(oldDisplayMode); - device.setFullScreenWindow(null); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (window != null) { - // this is very important to change the GL context - if (canvas != null) { - canvas.setVisible(false); - window.remove(canvas); - canvas = null; - } + if (!Globals.appletMode) { + try { + EventQueue.invokeAndWait(new Runnable() { + public void run() { + if (oldDisplayMode != null + && device.getFullScreenWindow() != null) { + try { + if (device.isFullScreenSupported()) { + if (!device.getDisplayMode().equals(oldDisplayMode)) + device.setDisplayMode(oldDisplayMode); + + } + device.setFullScreenWindow(null); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + + if (window != null) { + if (display != null) display.destroy(); window.dispose(); - } - post_init = false; - callback = INIT_CALLBACK; + while (window.isDisplayable()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + + } + } + } else { + if (display != null) { + display.destroy(); + // Remove the old display if there is one + container.remove(display); + } + } + display = null; } /** - * @return true - */ + * @return true + */ public boolean init(int xpos, int ypos) { - // do nothing - window_xpos = xpos; - window_ypos = ypos; - return true; + // set window position + window_xpos = xpos; + window_ypos = ypos; + // clear the screen + // first buffer + beginFrame(0.0f); + glViewport(0, 0, display.getWidth(), display.getHeight()); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + endFrame(); + // second buffer + beginFrame(0.0f); + glViewport(0, 0, display.getWidth(), display.getHeight()); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + endFrame(); + return true; } public void beginFrame(float camera_separation) { - // do nothing + display.activate(); } - - public void endFrame() { - glFlush(); - canvas.swapBuffers(); - } + public void endFrame() { + glFlush(); + display.update(); + } + public void appActivate(boolean activate) { // do nothing } @@ -313,53 +375,68 @@ public abstract class JoglDriver extends JoglGL implements GLDriver, GLEventList public void logNewFrame() { // do nothing } + + /* + * @see jake2.client.refexport_t#updateScreen() + */ - /* - * @see jake2.client.refexport_t#updateScreen() - */ - public void updateScreen() { - this.callback = INIT_CALLBACK; - canvas.display(); - } - - public void updateScreen(xcommand_t callback) { - this.callback = callback; - canvas.display(); - } - // ============================================================================ - // GLEventListener interface - // ============================================================================ - - /* - * @see net.java.games.jogl.GLEventListener#init(net.java.games.jogl.GLDrawable) - */ - public void init(GLDrawable drawable) { - setGL(drawable.getGL()); - } + public void updateScreen(xcommand_t callback) { + callback.execute(); + } - /* - * @see net.java.games.jogl.GLEventListener#display(net.java.games.jogl.GLDrawable) + protected void activate() { + display.activate(); + } + + // -------------------------------------------------------------------------- + + @SuppressWarnings("serial") + private static class Display extends GLCanvas { + + public Display(GLCapabilities capabilities) { + super(capabilities); + } + + public GL2 getGL() { + activate(); + return super.getGL().getGL2(); + } + + + /** + * @see java.awt.Component#setBounds(int, int, int, int) */ - public void display(GLDrawable drawable) { - setGL(drawable.getGL()); - - contextInUse = true; - callback.execute(); - contextInUse = false; - } - - /* - * @see net.java.games.jogl.GLEventListener#displayChanged(net.java.games.jogl.GLDrawable, boolean, boolean) - */ - public void displayChanged(GLDrawable drawable, boolean arg1, boolean arg2) { - // do nothing - } - - /* - * @see net.java.games.jogl.GLEventListener#reshape(net.java.games.jogl.GLDrawable, int, int, int, int) - */ - public void reshape(GLDrawable drawable, int x, int y, int width, int height) { - // do nothing + public void setBounds(int x, int y, int width, int height) { + final int mask = ~0x03; + if ((width & 0x03) != 0) { + width &= mask; + width += 4; + } + +// System.out.println("display bounds: " + x + ", " + y + ", " + width + ", " + height); + super.setBounds(x, y, width, height); + Base.setVid(width, height); + // let the sound and input subsystems know about the new window + VID.NewWindow(width, height); } + void activate() { + final GLContext ctx = this.getContext(); + if ( null != ctx && GLContext.getCurrent() != ctx ) { + ctx.makeCurrent(); + } + } + + private void release() { + final GLContext ctx = this.getContext(); + if ( null != ctx && GLContext.getCurrent() == ctx) { + ctx.release(); + } + } + + void update() { + release(); + swapBuffers(); + } + } } diff --git a/src/jake2/render/opengl/JoglGL.java b/src/jake2/render/opengl/JoglGL.java index 5296199..c009a40 100644 --- a/src/jake2/render/opengl/JoglGL.java +++ b/src/jake2/render/opengl/JoglGL.java @@ -3,315 +3,315 @@ package jake2.render.opengl; import java.nio.*; -import net.java.games.jogl.GL; +import javax.media.opengl.GL2; public class JoglGL implements QGL { - private GL jogl; + private GL2 gl; JoglGL() { // singleton } - void setGL(GL context) { - this.jogl = context; + void setGL(GL2 gl) { + this.gl = gl; } public void glAlphaFunc(int func, float ref) { - jogl.glAlphaFunc(func, ref); + gl.glAlphaFunc(func, ref); } public void glBegin(int mode) { - jogl.glBegin(mode); + gl.glBegin(mode); } public void glBindTexture(int target, int texture) { - jogl.glBindTexture(target, texture); + gl.glBindTexture(target, texture); } public void glBlendFunc(int sfactor, int dfactor) { - jogl.glBlendFunc(sfactor, dfactor); + gl.glBlendFunc(sfactor, dfactor); } public void glClear(int mask) { - jogl.glClear(mask); + gl.glClear(mask); } public void glClearColor(float red, float green, float blue, float alpha) { - jogl.glClearColor(red, green, blue, alpha); + gl.glClearColor(red, green, blue, alpha); } public void glColor3f(float red, float green, float blue) { - jogl.glColor3f(red, green, blue); + gl.glColor3f(red, green, blue); } public void glColor3ub(byte red, byte green, byte blue) { - jogl.glColor3ub(red, green, blue); + gl.glColor3ub(red, green, blue); } public void glColor4f(float red, float green, float blue, float alpha) { - jogl.glColor4f(red, green, blue, alpha); + gl.glColor4f(red, green, blue, alpha); } public void glColor4ub(byte red, byte green, byte blue, byte alpha) { - jogl.glColor4ub(red, green, blue, alpha); + gl.glColor4ub(red, green, blue, alpha); } public void glColorPointer(int size, boolean unsigned, int stride, ByteBuffer pointer) { - jogl.glColorPointer(size, GL_UNSIGNED_BYTE, stride, pointer); + gl.glColorPointer(size, GL_UNSIGNED_BYTE, stride, pointer); } public void glColorPointer(int size, int stride, FloatBuffer pointer) { - jogl.glColorPointer(size, GL_FLOAT, stride, pointer); + gl.glColorPointer(size, GL_FLOAT, stride, pointer); } public void glCullFace(int mode) { - jogl.glCullFace(mode); + gl.glCullFace(mode); } public void glDeleteTextures(IntBuffer textures) { - jogl.glDeleteTextures(textures.limit(), textures); + gl.glDeleteTextures(textures.limit(), textures); } public void glDepthFunc(int func) { - jogl.glDepthFunc(func); + gl.glDepthFunc(func); } public void glDepthMask(boolean flag) { - jogl.glDepthMask(flag); + gl.glDepthMask(flag); } public void glDepthRange(double zNear, double zFar) { - jogl.glDepthRange(zNear, zFar); + gl.glDepthRange(zNear, zFar); } public void glDisable(int cap) { - jogl.glDisable(cap); + gl.glDisable(cap); } public void glDisableClientState(int cap) { - jogl.glDisableClientState(cap); + gl.glDisableClientState(cap); } public void glDrawArrays(int mode, int first, int count) { - jogl.glDrawArrays(mode, first, count); + gl.glDrawArrays(mode, first, count); } public void glDrawBuffer(int mode) { - jogl.glDrawBuffer(mode); + gl.glDrawBuffer(mode); } public void glDrawElements(int mode, IntBuffer indices) { - jogl.glDrawElements(mode, indices.limit(), GL_UNSIGNED_INT, indices); + gl.glDrawElements(mode, indices.limit(), GL_UNSIGNED_INT, indices); } public void glEnable(int cap) { - jogl.glEnable(cap); + gl.glEnable(cap); } public void glEnableClientState(int cap) { - jogl.glEnableClientState(cap); + gl.glEnableClientState(cap); } public void glEnd() { - jogl.glEnd(); + gl.glEnd(); } public void glFinish() { - jogl.glFinish(); + gl.glFinish(); } public void glFlush() { - jogl.glFlush(); + gl.glFlush(); } public void glFrustum(double left, double right, double bottom, double top, double zNear, double zFar) { - jogl.glFrustum(left, right, bottom, top, zNear, zFar); + gl.glFrustum(left, right, bottom, top, zNear, zFar); } public int glGetError() { - return jogl.glGetError(); + return gl.glGetError(); } public void glGetFloat(int pname, FloatBuffer params) { - jogl.glGetFloatv(pname, params); + gl.glGetFloatv(pname, params); } public String glGetString(int name) { - return jogl.glGetString(name); + return gl.glGetString(name); } - + public void glHint(int target, int mode) { - jogl.glHint(target, mode); + gl.glHint(target, mode); } public void glInterleavedArrays(int format, int stride, FloatBuffer pointer) { - jogl.glInterleavedArrays(format, stride, pointer); + gl.glInterleavedArrays(format, stride, pointer); } public void glLoadIdentity() { - jogl.glLoadIdentity(); + gl.glLoadIdentity(); } public void glLoadMatrix(FloatBuffer m) { - jogl.glLoadMatrixf(m); + gl.glLoadMatrixf(m); } public void glMatrixMode(int mode) { - jogl.glMatrixMode(mode); + gl.glMatrixMode(mode); } public void glOrtho(double left, double right, double bottom, double top, double zNear, double zFar) { - jogl.glOrtho(left, right, bottom, top, zNear, zFar); + gl.glOrtho(left, right, bottom, top, zNear, zFar); } public void glPixelStorei(int pname, int param) { - jogl.glPixelStorei(pname, param); + gl.glPixelStorei(pname, param); } public void glPointSize(float size) { - jogl.glPointSize(size); + gl.glPointSize(size); } public void glPolygonMode(int face, int mode) { - jogl.glPolygonMode(face, mode); + gl.glPolygonMode(face, mode); } public void glPopMatrix() { - jogl.glPopMatrix(); + gl.glPopMatrix(); } public void glPushMatrix() { - jogl.glPushMatrix(); + gl.glPushMatrix(); } public void glReadPixels(int x, int y, int width, int height, int format, int type, ByteBuffer pixels) { - jogl.glReadPixels(x, y, width, height, format, type, pixels); + gl.glReadPixels(x, y, width, height, format, type, pixels); } public void glRotatef(float angle, float x, float y, float z) { - jogl.glRotatef(angle, x, y, z); + gl.glRotatef(angle, x, y, z); } public void glScalef(float x, float y, float z) { - jogl.glScalef(x, y, z); + gl.glScalef(x, y, z); } public void glScissor(int x, int y, int width, int height) { - jogl.glScissor(x, y, width, height); + gl.glScissor(x, y, width, height); } public void glShadeModel(int mode) { - jogl.glShadeModel(mode); + gl.glShadeModel(mode); } public void glTexCoord2f(float s, float t) { - jogl.glTexCoord2f(s, t); + gl.glTexCoord2f(s, t); } public void glTexCoordPointer(int size, int stride, FloatBuffer pointer) { - jogl.glTexCoordPointer(size, GL_FLOAT, stride, pointer); + gl.glTexCoordPointer(size, GL_FLOAT, stride, pointer); } public void glTexEnvi(int target, int pname, int param) { - jogl.glTexEnvi(target, pname, param); + gl.glTexEnvi(target, pname, param); } public void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, ByteBuffer pixels) { - jogl.glTexImage2D(target, level, internalformat, width, height, border, + gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); } public void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, IntBuffer pixels) { - jogl.glTexImage2D(target, level, internalformat, width, height, border, + gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); } public void glTexParameterf(int target, int pname, float param) { - jogl.glTexParameterf(target, pname, param); + gl.glTexParameterf(target, pname, param); } public void glTexParameteri(int target, int pname, int param) { - jogl.glTexParameteri(target, pname, param); + gl.glTexParameteri(target, pname, param); } public void glTexSubImage2D(int target, int level, int xoffset, int yoffset, int width, int height, int format, int type, IntBuffer pixels) { - jogl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, + gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); } public void glTranslatef(float x, float y, float z) { - jogl.glTranslatef(x, y, z); + gl.glTranslatef(x, y, z); } public void glVertex2f(float x, float y) { - jogl.glVertex2f(x, y); + gl.glVertex2f(x, y); } public void glVertex3f(float x, float y, float z) { - jogl.glVertex3f(x, y, z); + gl.glVertex3f(x, y, z); } public void glVertexPointer(int size, int stride, FloatBuffer pointer) { - jogl.glVertexPointer(size, GL_FLOAT, stride, pointer); + gl.glVertexPointer(size, GL_FLOAT, stride, pointer); } public void glViewport(int x, int y, int width, int height) { - jogl.glViewport(x, y, width, height); + gl.glViewport(x, y, width, height); } public void glColorTable(int target, int internalFormat, int width, int format, int type, ByteBuffer data) { - jogl.glColorTable(target, internalFormat, width, format, type, data); + gl.glColorTable(target, internalFormat, width, format, type, data); } public void glActiveTextureARB(int texture) { - jogl.glActiveTextureARB(texture); + gl.glActiveTexture(texture); } public void glClientActiveTextureARB(int texture) { - jogl.glClientActiveTextureARB(texture); + gl.glClientActiveTexture(texture); } public void glPointParameterEXT(int pname, FloatBuffer pfParams) { - jogl.glPointParameterfvEXT(pname, pfParams); + gl.glPointParameterfv(pname, pfParams); } public void glPointParameterfEXT(int pname, float param) { - jogl.glPointParameterfEXT(pname, param); + gl.glPointParameterf(pname, param); } public void glLockArraysEXT(int first, int count) { - jogl.glLockArraysEXT(first, count); + gl.glLockArraysEXT(first, count); } public void glArrayElement(int index) { - jogl.glArrayElement(index); + gl.glArrayElement(index); } public void glUnlockArraysEXT() { - jogl.glUnlockArraysEXT(); + gl.glUnlockArraysEXT(); } public void glMultiTexCoord2f(int target, float s, float t) { - jogl.glMultiTexCoord2f(target, s, t); + gl.glMultiTexCoord2f(target, s, t); } - + /* * util extensions */ public void setSwapInterval(int interval) { - jogl.setSwapInterval(interval); + gl.setSwapInterval(interval); } } diff --git a/src/jake2/render/opengl/Jsr231Driver.java b/src/jake2/render/opengl/Jsr231Driver.java deleted file mode 100644 index b6fa6eb..0000000 --- a/src/jake2/render/opengl/Jsr231Driver.java +++ /dev/null @@ -1,487 +0,0 @@ -/* - * Jsr231Driver.java - * Copyright (C) 2004 - * - */ -/* -Copyright (C) 1997-2001 Id Software, Inc. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program 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 GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -package jake2.render.opengl; - -import jake2.Defines; -import jake2.Globals; -import jake2.SizeChangeListener; -import jake2.client.VID; -import jake2.qcommon.Cbuf; -import jake2.qcommon.xcommand_t; -import jake2.render.Base; -import jake2.sys.JOGLKBD; - -import java.awt.*; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.LinkedList; - -import javax.media.opengl.*; -import javax.swing.ImageIcon; - -/** - * JoglCommon - */ -public abstract class Jsr231Driver extends Jsr231GL implements GLDriver { - - protected Jsr231Driver() { - // singleton - } - - private GraphicsDevice device; - private DisplayMode oldDisplayMode; - private volatile Display display; - private volatile Frame window; - - // This is either the above Window reference or the global - // applet if we're running in applet mode - private volatile Container container; - - // window position on the screen - int window_xpos, window_ypos; - - public DisplayMode[] getModeList() { - DisplayMode[] modes = device.getDisplayModes(); - LinkedList l = new LinkedList(); - l.add(oldDisplayMode); - - for (int i = 0; i < modes.length; i++) { - DisplayMode m = modes[i]; - - if (m.getBitDepth() != oldDisplayMode.getBitDepth()) continue; - if (m.getRefreshRate() > oldDisplayMode.getRefreshRate()) continue; - if (m.getHeight() < 240 || m.getWidth() < 320) continue; - - int j = 0; - DisplayMode ml = null; - for (j = 0; j < l.size(); j++) { - ml = (DisplayMode)l.get(j); - if (ml.getWidth() > m.getWidth()) break; - if (ml.getWidth() == m.getWidth() && ml.getHeight() >= m.getHeight()) break; - } - if (j == l.size()) { - l.addLast(m); - } else if (ml.getWidth() > m.getWidth() || ml.getHeight() > m.getHeight()) { - l.add(j, m); - } else if (m.getRefreshRate() > ml.getRefreshRate()){ - l.remove(j); - l.add(j, m); - } - } - DisplayMode[] ma = new DisplayMode[l.size()]; - l.toArray(ma); - return ma; - } - - DisplayMode findDisplayMode(Dimension dim) { - DisplayMode mode = null; - DisplayMode m = null; - DisplayMode[] modes = getModeList(); - int w = dim.width; - int h = dim.height; - - for (int i = 0; i < modes.length; i++) { - m = modes[i]; - if (m.getWidth() == w && m.getHeight() == h) { - mode = m; - break; - } - } - if (mode == null) mode = oldDisplayMode; - return mode; - } - - String getModeString(DisplayMode m) { - StringBuffer sb = new StringBuffer(); - sb.append(m.getWidth()); - sb.append('x'); - sb.append(m.getHeight()); - sb.append('x'); - sb.append(m.getBitDepth()); - sb.append('@'); - sb.append(m.getRefreshRate()); - sb.append("Hz"); - return sb.toString(); - } - - /** - * @param dim - * @param mode - * @param fullscreen - * @return enum Base.rserr_t - */ - public int setMode(Dimension dim, int mode, boolean fullscreen) { - - final Dimension newDim = new Dimension(); - - VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n"); - - VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); - - if (Globals.appletMode && container == null) { - container = (Container) Globals.applet; - } - - /* - * full screen handling - */ - if (device == null) { - GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); - device = env.getDefaultScreenDevice(); - } - - if (oldDisplayMode == null) { - oldDisplayMode = device.getDisplayMode(); - } - - if (!VID.GetModeInfo(newDim, mode)) { - VID.Printf(Defines.PRINT_ALL, " invalid mode\n"); - return Base.rserr_invalid_mode; - } - - VID.Printf(Defines.PRINT_ALL, " " + newDim.width + " " + newDim.height + '\n'); - - if (!Globals.appletMode) { - // destroy the existing window - if (window != null) shutdown(); - - window = new Frame("Jake2 (jsr231)"); - container = window; - ImageIcon icon = new ImageIcon(getClass().getResource("/icon-small.png")); - window.setIconImage(icon.getImage()); - window.setLayout(new GridBagLayout()); - // register event listener - window.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); - } - }); - } - - if (Globals.appletMode) { - // Destroy the previous display if there is one - shutdown(); - - // We don't support full-screen mode - fullscreen = false; - - // We need to feed the container to the JOGL - // keyboard class manually because we'll never get - // a component shown event for it - JOGLKBD.Init(container); - } - - Display canvas = new Display(new GLCapabilities()); - // we want keypressed events for TAB key - canvas.setFocusTraversalKeysEnabled(false); - canvas.setSize(newDim.width, newDim.height); - - // the OpenGL canvas grows and shrinks with the window - final GridBagConstraints gbc = new GridBagConstraints(); - gbc.fill = GridBagConstraints.BOTH; - gbc.weightx = gbc.weighty = 1; - - // D I F F E R E N T J A K E 2 E V E N T P R O C E S S I N G - container.addComponentListener(JOGLKBD.listener); - canvas.addKeyListener(JOGLKBD.listener); - canvas.addMouseListener(JOGLKBD.listener); - canvas.addMouseMotionListener(JOGLKBD.listener); - canvas.addMouseWheelListener(JOGLKBD.listener); - - if (fullscreen) { - - container.add(canvas, gbc); - - DisplayMode displayMode = findDisplayMode(newDim); - - newDim.width = displayMode.getWidth(); - newDim.height = displayMode.getHeight(); - window.setUndecorated(true); - window.setResizable(false); - - device.setFullScreenWindow(window); - - if (device.isFullScreenSupported()) - device.setDisplayMode(displayMode); - - window.setLocation(0, 0); - window.setSize(displayMode.getWidth(), displayMode.getHeight()); - canvas.setSize(displayMode.getWidth(), displayMode.getHeight()); - - VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " + getModeString(displayMode) + '\n'); - - } else { - if (!Globals.appletMode) { - container.add(canvas, gbc); - final Frame f2 = window; - try { - EventQueue.invokeAndWait(new Runnable() { - public void run() { - //f2.setLocation(window_xpos, window_ypos); - f2.pack(); - f2.setResizable(false); - f2.setVisible(true); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - } else { - final Display fd = canvas; - try { - EventQueue.invokeAndWait(new Runnable() { - public void run() { - container.add(fd, BorderLayout.CENTER); - // Notify the size listener about the change - SizeChangeListener listener = Globals.sizeChangeListener; - if (listener != null) { - listener.sizeChanged(newDim.width, newDim.height); - } - fd.setSize(newDim.width, newDim.height); - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - if (!Globals.appletMode) { - while (!canvas.isDisplayable() || !window.isDisplayable()) { - try { - Thread.sleep(100); - } catch (InterruptedException e) {} - } - } - canvas.requestFocus(); - - this.display = canvas; - - setGL(display.getGL()); - init(0, 0); - - return Base.rserr_ok; - } - - public void shutdown() { - if (!Globals.appletMode) { - try { - EventQueue.invokeAndWait(new Runnable() { - public void run() { - if (oldDisplayMode != null - && device.getFullScreenWindow() != null) { - try { - if (device.isFullScreenSupported()) { - if (!device.getDisplayMode().equals(oldDisplayMode)) - device.setDisplayMode(oldDisplayMode); - - } - device.setFullScreenWindow(null); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - - if (window != null) { - if (display != null) display.destroy(); - window.dispose(); - while (window.isDisplayable()) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - } - - } - } - } else { - if (display != null) { - display.destroy(); - // Remove the old display if there is one - container.remove(display); - } - } - display = null; - } - - /** - * @return true - */ - public boolean init(int xpos, int ypos) { - // set window position - window_xpos = xpos; - window_ypos = ypos; - // clear the screen - // first buffer - beginFrame(0.0f); - glViewport(0, 0, display.getWidth(), display.getHeight()); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - endFrame(); - // second buffer - beginFrame(0.0f); - glViewport(0, 0, display.getWidth(), display.getHeight()); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - endFrame(); - return true; - } - - public void beginFrame(float camera_separation) { - display.activate(); - } - - public void endFrame() { - glFlush(); - display.update(); - } - - public void appActivate(boolean activate) { - // do nothing - } - - public void enableLogging(boolean enable) { - // do nothing - } - - public void logNewFrame() { - // do nothing - } - - /* - * @see jake2.client.refexport_t#updateScreen() - */ - - public void updateScreen(xcommand_t callback) { - callback.execute(); - } - - protected void activate() { - display.activate(); - } - - // -------------------------------------------------------------------------- - - private static class Display extends Canvas { - private GLDrawable drawable; - - private GLContext context; - - public Display(GLCapabilities capabilities) { - super(unwrap((AWTGraphicsConfiguration)GLDrawableFactory.getFactory().chooseGraphicsConfiguration(capabilities, null, null))); - drawable = GLDrawableFactory.getFactory().getGLDrawable(this, capabilities, null); - context = drawable.createContext(null); - } - - GL getGL() { - activate(); - return context.getGL(); - } - - - /** - * @see java.awt.Component#setBounds(int, int, int, int) - */ - public void setBounds(int x, int y, int width, int height) { - final int mask = ~0x03; - if ((width & 0x03) != 0) { - width &= mask; - width += 4; - } - -// System.out.println("display bounds: " + x + ", " + y + ", " + width + ", " + height); - super.setBounds(x, y, width, height); - Base.setVid(width, height); - // let the sound and input subsystems know about the new window - VID.NewWindow(width, height); - } - - /** <B>Overrides:</B> - <DL><DD><CODE>paint</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ - // Overridden from Canvas to prevent the AWT's clearing of the - // canvas from interfering with the OpenGL rendering. - public void paint(Graphics g) { - // do nothing - } - - /** <B>Overrides:</B> - <DL><DD><CODE>update</CODE> in class <CODE>java.awt.Component</CODE></DD></DL> */ - // Overridden from Canvas to prevent the AWT's clearing of the - // canvas from interfering with the OpenGL rendering. - public void update(Graphics g) { - // do nothing - //paint(g); - } - - public void addNotify() { - super.addNotify(); - super.setBackground(Color.BLACK); - drawable.setRealized(true); - } - - public void removeNotify() { - if (drawable != null) { - drawable.setRealized(false); - drawable = null; - } - super.removeNotify(); - } - - void activate() { - if (GLContext.getCurrent() != context) - context.makeCurrent(); - } - - private void release() { - if (GLContext.getCurrent() == context) - context.release(); - } - - void update() { - release(); - drawable.swapBuffers(); - } - - void destroy() { - if (context != null) { - release(); - context.destroy(); - context = null; - } - } - - private static GraphicsConfiguration unwrap(AWTGraphicsConfiguration config) { - if (config == null) { - return null; - } - return config.getGraphicsConfiguration(); - } - } -} diff --git a/src/jake2/render/opengl/Jsr231GL.java b/src/jake2/render/opengl/Jsr231GL.java deleted file mode 100644 index 0087def..0000000 --- a/src/jake2/render/opengl/Jsr231GL.java +++ /dev/null @@ -1,317 +0,0 @@ -package jake2.render.opengl; - - -import java.nio.*; - -import javax.media.opengl.GL; - -public class Jsr231GL implements QGL { - - private GL gl; - - Jsr231GL() { - // singleton - } - - void setGL(GL gl) { - this.gl = gl; - } - - public void glAlphaFunc(int func, float ref) { - gl.glAlphaFunc(func, ref); - } - - public void glBegin(int mode) { - gl.glBegin(mode); - } - - public void glBindTexture(int target, int texture) { - gl.glBindTexture(target, texture); - } - - public void glBlendFunc(int sfactor, int dfactor) { - gl.glBlendFunc(sfactor, dfactor); - } - - public void glClear(int mask) { - gl.glClear(mask); - } - - public void glClearColor(float red, float green, float blue, float alpha) { - gl.glClearColor(red, green, blue, alpha); - } - - public void glColor3f(float red, float green, float blue) { - gl.glColor3f(red, green, blue); - } - - public void glColor3ub(byte red, byte green, byte blue) { - gl.glColor3ub(red, green, blue); - } - - public void glColor4f(float red, float green, float blue, float alpha) { - gl.glColor4f(red, green, blue, alpha); - } - - public void glColor4ub(byte red, byte green, byte blue, byte alpha) { - gl.glColor4ub(red, green, blue, alpha); - } - - public void glColorPointer(int size, boolean unsigned, int stride, - ByteBuffer pointer) { - gl.glColorPointer(size, GL_UNSIGNED_BYTE, stride, pointer); - } - - public void glColorPointer(int size, int stride, FloatBuffer pointer) { - gl.glColorPointer(size, GL_FLOAT, stride, pointer); - } - - public void glCullFace(int mode) { - gl.glCullFace(mode); - } - - public void glDeleteTextures(IntBuffer textures) { - gl.glDeleteTextures(textures.limit(), textures); - } - - public void glDepthFunc(int func) { - gl.glDepthFunc(func); - } - - public void glDepthMask(boolean flag) { - gl.glDepthMask(flag); - } - - public void glDepthRange(double zNear, double zFar) { - gl.glDepthRange(zNear, zFar); - } - - public void glDisable(int cap) { - gl.glDisable(cap); - } - - public void glDisableClientState(int cap) { - gl.glDisableClientState(cap); - } - - public void glDrawArrays(int mode, int first, int count) { - gl.glDrawArrays(mode, first, count); - } - - public void glDrawBuffer(int mode) { - gl.glDrawBuffer(mode); - } - - public void glDrawElements(int mode, IntBuffer indices) { - gl.glDrawElements(mode, indices.limit(), GL_UNSIGNED_INT, indices); - } - - public void glEnable(int cap) { - gl.glEnable(cap); - } - - public void glEnableClientState(int cap) { - gl.glEnableClientState(cap); - } - - public void glEnd() { - gl.glEnd(); - } - - public void glFinish() { - gl.glFinish(); - } - - public void glFlush() { - gl.glFlush(); - } - - public void glFrustum(double left, double right, double bottom, - double top, double zNear, double zFar) { - gl.glFrustum(left, right, bottom, top, zNear, zFar); - } - - public int glGetError() { - return gl.glGetError(); - } - - public void glGetFloat(int pname, FloatBuffer params) { - gl.glGetFloatv(pname, params); - } - - public String glGetString(int name) { - return gl.glGetString(name); - } - - public void glHint(int target, int mode) { - gl.glHint(target, mode); - } - - public void glInterleavedArrays(int format, int stride, - FloatBuffer pointer) { - gl.glInterleavedArrays(format, stride, pointer); - } - - public void glLoadIdentity() { - gl.glLoadIdentity(); - } - - public void glLoadMatrix(FloatBuffer m) { - gl.glLoadMatrixf(m); - } - - public void glMatrixMode(int mode) { - gl.glMatrixMode(mode); - } - - public void glOrtho(double left, double right, double bottom, - double top, double zNear, double zFar) { - gl.glOrtho(left, right, bottom, top, zNear, zFar); - } - - public void glPixelStorei(int pname, int param) { - gl.glPixelStorei(pname, param); - } - - public void glPointSize(float size) { - gl.glPointSize(size); - } - - public void glPolygonMode(int face, int mode) { - gl.glPolygonMode(face, mode); - } - - public void glPopMatrix() { - gl.glPopMatrix(); - } - - public void glPushMatrix() { - gl.glPushMatrix(); - } - - public void glReadPixels(int x, int y, int width, int height, - int format, int type, ByteBuffer pixels) { - gl.glReadPixels(x, y, width, height, format, type, pixels); - } - - public void glRotatef(float angle, float x, float y, float z) { - gl.glRotatef(angle, x, y, z); - } - - public void glScalef(float x, float y, float z) { - gl.glScalef(x, y, z); - } - - public void glScissor(int x, int y, int width, int height) { - gl.glScissor(x, y, width, height); - } - - public void glShadeModel(int mode) { - gl.glShadeModel(mode); - } - - public void glTexCoord2f(float s, float t) { - gl.glTexCoord2f(s, t); - } - - public void glTexCoordPointer(int size, int stride, FloatBuffer pointer) { - gl.glTexCoordPointer(size, GL_FLOAT, stride, pointer); - } - - public void glTexEnvi(int target, int pname, int param) { - gl.glTexEnvi(target, pname, param); - } - - public void glTexImage2D(int target, int level, int internalformat, - int width, int height, int border, int format, int type, - ByteBuffer pixels) { - gl.glTexImage2D(target, level, internalformat, width, height, border, - format, type, pixels); - } - - public void glTexImage2D(int target, int level, int internalformat, - int width, int height, int border, int format, int type, - IntBuffer pixels) { - gl.glTexImage2D(target, level, internalformat, width, height, border, - format, type, pixels); - } - - public void glTexParameterf(int target, int pname, float param) { - gl.glTexParameterf(target, pname, param); - } - - public void glTexParameteri(int target, int pname, int param) { - gl.glTexParameteri(target, pname, param); - } - - public void glTexSubImage2D(int target, int level, int xoffset, - int yoffset, int width, int height, int format, int type, - IntBuffer pixels) { - gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, - format, type, pixels); - } - - public void glTranslatef(float x, float y, float z) { - gl.glTranslatef(x, y, z); - } - - public void glVertex2f(float x, float y) { - gl.glVertex2f(x, y); - } - - public void glVertex3f(float x, float y, float z) { - gl.glVertex3f(x, y, z); - } - - public void glVertexPointer(int size, int stride, FloatBuffer pointer) { - gl.glVertexPointer(size, GL_FLOAT, stride, pointer); - } - - public void glViewport(int x, int y, int width, int height) { - gl.glViewport(x, y, width, height); - } - - public void glColorTable(int target, int internalFormat, int width, - int format, int type, ByteBuffer data) { - gl.glColorTable(target, internalFormat, width, format, type, data); - } - - public void glActiveTextureARB(int texture) { - gl.glActiveTexture(texture); - } - - public void glClientActiveTextureARB(int texture) { - gl.glClientActiveTexture(texture); - } - - public void glPointParameterEXT(int pname, FloatBuffer pfParams) { - gl.glPointParameterfvEXT(pname, pfParams); - } - - public void glPointParameterfEXT(int pname, float param) { - gl.glPointParameterfEXT(pname, param); - } - public void glLockArraysEXT(int first, int count) { - gl.glLockArraysEXT(first, count); - } - - public void glArrayElement(int index) { - gl.glArrayElement(index); - } - - public void glUnlockArraysEXT() { - gl.glUnlockArraysEXT(); - } - - public void glMultiTexCoord2f(int target, float s, float t) { - gl.glMultiTexCoord2f(target, s, t); - } - - /* - * util extensions - */ - public void setSwapInterval(int interval) { - gl.setSwapInterval(interval); - } - -} diff --git a/src/jake2/sound/S.java b/src/jake2/sound/S.java index 4b530c3..90b178c 100644 --- a/src/jake2/sound/S.java +++ b/src/jake2/sound/S.java @@ -67,7 +67,7 @@ public class S { // prefered driver try { - Class.forName("net.java.games.joal.AL"); + Class.forName("com.jogamp.openal.AL"); Class.forName("jake2.sound.joal.JOALSoundImpl"); } catch (Throwable e) { // ignore the joal driver if runtime not in classpath diff --git a/src/jake2/sound/joal/Channel.java b/src/jake2/sound/joal/Channel.java index 4b694ea..86a5990 100644 --- a/src/jake2/sound/joal/Channel.java +++ b/src/jake2/sound/joal/Channel.java @@ -29,14 +29,18 @@ import jake2.Globals; import jake2.client.CL_ents; import jake2.game.entity_state_t; import jake2.qcommon.Com; -import jake2.sound.*; +import jake2.sound.Sound; +import jake2.sound.sfx_t; +import jake2.sound.sfxcache_t; import jake2.util.Math3D; import java.nio.ByteBuffer; -import java.util.*; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; -import net.java.games.joal.AL; -import net.java.games.joal.ALException; +import com.jogamp.openal.AL; +import com.jogamp.openal.ALException; /** * Channel diff --git a/src/jake2/sound/joal/JOALSoundImpl.java b/src/jake2/sound/joal/JOALSoundImpl.java index d515633..e70b348 100644 --- a/src/jake2/sound/joal/JOALSoundImpl.java +++ b/src/jake2/sound/joal/JOALSoundImpl.java @@ -15,10 +15,10 @@ import jake2.util.Vargs; import java.nio.*; -import net.java.games.joal.*; -import net.java.games.joal.eax.EAX; -import net.java.games.joal.eax.EAXFactory; -import net.java.games.joal.util.ALut; +import com.jogamp.openal.*; +import com.jogamp.openal.eax.EAX; +import com.jogamp.openal.eax.EAXFactory; +import com.jogamp.openal.util.ALut; /** * JOALSoundImpl diff --git a/test/jake2/render/TestMap.java b/test/jake2/render/TestMap.java index f9a78ce..f127a19 100644 --- a/test/jake2/render/TestMap.java +++ b/test/jake2/render/TestMap.java @@ -84,7 +84,7 @@ public class TestMap // sehr wichtig !!! VID.Shutdown(); - Globals.re = this.re = Renderer.getDriver("jsr231", true); + Globals.re = this.re = Renderer.getDriver("jogl2", true); re.Init(0, 0); diff --git a/test/jake2/render/TestRenderer.java b/test/jake2/render/TestRenderer.java index 46426eb..a1a9515 100644 --- a/test/jake2/render/TestRenderer.java +++ b/test/jake2/render/TestRenderer.java @@ -75,7 +75,7 @@ public class TestRenderer { Locale.setDefault(Locale.US); Jake2.Q2Dialog.setVisible(true); - String DRIVER = "jsr231"; + String DRIVER = "jogl2"; Qcommon.Init(new String[] { "TestRenderer", "+set", "gl_mode", "6", "+set", "vid_fullscreen", "0", "+set", "vid_ref", DRIVER }); @@ -723,4 +723,4 @@ public class TestRenderer { vertexBuf.put(i + 1, org[1]); vertexBuf.put(i + 2, org[2]); } -}
\ No newline at end of file +} diff --git a/webstart/jake2_jsr231.jnlp b/webstart/jake2_jogl.jnlp index 1194a19..0af55d2 100644 --- a/webstart/jake2_jsr231.jnlp +++ b/webstart/jake2_jogl.jnlp @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <jnlp spec="1.0+" codebase="http://jake2.in-chemnitz.de/downloads" - href="jake2_jsr231.jnlp"> + href="jake2_jogl2.jnlp"> <information> <title>Jake2</title> @@ -27,7 +27,7 @@ <application-desc main-class="jake2.Jake2"> <argument>+set</argument> <argument>vid_ref</argument> - <argument>jsr231</argument> + <argument>jogl2</argument> <argument>+set</argument> <argument>s_impl</argument> <argument>joal</argument> diff --git a/webstart/jake2_online.jnlp b/webstart/jake2_online.jnlp index 0951c4c..645839c 100644 --- a/webstart/jake2_online.jnlp +++ b/webstart/jake2_online.jnlp @@ -27,7 +27,7 @@ <application-desc main-class="jake2.Jake2"> <argument>+set</argument> <argument>vid_ref</argument> - <argument>jsr231</argument> + <argument>jogl2</argument> <argument>+set</argument> <argument>s_impl</argument> <argument>joal</argument> |