diff options
author | Holger Zickner <[email protected]> | 2004-07-09 06:50:52 +0000 |
---|---|---|
committer | Holger Zickner <[email protected]> | 2004-07-09 06:50:52 +0000 |
commit | 20a66a892a3f0704ef37f1eebb681edfee6fc165 (patch) | |
tree | 118e0e5ea00eecf450e4c63edc88c421d52a7db2 /src/jake2/render/jogl | |
parent | 6b36f9e0380b7c80aecdc78ef07a0cf473712416 (diff) |
import of Jake2
Diffstat (limited to 'src/jake2/render/jogl')
-rw-r--r-- | src/jake2/render/jogl/Draw.java | 10 | ||||
-rw-r--r-- | src/jake2/render/jogl/Image.java | 56 | ||||
-rw-r--r-- | src/jake2/render/jogl/Impl.java | 183 | ||||
-rw-r--r-- | src/jake2/render/jogl/Light.java | 75 | ||||
-rw-r--r-- | src/jake2/render/jogl/Main.java | 210 | ||||
-rw-r--r-- | src/jake2/render/jogl/Mesh.java | 53 | ||||
-rw-r--r-- | src/jake2/render/jogl/Misc.java | 14 | ||||
-rw-r--r-- | src/jake2/render/jogl/Model.java | 21 | ||||
-rw-r--r-- | src/jake2/render/jogl/Surf.java | 126 | ||||
-rw-r--r-- | src/jake2/render/jogl/Warp.java | 6 |
10 files changed, 398 insertions, 356 deletions
diff --git a/src/jake2/render/jogl/Draw.java b/src/jake2/render/jogl/Draw.java index eac0a1e..3251b0e 100644 --- a/src/jake2/render/jogl/Draw.java +++ b/src/jake2/render/jogl/Draw.java @@ -2,7 +2,7 @@ * Draw.java * Copyright (C) 2003 * - * $Id: Draw.java,v 1.2 2004-07-08 15:58:45 hzi Exp $ + * $Id: Draw.java,v 1.3 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -257,10 +257,10 @@ public abstract class Draw extends Image { int color = d_8to24table[colorIndex]; - gl.glColor3f( - ((color >> 0) & 0xff)/255.0f, // r - ((color >> 8) & 0xff)/255.0f, // g - ((color >> 16) & 0xff)/255.0f // b + gl.glColor3ub( + (byte)((color >> 0) & 0xff), // r + (byte)((color >> 8) & 0xff), // g + (byte)((color >> 16) & 0xff) // b ); gl.glBegin (GL.GL_QUADS); diff --git a/src/jake2/render/jogl/Image.java b/src/jake2/render/jogl/Image.java index 4e65481..f0034fe 100644 --- a/src/jake2/render/jogl/Image.java +++ b/src/jake2/render/jogl/Image.java @@ -2,7 +2,7 @@ * Image.java * Copyright (C) 2003 * - * $Id: Image.java,v 1.2 2004-07-08 20:24:30 hzi Exp $ + * $Id: Image.java,v 1.3 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -26,27 +26,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package jake2.render.jogl; import jake2.Defines; +import jake2.client.particle_t; import jake2.game.cvar_t; import jake2.qcommon.longjmpException; import jake2.qcommon.qfiles; import jake2.render.image_t; +import jake2.util.Lib; import jake2.util.Vargs; import java.awt.Dimension; import java.awt.geom.AffineTransform; import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; -import java.awt.image.BufferedImageOp; -import java.awt.image.Raster; -import java.awt.image.SampleModel; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.IntBuffer; +import java.nio.*; import java.util.Arrays; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeMap; import net.java.games.jogl.GL; @@ -128,8 +121,7 @@ public abstract class Image extends Main { GL_TexEnv(GL.GL_REPLACE); } - void GL_SelectTexture(int texture /* GLenum */ - ) { + void GL_SelectTexture(int texture /* GLenum */) { int tmu; if (!qglSelectTextureSGIS && !qglActiveTextureARB) @@ -787,9 +779,9 @@ public abstract class Image extends Main { filledcolor = 0; // attempt to find opaque black for (i = 0; i < 256; ++i) - if (d_8to24table[i] == (255 << 0)) // alpha 1.0 - // TODO check this: if ((d_8to24table[i] & 0xFF000000) == 0xFF000000) // alpha 1.0 - { + // TODO check this + if (d_8to24table[i] == 0xFF000000) { // alpha 1.0 + //if (d_8to24table[i] == (255 << 0)) // alpha 1.0 filledcolor = i; break; } @@ -1068,6 +1060,7 @@ public abstract class Image extends Main { */ int[] scaled = new int[256 * 256]; byte[] paletted_texture = new byte[256 * 256]; + IntBuffer tex = Lib.newIntBuffer(512 * 256, ByteOrder.LITTLE_ENDIAN); boolean GL_Upload32(int[] data, int width, int height, boolean mipmap) { int samples; @@ -1149,6 +1142,7 @@ public abstract class Image extends Main { paletted_texture); } else { + tex.rewind(); tex.put(data); gl.glTexImage2D( GL.GL_TEXTURE_2D, 0, @@ -1158,13 +1152,13 @@ public abstract class Image extends Main { 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, - data); + tex); } //goto done; throw new longjmpException(); } //memcpy (scaled, data, width*height*4); were bytes - IntBuffer.wrap(data).get(scaled, 0, width * height); + System.arraycopy(data, 0, scaled, 0, width * height); } else @@ -1187,7 +1181,8 @@ public abstract class Image extends Main { paletted_texture); } else { - gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, scaled); + tex.rewind(); tex.put(scaled); + gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, tex); } if (mipmap) { @@ -1218,6 +1213,7 @@ public abstract class Image extends Main { paletted_texture); } else { + tex.rewind(); tex.put(scaled); gl.glTexImage2D( GL.GL_TEXTURE_2D, miplevel, @@ -1227,14 +1223,14 @@ public abstract class Image extends Main { 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, - scaled); + tex); } } } // label done: } catch (longjmpException e) { - ; // replaces labe done + ; // replaces label done } if (mipmap) { @@ -1578,7 +1574,7 @@ public abstract class Image extends Main { // free it // TODO jogl bug - //gl.glDeleteTextures(1, new int[] {image.texnum}); + gl.glDeleteTextures(1, new int[] {image.texnum}); image.clear(); } } @@ -1590,7 +1586,6 @@ public abstract class Image extends Main { */ protected void Draw_GetPalette() { int r, g, b; - int v; Dimension dim; byte[] pic; byte[][] palette = new byte[1][]; //new byte[768]; @@ -1604,15 +1599,18 @@ public abstract class Image extends Main { byte[] pal = palette[0]; + int j = 0; for (int i = 0; i < 256; i++) { - r = pal[i * 3 + 0]; - g = pal[i * 3 + 1]; - b = pal[i * 3 + 2]; + r = pal[j++] & 0xFF; + g = pal[j++] & 0xFF; + b = pal[j++] & 0xFF; - d_8to24table[i] = (255 << 24) + (r << 0) + (g << 8) + (b << 16); + d_8to24table[i] = (255 << 24) | (b << 16) | (g << 8) | (r << 0); } - d_8to24table[255] &= 0x00ffffff; // 255 is transparent + d_8to24table[255] &= 0x00FFFFFF; // 255 is transparent + + particle_t.setColorPalette(d_8to24table); } /* @@ -1686,7 +1684,7 @@ public abstract class Image extends Main { continue; // free image_t slot // free it // TODO jogl bug - //gl.glDeleteTextures(1, new int[] {image.texnum}); + gl.glDeleteTextures(1, new int[] {image.texnum}); image.clear(); } } diff --git a/src/jake2/render/jogl/Impl.java b/src/jake2/render/jogl/Impl.java index 991c349..cfaec7e 100644 --- a/src/jake2/render/jogl/Impl.java +++ b/src/jake2/render/jogl/Impl.java @@ -2,7 +2,7 @@ * Impl.java * Copyright (C) 2003 * - * $Id: Impl.java,v 1.4 2004-07-08 20:56:55 hzi Exp $ + * $Id: Impl.java,v 1.5 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -27,13 +27,11 @@ package jake2.render.jogl; import jake2.Defines; import jake2.Globals; -import jake2.client.CL; import jake2.qcommon.Com; import jake2.qcommon.xcommand_t; -import jake2.server.SV; import jake2.sys.KBD; -import java.awt.Dimension; +import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -48,17 +46,34 @@ import net.java.games.jogl.*; */ public class Impl extends Misc implements GLEventListener { - - public static final String DRIVER_NAME = "jogl"; // handles the post initialization with JoglRenderer protected boolean post_init = false; - // switch to updateScreen callback - private boolean switchToCallback = false; - private xcommand_t callback = null; + private final xcommand_t INIT_CALLBACK = new xcommand_t() { + public void execute() { + // only used for the first run (initialization) + // clear the screen + gl.glClearColor(0, 0, 0, 0); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + + // + // check the post init process + // + if (!post_init) { + ri.Con_Printf(Defines.PRINT_ALL, "Missing multi-texturing for FastJOGL renderer\n"); + } + + GLimp_EndFrame(); + } + }; + + private xcommand_t callback = INIT_CALLBACK; protected boolean contextInUse = false; + + private GraphicsDevice device; + private DisplayMode oldDisplayMode; GLCanvas canvas; JFrame window; @@ -88,13 +103,9 @@ public class Impl extends Misc implements GLEventListener { ri.Cvar_Get("r_fakeFullscreen", "0", Globals.CVAR_ARCHIVE); - ri.Con_Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n", null); + ri.Con_Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n"); - if (fullscreen) { - ri.Con_Printf(Defines.PRINT_ALL, "...setting fullscreen mode " + mode + ":"); - } - else - ri.Con_Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); + ri.Con_Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); if (!ri.Vid_GetModeInfo(newDim, mode)) { ri.Con_Printf(Defines.PRINT_ALL, " invalid mode\n"); @@ -113,18 +124,12 @@ public class Impl extends Misc implements GLEventListener { // TODO Use debug pipeline //canvas.setGL(new DebugGL(canvas.getGL())); - //canvas.setRenderingThread(Thread.currentThread()); - canvas.setNoAutoRedrawMode(true); canvas.addGLEventListener(this); - window.getContentPane().add(canvas); - + window.getContentPane().add(canvas); canvas.setSize(newDim.width, newDim.height); - window.setLocation(window_xpos, window_ypos); - //window.setUndecorated(true); - window.setResizable(false); // register event listener window.addWindowListener(new WindowAdapter() { @@ -134,14 +139,57 @@ public class Impl extends Misc implements GLEventListener { }); // 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(KBD.listener); canvas.addKeyListener(KBD.listener); canvas.addMouseListener(KBD.listener); canvas.addMouseMotionListener(KBD.listener); - window.addComponentListener(KBD.listener); - canvas.requestFocus(); - window.pack(); - window.show(); + /* + * fullscreen handling + */ + GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); + device = env.getDefaultScreenDevice(); + + if (fullscreen && !device.isFullScreenSupported()) { + ri.Con_Printf(Defines.PRINT_ALL, "...fullscreen not supported\n"); + vid_fullscreen.value = 0; + vid_fullscreen.modified = false; + } + + fullscreen = fullscreen && device.isFullScreenSupported(); + + if (oldDisplayMode == null) { + oldDisplayMode = device.getDisplayMode(); + } + + if (fullscreen) { + + DisplayMode displayMode = findDisplayMode(newDim, oldDisplayMode.getBitDepth(), oldDisplayMode.getRefreshRate()); + + if (displayMode != null) { + newDim.width = displayMode.getWidth(); + newDim.height = displayMode.getHeight(); + window.setUndecorated(true); + window.setResizable(false); + device.setFullScreenWindow(window); + device.setDisplayMode(displayMode); + window.setLocation(0, 0); + window.setSize(displayMode.getWidth(), displayMode.getHeight()); + canvas.setSize(displayMode.getWidth(), displayMode.getHeight()); + ri.Con_Printf(Defines.PRINT_ALL, "...setting fullscreen " + getModeString(displayMode) + '\n'); + } + } else { + window.setLocation(window_xpos, window_ypos); + window.pack(); + window.setResizable(false); + window.setVisible(true); + } + + while (!canvas.isDisplayable()) { + try { + Thread.sleep(50); + } catch (InterruptedException e) {} + } canvas.requestFocus(); this.canvas = canvas; @@ -154,6 +202,38 @@ public class Impl extends Misc implements GLEventListener { return rserr_ok; } + + DisplayMode findDisplayMode(Dimension dim, int depth, int rate) { + DisplayMode mode = null; + DisplayMode m = null; + DisplayMode[] modes = device.getDisplayModes(); + 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 && m.getBitDepth() == depth && m.getRefreshRate() == rate) { + mode = m; + break; + } + } + if (mode == null) mode = oldDisplayMode; + Com.Printf(getModeString(mode) + '\n'); + 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(); + } void GLimp_BeginFrame(float camera_separation) { // do nothing @@ -180,11 +260,19 @@ public class Impl extends Misc implements GLEventListener { } void GLimp_Shutdown() { + if (oldDisplayMode != null && device.getFullScreenWindow() != null) { + try { + device.setDisplayMode(oldDisplayMode); + device.setFullScreenWindow(null); + } catch (Exception e) { + e.printStackTrace(); + } + } if (this.window != null) { window.dispose(); } post_init = false; - switchToCallback = false; + callback = INIT_CALLBACK; } void GLimp_EnableLogging(boolean enable) { @@ -221,31 +309,8 @@ public class Impl extends Misc implements GLEventListener { this.gl = drawable.getGL(); this.glu = drawable.getGLU(); - this.contextInUse = true; - - if (switchToCallback) { - callback.execute(); - } - else - { - - // after the first run (initialization) switch to callback - switchToCallback = true; - - // clear the screen - gl.glClearColor(0, 0, 0, 0); - gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - - // - // check the post init process - // - if (!post_init) { - ri.Sys_Error(Defines.ERR_FATAL, "Error: can't init JOGL renderer"); - } - - GLimp_EndFrame(); - } - + contextInUse = true; + callback.execute(); contextInUse = false; } @@ -260,20 +325,18 @@ public class Impl extends Misc implements GLEventListener { * @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) { - - vid.height = height; - vid.width = width; - - ri.Vid_NewWindow(width, height); + // do nothing } /* * @see jake2.client.refexport_t#updateScreen() */ + public void updateScreen() { + this.callback = INIT_CALLBACK; + canvas.display(); + } + public void updateScreen(xcommand_t callback) { -// if (canvas == null) { -// throw new IllegalStateException("Refresh modul \"" + DRIVER_NAME + "\" have to be initialized."); -// } this.callback = callback; canvas.display(); } diff --git a/src/jake2/render/jogl/Light.java b/src/jake2/render/jogl/Light.java index 686884a..851f4e6 100644 --- a/src/jake2/render/jogl/Light.java +++ b/src/jake2/render/jogl/Light.java @@ -2,7 +2,7 @@ * Light.java * Copyright (C) 2003 * - * $Id: Light.java,v 1.3 2004-07-08 20:56:55 hzi Exp $ + * $Id: Light.java,v 1.4 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -25,12 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.jogl; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.util.Arrays; - -import net.java.games.jogl.GL; - import jake2.Defines; import jake2.Globals; import jake2.client.dlight_t; @@ -38,12 +32,15 @@ import jake2.client.lightstyle_t; import jake2.game.GameBase; import jake2.game.cplane_t; import jake2.qcommon.longjmpException; -import jake2.render.mnode_t; -import jake2.render.msurface_t; -import jake2.render.mtexinfo_t; -import jake2.util.Lib; +import jake2.render.*; import jake2.util.Math3D; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.util.Arrays; + +import net.java.games.jogl.GL; + /** * Light * @@ -79,7 +76,7 @@ public abstract class Light extends Warp { gl.glColor3f (light.color[0]*0.2f, light.color[1]*0.2f, light.color[2]*0.2f); for (i=0 ; i<3 ; i++) v[i] = light.origin[i] - vpn[i]*rad; - gl.glVertex3fv (v); + gl.glVertex3f(v[0], v[1], v[2]); gl.glColor3f (0,0,0); for (i=16 ; i>=0 ; i--) { @@ -87,7 +84,7 @@ public abstract class Light extends Warp { for (j=0 ; j<3 ; j++) v[j] = (float)(light.origin[j] + vright[j]*Math.cos(a)*rad + vup[j]*Math.sin(a)*rad); - gl.glVertex3fv (v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -306,16 +303,13 @@ public abstract class Light extends Warp { ds >>= 4; dt >>= 4; - //surf.samples.reset(); - lightmap = surf.samples.slice(); - + lightmap = surf.samples; int lightmapIndex = 0; + Math3D.VectorCopy (Globals.vec3_origin, pointcolor); if (lightmap != null) { float[] scale = {0, 0, 0}; - -// lightmap += 3*(dt * ((surf.extents[0]>>4)+1) + ds); lightmapIndex += 3 * (dt * ((surf.extents[0] >> 4) + 1) + ds); for (maps = 0 ; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte)255; maps++) @@ -326,15 +320,11 @@ public abstract class Light extends Warp { pointcolor[0] += (lightmap.get(lightmapIndex + 0) & 0xFF) * scale[0] * (1.0f/255); pointcolor[1] += (lightmap.get(lightmapIndex + 1) & 0xFF) * scale[1] * (1.0f/255); pointcolor[2] += (lightmap.get(lightmapIndex + 2) & 0xFF) * scale[2] * (1.0f/255); -// lightmap += 3*((surf.extents[0]>>4)+1) * -// ((surf.extents[1]>>4)+1); lightmapIndex += 3 * ((surf.extents[0] >> 4) + 1) * ((surf.extents[1] >> 4) + 1); } } - return 1; } - // go down back side return RecursiveLightPoint (node.children[1 - sideIndex], mid, end); } @@ -506,7 +496,7 @@ public abstract class Light extends Warp { Combine and scale multiple lightmaps into the floating format in blocklights =============== */ - void R_BuildLightMap(msurface_t surf, ByteBuffer dest, int stride) + void R_BuildLightMap(msurface_t surf, IntBuffer dest, int stride) { int smax, tmax; int r, g, b, a, max; @@ -549,8 +539,8 @@ public abstract class Light extends Warp { nummaps++) ; - //surf.samples.reset(); - lightmap = surf.samples.slice(); + lightmap = surf.samples; + int lightmapIndex = 0; // add all the lightmaps if ( nummaps == 1 ) @@ -572,18 +562,18 @@ public abstract class Light extends Warp { { for (i=0 ; i<size ; i++) { - bl[blp++] = lightmap.get() & 0xFF; - bl[blp++] = lightmap.get() & 0xFF; - bl[blp++] = lightmap.get() & 0xFF; + bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; + bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; + bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; } } else { for (i=0 ; i<size ; i++) { - bl[blp++] = (lightmap.get() & 0xFF) * scale[0]; - bl[blp++] = (lightmap.get() & 0xFF) * scale[1]; - bl[blp++] = (lightmap.get() & 0xFF) * scale[2]; + bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[0]; + bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[1]; + bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale[2]; } } //lightmap += size*3; // skip to next lightmap @@ -612,18 +602,18 @@ public abstract class Light extends Warp { { for (i=0 ; i<size ; i++) { - bl[blp++] += lightmap.get() & 0xFF; - bl[blp++] += lightmap.get() & 0xFF; - bl[blp++] += lightmap.get() & 0xFF; + bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; + bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; + bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; } } else { for (i=0 ; i<size ; i++) { - bl[blp++] += (lightmap.get() & 0xFF) * scale[0]; - bl[blp++] += (lightmap.get() & 0xFF) * scale[1]; - bl[blp++] += (lightmap.get() & 0xFF) * scale[2]; + bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[0]; + bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[1]; + bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale[2]; } } //lightmap += size*3; // skip to next lightmap @@ -638,7 +628,7 @@ public abstract class Light extends Warp { } catch (longjmpException store) {} // put into texture format - stride -= (smax<<2); + stride -= smax; bl = s_blocklights; int blp = 0; @@ -697,8 +687,8 @@ public abstract class Light extends Warp { b = (int)(b*t); a = (int)(a*t); } - dest.put((byte)r).put((byte)g).put((byte)b).put((byte)a); - destp += 4; + r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; + dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | (r << 0)); } } } @@ -778,9 +768,8 @@ public abstract class Light extends Warp { a = 255 - a; break; } - - dest.put((byte)r).put((byte)g).put((byte)b).put((byte)a); - destp += 4; + r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; + dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | (r << 0)); } } } diff --git a/src/jake2/render/jogl/Main.java b/src/jake2/render/jogl/Main.java index 32442ba..2b46501 100644 --- a/src/jake2/render/jogl/Main.java +++ b/src/jake2/render/jogl/Main.java @@ -2,7 +2,7 @@ * Main.java * Copyright (C) 2003 * - * $Id: Main.java,v 1.2 2004-07-08 15:58:44 hzi Exp $ + * $Id: Main.java,v 1.3 2004-07-09 06:50:47 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -29,6 +29,7 @@ import jake2.*; import jake2.client.*; import jake2.game.cplane_t; import jake2.game.cvar_t; +import jake2.qcommon.Cvar; import jake2.qcommon.qfiles; import jake2.qcommon.xcommand_t; import jake2.render.*; @@ -36,9 +37,12 @@ import jake2.util.Math3D; import jake2.util.Vargs; import java.awt.Dimension; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; import net.java.games.jogl.GL; import net.java.games.jogl.GLU; +import net.java.games.jogl.util.BufferUtils; import net.java.games.jogl.util.GLUT; /** @@ -52,7 +56,7 @@ public abstract class Main extends Base { GLU glu; GLUT glut = new GLUT(); - int[] d_8to24table = new int[256]; + public static int[] d_8to24table = new int[256]; int c_visible_lightmaps; int c_visible_textures; @@ -66,8 +70,8 @@ public abstract class Main extends Base { boolean qglActiveTextureARB = false; boolean qglPointParameterfEXT = false; boolean qglLockArraysEXT = false; - boolean qglUnlockArraysEXT = false; boolean qglMTexCoord2fSGIS = false; + boolean qwglSwapIntervalEXT = false; // ================= // abstract methods @@ -323,22 +327,22 @@ public abstract class Main extends Base { gl.glTexCoord2f(0, 1); Math3D.VectorMA(e.origin, -frame.origin_y, vup, point); Math3D.VectorMA(point, -frame.origin_x, vright, point); - gl.glVertex3fv(point); + gl.glVertex3f(point[0], point[1], point[2]); gl.glTexCoord2f(0, 0); Math3D.VectorMA(e.origin, frame.height - frame.origin_y, vup, point); Math3D.VectorMA(point, -frame.origin_x, vright, point); - gl.glVertex3fv(point); + gl.glVertex3f(point[0], point[1], point[2]); gl.glTexCoord2f(1, 0); Math3D.VectorMA(e.origin, frame.height - frame.origin_y, vup, point); Math3D.VectorMA(point, frame.width - frame.origin_x, vright, point); - gl.glVertex3fv(point); + gl.glVertex3f(point[0], point[1], point[2]); gl.glTexCoord2f(1, 1); Math3D.VectorMA(e.origin, -frame.origin_y, vup, point); Math3D.VectorMA(point, frame.width - frame.origin_x, vright, point); - gl.glVertex3fv(point); + gl.glVertex3f(point[0], point[1], point[2]); gl.glEnd(); @@ -375,7 +379,7 @@ public abstract class Main extends Base { R_RotateForEntity(currententity); gl.glDisable(GL.GL_TEXTURE_2D); - gl.glColor3fv(shadelight); + gl.glColor3f(shadelight[0], shadelight[1], shadelight[2]); // this replaces the TRIANGLE_FAN glut.glutWireCube(gl, 20); @@ -479,63 +483,63 @@ public abstract class Main extends Base { } gl.glDepthMask(true); // back to writing } - + /* ** GL_DrawParticles ** */ - void GL_DrawParticles(int num_particles, particle_t[] particles) { - particle_t p; - int i; + void GL_DrawParticles(int num_particles) { float[] up = { 0, 0, 0 }; float[] right = { 0, 0, 0 }; float scale; int color; + float origin_x, origin_y, origin_z; + + Math3D.VectorScale(vup, 1.5f, up); + Math3D.VectorScale(vright, 1.5f, right); + GL_Bind(r_particletexture.texnum); gl.glDepthMask(false); // no z buffering gl.glEnable(GL.GL_BLEND); GL_TexEnv(GL.GL_MODULATE); + gl.glBegin(GL.GL_TRIANGLES); - Math3D.VectorScale(vup, 1.5f, up); - Math3D.VectorScale(vright, 1.5f, right); + FloatBuffer sourceVertices = particle_t.vertexArray; + IntBuffer sourceColors = particle_t.colorArray; + for (int j = 0, i = 0; i < num_particles; i++) { + origin_x = sourceVertices.get(j++); + origin_y = sourceVertices.get(j++); + origin_z = sourceVertices.get(j++); - for (i = 0; i < num_particles; i++) { - p = particles[i]; // hack a scale up to keep particles from disapearing scale = - (p.origin[0] - r_origin[0]) * vpn[0] - + (p.origin[1] - r_origin[1]) * vpn[1] - + (p.origin[2] - r_origin[2]) * vpn[2]; + (origin_x - r_origin[0]) * vpn[0] + + (origin_y - r_origin[1]) * vpn[1] + + (origin_z - r_origin[2]) * vpn[2]; - if (scale < 20) - scale = 1; - else - scale = 1 + scale * 0.004f; - - color = d_8to24table[p.color]; + scale = (scale < 20) ? 1 : 1 + scale * 0.004f; + color = sourceColors.get(i); gl.glColor4ub( - (byte) ((color >> 0) & 0xff), - (byte) ((color >> 8) & 0xff), - (byte) ((color >> 16) & 0xff), - (byte) (p.alpha * 255)); - + (byte)((color >> 0) & 0xFF), + (byte)((color >> 8) & 0xFF), + (byte)((color >> 16) & 0xFF), + (byte)((color >> 24) & 0xFF) + ); + // first vertex gl.glTexCoord2f(0.0625f, 0.0625f); - gl.glVertex3fv(p.origin); - + gl.glVertex3f(origin_x, origin_y, origin_z); + // second vertex gl.glTexCoord2f(1.0625f, 0.0625f); - gl.glVertex3f(p.origin[0] + up[0] * scale, p.origin[1] + up[1] * scale, p.origin[2] + up[2] * scale); - + gl.glVertex3f(origin_x + up[0] * scale, origin_y + up[1] * scale, origin_z + up[2] * scale); + // third vertex gl.glTexCoord2f(0.0625f, 1.0625f); - gl.glVertex3f( - p.origin[0] + right[0] * scale, - p.origin[1] + right[1] * scale, - p.origin[2] + right[2] * scale); + gl.glVertex3f(origin_x + right[0] * scale, origin_y + right[1] * scale, origin_z + right[2] * scale); } - gl.glEnd(); + gl.glDisable(GL.GL_BLEND); gl.glColor4f(1, 1, 1, 1); gl.glDepthMask(true); // back to normal Z buffering @@ -550,29 +554,21 @@ public abstract class Main extends Base { void R_DrawParticles() { if (gl_ext_pointparameters.value != 0.0f && qglPointParameterfEXT) { - int color; - particle_t p; + gl.glEnableClientState(GL.GL_VERTEX_ARRAY); + gl.glVertexPointer(3, GL.GL_FLOAT, 0, particle_t.vertexArray); + gl.glEnableClientState(GL.GL_COLOR_ARRAY); + gl.glColorPointer(4, GL.GL_UNSIGNED_BYTE, 0, particle_t.colorArray); + gl.glDepthMask(false); gl.glEnable(GL.GL_BLEND); gl.glDisable(GL.GL_TEXTURE_2D); - gl.glPointSize(gl_particle_size.value); - - gl.glBegin(GL.GL_POINTS); - for (int i = 0; i < r_newrefdef.num_particles; i++) { - p = r_newrefdef.particles[i]; - color = d_8to24table[p.color]; - - gl.glColor4ub( - (byte) ((color >> 0) & 0xff), - (byte) ((color >> 8) & 0xff), - (byte) ((color >> 16) & 0xff), - (byte) (p.alpha * 255)); - - gl.glVertex3fv(p.origin); - } - gl.glEnd(); + + gl.glDrawArrays(GL.GL_POINTS, 0, r_newrefdef.num_particles); + + gl.glDisableClientState(GL.GL_COLOR_ARRAY); + gl.glDisableClientState(GL.GL_VERTEX_ARRAY); gl.glDisable(GL.GL_BLEND); gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -581,7 +577,7 @@ public abstract class Main extends Base { } else { - GL_DrawParticles(r_newrefdef.num_particles, r_newrefdef.particles); + GL_DrawParticles(r_newrefdef.num_particles); } } @@ -608,7 +604,7 @@ public abstract class Main extends Base { gl.glRotatef(-90, 1, 0, 0); // put Z going up gl.glRotatef(90, 0, 0, 1); // put Z going up - gl.glColor4fv(v_blend); + gl.glColor4f(v_blend[0], v_blend[1], v_blend[2], v_blend[3]); gl.glBegin(GL.GL_QUADS); @@ -958,7 +954,7 @@ public abstract class Main extends Base { protected void R_Register() { r_lefthand = ri.Cvar_Get("hand", "0", Globals.CVAR_USERINFO | Globals.CVAR_ARCHIVE); r_norefresh = ri.Cvar_Get("r_norefresh", "0", 0); - r_fullbright = ri.Cvar_Get("r_fullbright", "1", 0); + r_fullbright = ri.Cvar_Get("r_fullbright", "0", 0); r_drawentities = ri.Cvar_Get("r_drawentities", "1", 0); r_drawworld = ri.Cvar_Get("r_drawworld", "1", 0); r_novis = ri.Cvar_Get("r_novis", "0", 0); @@ -1007,7 +1003,7 @@ public abstract class Main extends Base { gl_vertex_arrays = ri.Cvar_Get("gl_vertex_arrays", "0", Globals.CVAR_ARCHIVE); gl_ext_swapinterval = ri.Cvar_Get("gl_ext_swapinterval", "1", Globals.CVAR_ARCHIVE); - gl_ext_palettedtexture = ri.Cvar_Get("gl_ext_palettedtexture", "1", Globals.CVAR_ARCHIVE); + gl_ext_palettedtexture = ri.Cvar_Get("gl_ext_palettedtexture", "0", Globals.CVAR_ARCHIVE); gl_ext_multitexture = ri.Cvar_Get("gl_ext_multitexture", "1", Globals.CVAR_ARCHIVE); gl_ext_pointparameters = ri.Cvar_Get("gl_ext_pointparameters", "1", Globals.CVAR_ARCHIVE); gl_ext_compiled_vertex_array = ri.Cvar_Get("gl_ext_compiled_vertex_array", "1", Globals.CVAR_ARCHIVE); @@ -1056,11 +1052,11 @@ public abstract class Main extends Base { int err; // enum rserr_t boolean fullscreen; - if (vid_fullscreen.modified && !gl_config.allow_cds) { - ri.Con_Printf(Defines.PRINT_ALL, "R_SetMode() - CDS not allowed with this driver\n"); - ri.Cvar_SetValue("vid_fullscreen", (vid_fullscreen.value > 0.0f) ? 0.0f : 1.0f); - vid_fullscreen.modified = false; - } +// if (vid_fullscreen.modified && !gl_config.allow_cds) { +// ri.Con_Printf(Defines.PRINT_ALL, "R_SetMode() - CDS not allowed with this driver\n"); +// ri.Cvar_SetValue("vid_fullscreen", (vid_fullscreen.value > 0.0f) ? 0.0f : 1.0f); +// vid_fullscreen.modified = false; +// } fullscreen = (vid_fullscreen.value > 0.0f); @@ -1237,25 +1233,24 @@ public abstract class Main extends Base { || gl_config.extensions_string.indexOf("GL_SGI_compiled_vertex_array") >= 0) { ri.Con_Printf(Defines.PRINT_ALL, "...enabling GL_EXT_compiled_vertex_array\n"); // qglLockArraysEXT = ( void * ) qwglGetProcAddress( "glLockArraysEXT" ); - qglLockArraysEXT = true; + if (gl_ext_compiled_vertex_array.value != 0.0f) + qglLockArraysEXT = true; + else + qglLockArraysEXT = false; // qglUnlockArraysEXT = ( void * ) qwglGetProcAddress( "glUnlockArraysEXT" ); - qglUnlockArraysEXT = true; + //qglUnlockArraysEXT = true; } else { ri.Con_Printf(Defines.PRINT_ALL, "...GL_EXT_compiled_vertex_array not found\n"); } - // #ifdef _WIN32 - // if ( strstr( gl_config.extensions_string, "WGL_EXT_swap_control" ) ) - // { - // qwglSwapIntervalEXT = ( BOOL (WINAPI *)(int)) qwglGetProcAddress( "wglSwapIntervalEXT" ); - // ri.Con_Printf( Defines.PRINT_ALL, "...enabling WGL_EXT_swap_control\n" ); - // } - // else - // { - // ri.Con_Printf( Defines.PRINT_ALL, "...WGL_EXT_swap_control not found\n" ); - // } - // #endif + if (gl_config.extensions_string.indexOf("WGL_EXT_swap_control") >= 0) { + qwglSwapIntervalEXT = true; + ri.Con_Printf(Defines.PRINT_ALL, "...enabling WGL_EXT_swap_control\n"); + } else { + qwglSwapIntervalEXT = false; + ri.Con_Printf(Defines.PRINT_ALL, "...WGL_EXT_swap_control not found\n"); + } if (gl_config.extensions_string.indexOf("GL_EXT_point_parameters") >= 0) { if (gl_ext_pointparameters.value != 0.0f) { @@ -1301,6 +1296,7 @@ public abstract class Main extends Base { } else { ri.Con_Printf(Defines.PRINT_ALL, "...ignoring GL_EXT_shared_texture_palette\n"); + qglColorTableEXT = false; } } else { @@ -1317,34 +1313,40 @@ public abstract class Main extends Base { qglMTexCoord2fSGIS = true; GL_TEXTURE0 = GL.GL_TEXTURE0_ARB; GL_TEXTURE1 = GL.GL_TEXTURE1_ARB; + Cvar.SetValue("r_fullbright", 1); } else { ri.Con_Printf(Defines.PRINT_ALL, "...ignoring GL_ARB_multitexture\n"); + Cvar.SetValue("r_fullbright", 0); } } else { ri.Con_Printf(Defines.PRINT_ALL, "...GL_ARB_multitexture not found\n"); + Cvar.SetValue("r_fullbright", 0); } if (gl_config.extensions_string.indexOf("GL_SGIS_multitexture") >= 0) { if (qglActiveTextureARB) { ri.Con_Printf(Defines.PRINT_ALL, "...GL_SGIS_multitexture deprecated in favor of ARB_multitexture\n"); - } - else if (gl_ext_multitexture.value != 0.0f) { + Cvar.SetValue("r_fullbright", 1); + } else if (gl_ext_multitexture.value != 0.0f) { ri.Con_Printf(Defines.PRINT_ALL, "...using GL_SGIS_multitexture\n"); // qglMTexCoord2fSGIS = ( void * ) qwglGetProcAddress( "glMTexCoord2fSGIS" ); // qglSelectTextureSGIS = ( void * ) qwglGetProcAddress( "glSelectTextureSGIS" ); qglSelectTextureSGIS = true; qglMTexCoord2fSGIS = true; + Cvar.SetValue("r_fullbright", 1); // //GL_TEXTURE0 = GL.GL_TEXTURE0_SGIS; // //GL_TEXTURE1 = GL.GL_TEXTURE1_SGIS; - } - else { + } else { ri.Con_Printf(Defines.PRINT_ALL, "...ignoring GL_SGIS_multitexture\n"); + Cvar.SetValue("r_fullbright", 0); } } else { ri.Con_Printf(Defines.PRINT_ALL, "...GL_SGIS_multitexture not found\n"); + if (!qglActiveTextureARB) + Cvar.SetValue("r_fullbright", 0); } GL_SetDefaultState(); @@ -1359,7 +1361,7 @@ public abstract class Main extends Base { ri.Con_Printf( Defines.PRINT_ALL, "glGetError() = 0x%x\n\t%s\n", - new Vargs(2).add(err).add(gl.glGetString(err))); + new Vargs(2).add(err).add("" + gl.glGetString(err))); return true; } @@ -1406,7 +1408,7 @@ public abstract class Main extends Base { // FIXME: only restart if CDS is required cvar_t ref; - ref = ri.Cvar_Get("vid_ref", "gl", 0); + ref = ri.Cvar_Get("vid_ref", "jogl", 0); ref.modified = true; } @@ -1511,26 +1513,22 @@ public abstract class Main extends Base { ============= */ protected void R_SetPalette(byte[] palette) { - - //assert(palette != null && palette.length == 768) : "byte palette[768] bug"; - // es darf auch null sein - + // 256 RGB values (768 bytes) + // or null int i; int color = 0; if (palette != null) { - + int j =0; for (i = 0; i < 256; i++) { - color = (palette[i * 3 + 0] << 0) & 0x000000FF; - color |= (palette[i * 3 + 1] << 8) & 0x0000FF00; - color |= (palette[i * 3 + 2] << 8) & 0x00FF0000; + color = (palette[j++] & 0xFF) << 0; + color |= (palette[j++] & 0xFF) << 8; + color |= (palette[j++] & 0xFF) << 16; color |= 0xFF000000; r_rawpalette[i] = color; } - } else { - for (i = 0; i < 256; i++) { r_rawpalette[i] = d_8to24table[i] | 0xff000000; } @@ -1543,6 +1541,9 @@ public abstract class Main extends Base { } static final int NUM_BEAM_SEGS = 6; + float[][] start_points = new float[NUM_BEAM_SEGS][3]; + // array of vec3_t + float[][] end_points = new float[NUM_BEAM_SEGS][3]; // array of vec3_t /* ** R_DrawBeam @@ -1556,10 +1557,6 @@ public abstract class Main extends Base { float[] direction = { 0, 0, 0 }; // vec3_t float[] normalized_direction = { 0, 0, 0 }; // vec3_t - float[][] start_points = new float[NUM_BEAM_SEGS][3]; - // array of vec3_t - float[][] end_points = new float[NUM_BEAM_SEGS][3]; // array of vec3_t - float[] oldorigin = { 0, 0, 0 }; // vec3_t float[] origin = { 0, 0, 0 }; // vec3_t @@ -1607,11 +1604,18 @@ public abstract class Main extends Base { gl.glColor4f(r, g, b, e.alpha); gl.glBegin(GL.GL_TRIANGLE_STRIP); + + float[] v; + for (i = 0; i < NUM_BEAM_SEGS; i++) { - gl.glVertex3fv(start_points[i]); - gl.glVertex3fv(end_points[i]); - gl.glVertex3fv(start_points[(i + 1) % NUM_BEAM_SEGS]); - gl.glVertex3fv(end_points[(i + 1) % NUM_BEAM_SEGS]); + v = start_points[i]; + gl.glVertex3f(v[0], v[1], v[2]); + v = end_points[i]; + gl.glVertex3f(v[0], v[1], v[2]); + v = start_points[(i + 1) % NUM_BEAM_SEGS]; + gl.glVertex3f(v[0], v[1], v[2]); + v = end_points[(i + 1) % NUM_BEAM_SEGS]; + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); diff --git a/src/jake2/render/jogl/Mesh.java b/src/jake2/render/jogl/Mesh.java index 37e4445..991bf37 100644 --- a/src/jake2/render/jogl/Mesh.java +++ b/src/jake2/render/jogl/Mesh.java @@ -2,7 +2,7 @@ * Mesh.java * Copyright (C) 2003 * - * $Id: Mesh.java,v 1.3 2004-07-08 20:24:30 hzi Exp $ + * $Id: Mesh.java,v 1.4 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -104,36 +104,36 @@ public abstract class Mesh extends Light { { int i; int lerpIndex = 0; - lerp.position(0); //PMM -- added RF_SHELL_DOUBLE, RF_SHELL_HALF_DAM if ( (currententity.flags & ( Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0 ) { float[] normal; + int j = 0; for (i=0 ; i < nverts; i++/* , v++, ov++, lerp+=4 */) { normal = r_avertexnormals[verts[i].lightnormalindex]; - lerp.put(move[0] + ov[i].v[0]*backv[0] + v[i].v[0]*frontv[0] + normal[0] * Defines.POWERSUIT_SCALE); - lerp.put(move[1] + ov[i].v[1]*backv[1] + v[i].v[1]*frontv[1] + normal[1] * Defines.POWERSUIT_SCALE); - lerp.put(move[2] + ov[i].v[2]*backv[2] + v[i].v[2]*frontv[2] + normal[2] * Defines.POWERSUIT_SCALE); - lerp.get(); + lerp.put(j++, move[0] + ov[i].v[0]*backv[0] + v[i].v[0]*frontv[0] + normal[0] * Defines.POWERSUIT_SCALE); + lerp.put(j++, move[1] + ov[i].v[1]*backv[1] + v[i].v[1]*frontv[1] + normal[1] * Defines.POWERSUIT_SCALE); + lerp.put(j++, move[2] + ov[i].v[2]*backv[2] + v[i].v[2]*frontv[2] + normal[2] * Defines.POWERSUIT_SCALE); } } else { + int j = 0; for (i=0 ; i < nverts; i++ /* , v++, ov++, lerp+=4 */) { - lerp.put(move[0] + ov[i].v[0]*backv[0] + v[i].v[0]*frontv[0]); - lerp.put(move[1] + ov[i].v[1]*backv[1] + v[i].v[1]*frontv[1]); - lerp.put(move[2] + ov[i].v[2]*backv[2] + v[i].v[2]*frontv[2]); - lerp.get(); + + lerp.put(j++, move[0] + ov[i].v[0]*backv[0] + v[i].v[0]*frontv[0]); + lerp.put(j++, move[1] + ov[i].v[1]*backv[1] + v[i].v[1]*frontv[1]); + lerp.put(j++, move[2] + ov[i].v[2]*backv[2] + v[i].v[2]*frontv[2]); } } } FloatBuffer colorArrayBuf = BufferUtils.newFloatBuffer(qfiles.MAX_VERTS * 4); - FloatBuffer vertexArrayBuf = BufferUtils.newFloatBuffer(qfiles.MAX_VERTS * 4); + FloatBuffer vertexArrayBuf = BufferUtils.newFloatBuffer(qfiles.MAX_VERTS * 3); boolean isFilled = false; float[] tmpVec = {0, 0, 0}; @@ -218,7 +218,7 @@ public abstract class Mesh extends Light { GL_LerpVerts( paliashdr.num_xyz, v, ov, verts, vertexArrayBuf, move, frontv, backv ); gl.glEnableClientState( GL.GL_VERTEX_ARRAY ); - gl.glVertexPointer( 3, GL.GL_FLOAT, 16, vertexArrayBuf ); // padded for SIMD + gl.glVertexPointer( 3, GL.GL_FLOAT, 0, vertexArrayBuf ); // PMM - added double damage shell if ( (currententity.flags & ( Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) @@ -233,11 +233,15 @@ public abstract class Mesh extends Light { // // pre light everything // - colorArrayBuf.position(0); + FloatBuffer color = colorArrayBuf; + int j = 0; for ( i = 0; i < paliashdr.num_xyz; i++ ) { l = shadedots[verts[i].lightnormalindex]; - colorArrayBuf.put(l * shadelight[0]).put(l * shadelight[1]).put(l * shadelight[2]).put(alpha); + color.put(j++, l * shadelight[0]); + color.put(j++, l * shadelight[1]); + color.put(j++, l * shadelight[2]); + color.put(j++, alpha); } } @@ -294,13 +298,15 @@ public abstract class Mesh extends Light { gl.glEnd (); } - if ( qglUnlockArraysEXT ) + if ( qglLockArraysEXT ) gl.glUnlockArraysEXT(); } else { GL_LerpVerts( paliashdr.num_xyz, v, ov, verts, s_lerped, move, frontv, backv ); + float[] tmp; + while (true) { // get the vertex count and primitive type @@ -325,7 +331,8 @@ public abstract class Mesh extends Light { orderIndex += 3; gl.glColor4f( shadelight[0], shadelight[1], shadelight[2], alpha); - gl.glVertex3fv (s_lerped[index_xyz]); + tmp = s_lerped[index_xyz]; + gl.glVertex3f(tmp[0], tmp[1], tmp[2]); } while (--count != 0); } @@ -344,7 +351,8 @@ public abstract class Mesh extends Light { l = shadedots[verts[index_xyz].lightnormalindex]; gl.glColor4f (l* shadelight[0], l*shadelight[1], l*shadelight[2], alpha); - gl.glVertex3fv (s_lerped[index_xyz]); + tmp = s_lerped[index_xyz]; + gl.glVertex3f(tmp[0], tmp[1], tmp[2]); } while (--count != 0); } gl.glEnd (); @@ -384,6 +392,7 @@ public abstract class Mesh extends Light { height = -lheight + 1.0f; int orderIndex = 0; + int index = 0; while (true) { @@ -410,18 +419,20 @@ public abstract class Mesh extends Light { if ( gl_vertex_arrays.value != 0.0f ) { - vertexArrayBuf.position(order[orderIndex + 2] * 4); - vertexArrayBuf.get(point); + index = order[orderIndex + 2] * 3; + point[0] = vertexArrayBuf.get(index); + point[1] = vertexArrayBuf.get(index + 1); + point[2] = vertexArrayBuf.get(index + 2); } else { - System.arraycopy(s_lerped[order[orderIndex + 2]], 0, point, 0, 3); + Math3D.VectorCopy(s_lerped[order[orderIndex + 2]], point); } point[0] -= shadevector[0]*(point[2]+lheight); point[1] -= shadevector[1]*(point[2]+lheight); point[2] = height; - gl.glVertex3fv (point); + gl.glVertex3f(point[0], point[1], point[2]); orderIndex += 3; diff --git a/src/jake2/render/jogl/Misc.java b/src/jake2/render/jogl/Misc.java index 8f04a84..a1d2e70 100644 --- a/src/jake2/render/jogl/Misc.java +++ b/src/jake2/render/jogl/Misc.java @@ -2,7 +2,7 @@ * Misc.java * Copyright (C) 2003 * - * $Id: Misc.java,v 1.1 2004-07-07 19:59:41 hzi Exp $ + * $Id: Misc.java,v 1.2 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -25,9 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.jogl; -import net.java.games.jogl.GL; - import jake2.Defines; +import net.java.games.jogl.GL; +import net.java.games.jogl.WGL; /** * Misc @@ -249,13 +249,11 @@ public abstract class Misc extends Mesh { if ( gl_swapinterval.modified ) { gl_swapinterval.modified = false; - if ( !gl_state.stereo_enabled ) { -// #ifdef _WIN32 -// if ( qwglSwapIntervalEXT ) -// qwglSwapIntervalEXT( gl_swapinterval->value ); -// #endif + if (qwglSwapIntervalEXT) { + ((WGL)gl).wglSwapIntervalEXT((int)gl_swapinterval.value); + } } } } diff --git a/src/jake2/render/jogl/Model.java b/src/jake2/render/jogl/Model.java index 8c2cfc8..75357c3 100644 --- a/src/jake2/render/jogl/Model.java +++ b/src/jake2/render/jogl/Model.java @@ -2,7 +2,7 @@ * Model.java * Copyright (C) 2003 * - * $Id: Model.java,v 1.1 2004-07-07 19:59:42 hzi Exp $ + * $Id: Model.java,v 1.2 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -517,6 +517,9 @@ public abstract class Model extends Surf { count = l.filelen / texinfo_t.SIZE; // out = Hunk_Alloc ( count*sizeof(*out)); out = new mtexinfo_t[count]; + for ( i=0 ; i<count ; i++) { + out[i] = new mtexinfo_t(); + } loadmodel.texinfo = out; loadmodel.numtexinfo = count; @@ -524,13 +527,10 @@ public abstract class Model extends Surf { ByteBuffer bb = ByteBuffer.wrap(mod_base, l.fileofs, l.filelen); bb.order(ByteOrder.LITTLE_ENDIAN); - for ( i=0 ; i<count ; i++) - { - in = new texinfo_t(bb); - out[i] = new mtexinfo_t(); - //for (j=0 ; j<8 ; j++) - out[i].vecs = in.vecs; + for ( i=0 ; i<count ; i++) { + in = new texinfo_t(bb); + out[i].vecs = in.vecs; out[i].flags = in.flags; next = in.nexttexinfo; if (next > 0) @@ -541,17 +541,14 @@ public abstract class Model extends Surf { name = "textures/" + in.texture + ".wal"; out[i].image = GL_FindImage(name, it_wall); - if (out[i].image == null) - { + if (out[i].image == null) { ri.Con_Printf(Defines.PRINT_ALL, "Couldn't load " + name + '\n'); out[i].image = r_notexture; } } // count animation frames - for (i=0 ; i<count ; i++) - { - // out = &loadmodel.texinfo[i]; + for (i=0 ; i<count ; i++) { out[i].numframes = 1; for (step = out[i].next ; (step != null) && (step != out[i]) ; step=step.next) out[i].numframes++; diff --git a/src/jake2/render/jogl/Surf.java b/src/jake2/render/jogl/Surf.java index 7f05332..54e0e77 100644 --- a/src/jake2/render/jogl/Surf.java +++ b/src/jake2/render/jogl/Surf.java @@ -2,7 +2,7 @@ * Surf.java * Copyright (C) 2003 * - * $Id: Surf.java,v 1.2 2004-07-08 20:24:30 hzi Exp $ + * $Id: Surf.java,v 1.3 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -25,35 +25,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.render.jogl; -import java.awt.geom.AffineTransform; -import java.awt.image.AffineTransformOp; -import java.awt.image.BufferedImage; -import java.nio.ByteBuffer; +import jake2.Defines; +import jake2.client.*; +import jake2.game.cplane_t; +import jake2.render.*; +import jake2.util.Lib; +import jake2.util.Math3D; + import java.nio.ByteOrder; import java.nio.IntBuffer; import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; import net.java.games.jogl.GL; -import net.java.games.jogl.util.BufferUtils; - -import jake2.Defines; -import jake2.client.dlight_t; -import jake2.client.entity_t; -import jake2.client.lightstyle_t; -import jake2.game.cplane_t; -import jake2.imageio.ImageFrame; -import jake2.render.glpoly_t; -import jake2.render.image_t; -import jake2.render.medge_t; -import jake2.render.mleaf_t; -import jake2.render.mnode_t; -import jake2.render.model_t; -import jake2.render.msurface_t; -import jake2.render.mtexinfo_t; -import jake2.util.Lib; -import jake2.util.Math3D; /** * Surf @@ -92,7 +75,7 @@ public abstract class Surf extends Draw { // the lightmap texture data needs to be kept in // main memory so texsubimage can update properly - byte[] lightmap_buffer = new byte[4 * BLOCK_WIDTH * BLOCK_HEIGHT]; + IntBuffer lightmap_buffer = Lib.newIntBuffer(BLOCK_WIDTH * BLOCK_HEIGHT, ByteOrder.LITTLE_ENDIAN); public gllightmapstate_t() { @@ -129,7 +112,7 @@ public abstract class Surf extends Draw { // Light.java abstract void R_MarkLights (dlight_t light, int bit, mnode_t node); abstract void R_SetCacheState( msurface_t surf ); - abstract void R_BuildLightMap(msurface_t surf, ByteBuffer dest, int stride); + abstract void R_BuildLightMap(msurface_t surf, IntBuffer dest, int stride); /* ============================================================= @@ -178,7 +161,7 @@ public abstract class Surf extends Draw { { v = p.verts[i]; gl.glTexCoord2f(v[3], v[4]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); } @@ -208,7 +191,7 @@ public abstract class Surf extends Draw { { v = p.verts[i]; gl.glTexCoord2f ((v[3] + scroll), v[4]); - gl.glVertex3fv( v ); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -273,7 +256,7 @@ public abstract class Surf extends Draw { { v = p.verts[j]; gl.glTexCoord2f (v[5], v[6] ); - gl.glVertex3fv( v ); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); } @@ -290,7 +273,7 @@ public abstract class Surf extends Draw { { v = p.verts[j]; gl.glTexCoord2f (v[5] - soffset, v[6] - toffset ); - gl.glVertex3fv( v ); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); } @@ -399,7 +382,7 @@ public abstract class Surf extends Draw { for ( surf = gl_lms.lightmap_surfaces[0]; surf != null; surf = surf.lightmapchain ) { int smax, tmax; - ByteBuffer base; + IntBuffer base; smax = (surf.extents[0]>>4)+1; tmax = (surf.extents[1]>>4)+1; @@ -412,10 +395,10 @@ public abstract class Surf extends Draw { surf.dlight_s = lightPos.x; surf.dlight_t = lightPos.y; - base = ByteBuffer.wrap(gl_lms.lightmap_buffer); - base.position( ( surf.dlight_t * BLOCK_WIDTH + surf.dlight_s ) * LIGHTMAP_BYTES); + base = gl_lms.lightmap_buffer; + base.position(surf.dlight_t * BLOCK_WIDTH + surf.dlight_s ); - R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES); + R_BuildLightMap (surf, base.slice(), BLOCK_WIDTH); } else { @@ -448,10 +431,10 @@ public abstract class Surf extends Draw { surf.dlight_s = lightPos.x; surf.dlight_t = lightPos.y; - base = ByteBuffer.wrap(gl_lms.lightmap_buffer); - base.position( ( surf.dlight_t * BLOCK_WIDTH + surf.dlight_s ) * LIGHTMAP_BYTES); + base = gl_lms.lightmap_buffer; + base.position(surf.dlight_t * BLOCK_WIDTH + surf.dlight_s ); - R_BuildLightMap (surf, base, BLOCK_WIDTH*LIGHTMAP_BYTES); + R_BuildLightMap (surf, base.slice(), BLOCK_WIDTH); } } @@ -476,7 +459,7 @@ public abstract class Surf extends Draw { gl.glDepthMask( true ); } - private ByteBuffer temp2 = BufferUtils.newByteBuffer(34 * 34 * 4); + private IntBuffer temp2 = Lib.newIntBuffer(34 * 34, ByteOrder.LITTLE_ENDIAN); /* ================ @@ -562,7 +545,7 @@ public abstract class Surf extends Draw { smax = (fa.extents[0]>>4)+1; tmax = (fa.extents[1]>>4)+1; - R_BuildLightMap( fa, temp2, smax*4 ); + R_BuildLightMap( fa, temp2, smax); R_SetCacheState( fa ); GL_Bind( gl_state.lightmap_textures + fa.lightmaptexturenum ); @@ -717,7 +700,7 @@ public abstract class Surf extends Draw { } // direct buffer - ByteBuffer temp = BufferUtils.newByteBuffer(128 * 128 * 4); + private IntBuffer temp = Lib.newIntBuffer(128 * 128, ByteOrder.LITTLE_ENDIAN); void GL_RenderLightmappedPoly( msurface_t surf ) { @@ -766,7 +749,7 @@ public abstract class Surf extends Draw { smax = (surf.extents[0]>>4)+1; tmax = (surf.extents[1]>>4)+1; - R_BuildLightMap( surf, temp, smax*4 ); + R_BuildLightMap( surf, temp, smax); R_SetCacheState( surf ); GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum ); @@ -785,7 +768,7 @@ public abstract class Surf extends Draw { smax = (surf.extents[0]>>4)+1; tmax = (surf.extents[1]>>4)+1; - R_BuildLightMap( surf, temp, smax*4 ); + R_BuildLightMap( surf, temp, smax); GL_MBind( GL_TEXTURE1, gl_state.lightmap_textures + 0 ); @@ -825,7 +808,7 @@ public abstract class Surf extends Draw { gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -843,7 +826,7 @@ public abstract class Surf extends Draw { gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -879,7 +862,7 @@ public abstract class Surf extends Draw { gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]); // qglMTexCoord2fSGIS( GL_TEXTURE0, (v[3]+scroll), v[4]); // qglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd(); } @@ -899,7 +882,7 @@ public abstract class Surf extends Draw { gl.glMultiTexCoord2fARB(GL_TEXTURE1, v[5], v[6]); //gglMTexCoord2fSGIS( GL_TEXTURE0, v[3], v[4]); //gglMTexCoord2fSGIS( GL_TEXTURE1, v[5], v[6]); - gl.glVertex3fv(v); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -1558,7 +1541,7 @@ public abstract class Surf extends Draw { void GL_CreateSurfaceLightmap(msurface_t surf) { int smax, tmax; - ByteBuffer base; + IntBuffer base; if ( (surf.flags & (Defines.SURF_DRAWSKY | Defines.SURF_DRAWTURB)) != 0) return; @@ -1585,13 +1568,12 @@ public abstract class Surf extends Draw { surf.lightmaptexturenum = gl_lms.current_lightmap_texture; - // base = gl_lms.lightmap_buffer; - base = ByteBuffer.wrap(gl_lms.lightmap_buffer); - int basep = (surf.light_t * BLOCK_WIDTH + surf.light_s) * LIGHTMAP_BYTES; + int basep = (surf.light_t * BLOCK_WIDTH + surf.light_s);// * LIGHTMAP_BYTES; + base = gl_lms.lightmap_buffer; base.position(basep); R_SetCacheState( surf ); - R_BuildLightMap(surf, base.slice(), BLOCK_WIDTH * LIGHTMAP_BYTES); + R_BuildLightMap(surf, base.slice(), BLOCK_WIDTH); } lightstyle_t[] lightstyles; @@ -1713,26 +1695,26 @@ public abstract class Surf extends Draw { } - ImageFrame frame; + //ImageFrame frame; - void debugLightmap(byte[] buf, int w, int h, float scale) { - IntBuffer pix = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); - - int[] pixel = new int[w * h]; - - pix.get(pixel); - - BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); - image.setRGB(0, 0, w, h, pixel, 0, w); - AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(scale, scale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR); - BufferedImage tmp = op.filter(image, null); - - if (frame == null) { - frame = new ImageFrame(null); - frame.show(); - } - frame.showImage(tmp); - - } +// void debugLightmap(byte[] buf, int w, int h, float scale) { +// IntBuffer pix = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); +// +// int[] pixel = new int[w * h]; +// +// pix.get(pixel); +// +// BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); +// image.setRGB(0, 0, w, h, pixel, 0, w); +// AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(scale, scale), AffineTransformOp.TYPE_NEAREST_NEIGHBOR); +// BufferedImage tmp = op.filter(image, null); +// +// if (frame == null) { +// frame = new ImageFrame(null); +// frame.show(); +// } +// frame.showImage(tmp); +// +// } } diff --git a/src/jake2/render/jogl/Warp.java b/src/jake2/render/jogl/Warp.java index 8ccb93a..6dc5145 100644 --- a/src/jake2/render/jogl/Warp.java +++ b/src/jake2/render/jogl/Warp.java @@ -2,7 +2,7 @@ * Warp.java * Copyright (C) 2003 * - * $Id: Warp.java,v 1.3 2004-07-08 20:24:30 hzi Exp $ + * $Id: Warp.java,v 1.4 2004-07-09 06:50:48 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -313,7 +313,7 @@ public abstract class Warp extends Model { t *= (1.0f/64); gl.glTexCoord2f (s, t); - gl.glVertex3fv( v ); + gl.glVertex3f(v[0], v[1], v[2]); } gl.glEnd (); } @@ -612,7 +612,7 @@ public abstract class Warp extends Model { t = 1.0f - t; gl.glTexCoord2f (s, t); - gl.glVertex3fv( v ); + gl.glVertex3f(v[0], v[1], v[2]); } /* |