The code posted below in jogl runs at @ 450+ FPS on a quadro fx 3400, but the same code in lwjgl runs @250-290 FPS. Is it that lwjgl would prefer VBO's instead? I have searched the javagaming forums and and lwjgl forums but as of yet have not yielded a good tutorial on how to do VBO's in lwjgl or jogl. If anyone out out there could be a kind soul and could provide a small tutorial to help both myself and others to learn how to utilize VBO's in lwjgl I amd sure myself and others would be ever so grateful. :wink:
package JavaGL;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.glu.GLU;
public class RenderPolygons extends JGLmain {
public static long startTime = System.currentTimeMillis() + 5000;
public static long pps = 0;
public static float angle = 0.0f;
public static float [] g_cubeVertices = {
1.0f, 0.0f, 0.0f, -1.0f, -1.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, -1.0f, -1.0f, -1.0f,
0.0f, 1.0f, 0.0f, -1.0f, 1.0f, -1.0f,
0.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f,
1.0f, 0.0f, 1.0f, 1.0f, -1.0f, -1.0f,
1.0f, 0.0f, 0.0f, -1.0f, 1.0f, -1.0f,
0.0f, 1.0f, 0.0f, -1.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f,
1.0f, 0.0f, 0.0f, -1.0f, -1.0f, -1.0f,
0.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f,
0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f,
1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f, -1.0f, -1.0f,
0.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f,
0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 1.0f,
1.0f, 0.0f, 0.0f, -1.0f, -1.0f, -1.0f,
0.0f, 1.0f, 0.0f, -1.0f, -1.0f, 1.0f,
0.0f, 0.0f, 1.0f, -1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, -1.0f, 1.0f, -1.0f
};
public static FloatBuffer cubeVertices = BufferUtils.createFloatBuffer(144);
public static void rendershit() {
cubeVertices.put(g_cubeVertices).rewind();
GL11.glColor3f(1.0f,1.0f,1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
//GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
int n = 20;
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
for (int z = 0; z < n; z++) {
if (startTime > System.currentTimeMillis()) { //check to see if startTime is greater than the current System Time in Milliseconds
pps+=6;
GL11.glPushMatrix();
GLU.gluLookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(angle, 1.0f, .0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
int n2 = n/2;
GL11.glTranslatef(x-n2,y-n2,z-n2);
GL11.glScalef(.1f, .1f, .1f);
GL11.glInterleavedArrays(GL11.GL_C3F_V3F, 0, cubeVertices);
GL11.glDrawArrays(GL11.GL_QUADS, 0, 24);
GL11.glPopMatrix();
} else {
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
startTime = System.currentTimeMillis() + 5000;
String outdata = pps + " Polys in " + (float) (timeUsed / 1000f) + " seconds = "+ (pps / (timeUsed / 1000f))+" PPS"; // put all the math into a string
System.out.println( outdata );
pps = 0;
}
}
}
}
angle += 1.0f;
if ( angle > 360.0f )
angle = 0.0f;
}
}
Very Pretty! I started it and totally forgot what I was doing! This is what the output was on a P4 2.66GHz with a GeForce FX5200:
3232242 Polys in 5.0 seconds = 646448.4 PPS
3592014 Polys in 5.0 seconds = 718402.8 PPS
3620526 Polys in 5.0 seconds = 724105.2 PPS
3608646 Polys in 5.0 seconds = 721729.2 PPS
3625764 Polys in 5.0 seconds = 725152.8 PPS
3625080 Polys in 5.0 seconds = 725016.0 PPS
3615678 Polys in 5.0 seconds = 723135.6 PPS
3626856 Polys in 5.0 seconds = 725371.2 PPS
3600234 Polys in 5.0 seconds = 720046.8 PPS
3577218 Polys in 5.0 seconds = 715443.6 PPS
thanks! I found it pretty trippy myself, try some variations on the lookat values to make it fly through as it rotates for more fun. Change the values of n to alter the number of rows and colums of drawn cubes. (A 7800GTX starts to choke on this test with n =100 or more) Hopefully with a few pointers it can be made to run faster FPS, and PPS wise. I am new to java programming but used to be pretty good with C++ and OpenGL, and after a 4 year hiatus' have recently taken OpenGL programming back up.
I would like to send a congrats on the lwjgl development efforts thus far simply awesome.
My only gripe tho thus far is is the lack of tutorials for lwjgl, examples and code snippets can be found easily however and insight as to how they work is what is missing.
It would be great to see more of the NeHe tutorials ported to lwjgl.
My other Question if anyone cares to field it is I am assuming that this same thing using GLSL, and it would be super fast or even more efficient?
Perhaps maybe a few lwjgl+GLSL tutorials? :D
Speed between the two should be identical, are you sure you've getting the same framebuffer format in both tests? Jogl's pixelformat selectors tend to be more forgiving and often drop you back to less than your requested format if they feel like it.
QuotecubeVertices.put(g_cubeVertices).rewind();
You're calling this every frames... It kills the performances.
Is there a better way to go about that?
The first 35 NeHe Tutorials are ported to LWJGL, that should give you a pretty good start and if you programmed OpenGL in C++ you should be able to get right back into the swing of things! :)
yeah i have been looking through them unfourtunately the one I'd like to see right now is tut 45 VBO's.
QuoteQuote:
cubeVertices.put(g_cubeVertices).rewind();
You're calling this every frames... It kills the performances.
I fixed this by moving it outside the loop to a one time init.
Framerate is still signifigantly slower than in jogl.
there is one major diff between the two in jogl i am able to leave the float array untouched and pass it to glInterleavedArrays, however in lwjgl i have to pass a floatbuffer to glInterleavedArrays which requires me to place the float arrays data into a floatbuffer before passing it to glInterleavedArrays.
That won't make any difference...
would you please run both versions using -Xprof and show the output here? Would be interesting to know just why the JOGL one is faster as it's 99% usually the other way round.
Cas :)
java -Xprof -jar joglspec.jar JOGL!!!
Flat profile of 2.33 secs (170 total ticks): main
Interpreted + native Method
35.5% 0 + 27 sun.awt.Win32GraphicsEnvironment.initDisplay
6.6% 0 + 5 net.java.games.jogl.impl.windows.WindowsOnscreenGLConte
xt.createGL
5.3% 4 + 0 java.lang.ClassLoader.defineClass1
3.9% 0 + 3 sun.awt.windows.WComponentPeer.pShow
2.6% 0 + 2 java.util.zip.Inflater.inflateBytes
2.6% 2 + 0 java.lang.StringCoding.trim
1.3% 1 + 0 java.lang.ClassLoader.findBootstrapClass
1.3% 0 + 1 java.lang.ClassLoader$NativeLibrary.load
1.3% 0 + 1 sun.awt.windows.WWindowPeer._setTitle
1.3% 0 + 1 sun.awt.windows.WPanelPeer.pRestack
1.3% 0 + 1 java.io.WinNTFileSystem.getLastModifiedTime
1.3% 0 + 1 java.lang.Object.hashCode
1.3% 0 + 1 joglspec.JsCap.<init>
1.3% 0 + 1 java.util.zip.ZipFile.read
1.3% 1 + 0 javax.swing.plaf.basic.BasicButtonUI.createButtonListen
er
1.3% 0 + 1 java.lang.Thread.currentThread
1.3% 1 + 0 javax.swing.plaf.basic.BasicComboBoxUI.createPopup
1.3% 1 + 0 sun.font.StrikeCache.getGlyphCacheDescription
1.3% 1 + 0 javax.swing.JFormattedTextField.<clinit>
1.3% 1 + 0 java.awt.Component.getGraphicsConfiguration
1.3% 1 + 0 joglspec.JoglSpec.main
1.3% 1 + 0 net.java.games.jogl.impl.GLContext.<init>
1.3% 1 + 0 java.lang.String.trim
1.3% 1 + 0 java.io.Win32FileSystem.normalize
1.3% 1 + 0 joglspec.JtVertPointer3.<init>
88.2% 22 + 45 Total interpreted (including elided)
Compiled + native Method
1.3% 1 + 0 java.util.Arrays.fill
1.3% 1 + 0 Total compiled
Thread-local ticks:
55.3% 94 Blocked (of total)
10.5% 8 Compilation
tp=color Arrays Cube
Flat profile of 5.47 secs (435 total ticks): Thread-3
Interpreted + native Method
70.1% 0 + 305 java.lang.Thread.sleep
0.5% 2 + 0 java.awt.EventQueue.postEventPrivate
70.6% 2 + 305 Total interpreted
Compiled + native Method
0.7% 0 + 3 java.awt.EventQueue.postEventPrivate
0.7% 0 + 3 Total compiled
Stub + native Method
23.7% 0 + 103 java.lang.Thread.sleep
23.7% 0 + 103 Total stub
Thread-local ticks:
5.1% 22 Compilation
Flat profile of 40.62 secs (3664 total ticks): AWT-Windows
Interpreted + native Method
99.8% 3 + 3654 sun.awt.windows.WToolkit.eventLoop
0.1% 0 + 3 sun.awt.windows.WToolkit.init
0.0% 1 + 0 sun.awt.PostEventQueue.postEvent
0.0% 1 + 0 sun.awt.AWTAutoShutdown.setToolkitBusy
0.0% 0 + 1 sun.awt.SunToolkit.getAppContext
100.0% 5 + 3658 Total interpreted
Thread-local ticks:
0.0% 1 Compilation
Flat profile of 28.53 secs (2580 total ticks): TimerQueue
Interpreted + native Method
100.0% 0 + 1 java.lang.System.currentTimeMillis
100.0% 0 + 1 Total interpreted
Thread-local ticks:
100.0% 2579 Blocked (of total)
Flat profile of 38.81 secs (3536 total ticks): DestroyJavaVM
Thread-local ticks:
100.0% 3536 Blocked (of total)
Flat profile of 40.60 secs (3664 total ticks): AWT-EventQueue-0
Interpreted + native Method
23.4% 0 + 119 net.java.games.jogl.impl.windows.WGL.SwapBuffers
11.2% 0 + 57 net.java.games.jogl.impl.windows.WindowsGLImpl.glDrawAr
rays
4.9% 0 + 25 net.java.games.jogl.impl.windows.WGL.wglMakeCurrent
2.8% 0 + 14 sun.awt.windows.WGlobalCursorManager.findHeavyweightUnd
erCursor
2.6% 0 + 13 sun.awt.windows.Win32BlitLoops.Blit
2.0% 0 + 10 sun.awt.windows.Win32DDRenderer.doFillRectDD
1.4% 0 + 7 sun.java2d.loops.DrawGlyphList.DrawGlyphList
1.4% 0 + 7 sun.awt.windows.Win32DDRenderer.doDrawLineDD
1.4% 0 + 7 net.java.games.jogl.impl.JAWT_DrawingSurface.FreeDrawin
gSurfaceInfo0
0.6% 0 + 3 java.lang.Object.clone
0.4% 0 + 2 sun.java2d.loops.Blit.Blit
0.4% 0 + 2 java.lang.Thread.currentThread
0.4% 0 + 2 sun.awt.windows.WGlobalCursorManager.setCursor
0.4% 0 + 2 java.lang.System.arraycopy
0.4% 0 + 2 net.java.games.jogl.impl.JAWT_DrawingSurface.Unlock0
0.4% 0 + 2 sun.awt.windows.Win32Renderer.doFillRect
0.2% 0 + 1 net.java.games.jogl.impl.windows.WGL.ChoosePixelFormat0
0.2% 1 + 0 net.java.games.jogl.impl.JAWT.GetDrawingSurface0
0.2% 0 + 1 java.lang.Object.wait
0.2% 0 + 1 net.java.games.jogl.impl.JAWT.FreeDrawingSurface0
0.2% 1 + 0 sun.awt.image.PixelConverter$Xrgb.rgbToPixel
0.2% 0 + 1 sun.awt.windows.WGlobalCursorManager.getCursorPos
0.2% 0 + 1 sun.awt.windows.WGlobalCursorManager.findComponentAt
0.2% 0 + 1 net.java.games.jogl.impl.JAWT_DrawingSurface.Lock0
0.2% 0 + 1 sun.awt.windows.WInputMethod.disableNativeIME
61.2% 16 + 295 Total interpreted (including elided)
Compiled + native Method
0.6% 0 + 3 java.awt.EventQueue.getNextEvent
0.4% 0 + 2 sun.awt.AWTAutoShutdown.notifyThreadFree
0.2% 1 + 0 java.util.ArrayList.get
1.2% 1 + 5 Total compiled
Stub + native Method
4.5% 0 + 23 net.java.games.jogl.impl.windows.WGL.SwapBuffers
3.0% 0 + 15 net.java.games.jogl.impl.windows.WGL.wglMakeCurrent
3.0% 0 + 15 net.java.games.jogl.impl.windows.WindowsGLImpl.glDrawAr
rays
0.6% 0 + 3 java.lang.Thread.isInterrupted
0.6% 0 + 3 net.java.games.jogl.impl.JAWT_DrawingSurface.FreeDrawin
gSurfaceInfo0
0.4% 0 + 2 java.lang.Class.isAssignableFrom
0.2% 1 + 0 net.java.games.jogl.impl.JAWT_DrawingSurfaceInfo.platfo
rmInfo0
0.2% 0 + 1 java.lang.Object.notifyAll
0.2% 0 + 1 net.java.games.jogl.impl.windows.WGL.wglGetProcAddress
12.6% 1 + 63 Total stub
Thread-local ticks:
86.1% 3156 Blocked (of total)
25.0% 127 Compilation
Flat profile of 40.73 secs (3675 total ticks): AWT-Shutdown
Thread-local ticks:
100.0% 3675 Blocked (of total)
Flat profile of 40.74 secs (3676 total ticks): Java2D Disposer
Thread-local ticks:
100.0% 3676 Blocked (of total)
Global summary of 41.15 seconds:
100.0% 3730 Received ticks
0.6% 23 Received GC ticks
0.5% 17 Compilation
java -Xprof -jar JavaGL.jar LWJGL!!!!!!!
Flat profile of 2.90 secs (258 total ticks): AWT-Shutdown
Thread-local ticks:
100.0% 258 Blocked (of total)
Flat profile of 2.77 secs (246 total ticks): AWT-EventQueue-0
Interpreted + native Method
9.7% 0 + 3 java.io.RandomAccessFile.open
9.7% 0 + 3 sun.awt.windows.Win32DDRenderer.doFillRectDD
6.5% 0 + 2 sun.awt.windows.WInputMethodDescriptor.getNativeAvailab
leLocales
3.2% 1 + 0 sun.awt.windows.WFramePeer.getState
3.2% 0 + 1 sun.awt.windows.WInputMethod.getOpenStatus
3.2% 0 + 1 sun.awt.windows.WGlobalCursorManager.findHeavyweightUnd
erCursor
3.2% 0 + 1 java.lang.Object.hashCode
3.2% 0 + 1 java.lang.System.currentTimeMillis
3.2% 0 + 1 sun.nio.ch.FileDispatcher.read0
3.2% 0 + 1 sun.font.FileFont.getGlyphImage
3.2% 1 + 0 sun.font.TrueTypeFont.verify
3.2% 0 + 1 sun.awt.windows.Win32OffScreenSurfaceData.initSurface
3.2% 0 + 1 java.lang.Thread.currentThread
3.2% 0 + 1 sun.awt.windows.Win32DDRenderer.doDrawLineDD
3.2% 1 + 0 java.nio.HeapByteBuffer.<init>
3.2% 0 + 1 sun.java2d.loops.Blit.Blit
3.2% 1 + 0 java.lang.StringCoding.trim
3.2% 1 + 0 java.nio.ByteBufferAsCharBufferB.get
3.2% 1 + 0 java.awt.KeyboardFocusManager.getCurrentKeyboardFocusMa
nager
3.2% 1 + 0 javax.swing.plaf.metal.MetalUtils$GradientPainter.paint
3.2% 1 + 0 java.awt.EventQueue.getNextEvent
3.2% 1 + 0 java.io.Win32FileSystem.parentOrNull
3.2% 1 + 0 com.sun.java.swing.SwingUtilities2.drawString
3.2% 1 + 0 sun.java2d.pipe.SpanShapeRenderer.renderRect
3.2% 1 + 0 sun.font.FileFontStrike.<init>
96.8% 12 + 18 Total interpreted
Compiled + native Method
3.2% 1 + 0 java.util.Hashtable.get
3.2% 1 + 0 Total compiled
Thread-local ticks:
87.4% 215 Blocked (of total)
170 frames in 5.0 seconds = 34.0 FPS
207 frames in 5.0 seconds = 41.4 FPS
Flat profile of 12.90 secs (1144 total ticks): AWT-Windows
Interpreted + native Method
99.7% 0 + 1141 sun.awt.windows.WToolkit.eventLoop
0.3% 0 + 3 sun.awt.windows.WToolkit.init
100.0% 0 + 1144 Total interpreted
Flat profile of 0.11 secs (11 total ticks): AWT-Shutdown
Thread-local ticks:
100.0% 11 Blocked (of total)
Flat profile of 13.02 secs (1156 total ticks): Java2D Disposer
Thread-local ticks:
100.0% 1156 Blocked (of total)
Flat profile of 13.09 secs (1161 total ticks): main
Interpreted + native Method
2.7% 0 + 27 org.lwjgl.opengl.GL11.nglDrawArrays
1.7% 0 + 17 org.lwjgl.opengl.Win32PeerInfo.nChoosePixelFormat
1.7% 0 + 17 org.lwjgl.opengl.Win32Display.nUpdate
1.1% 0 + 11 org.lwjgl.opengl.Win32ContextImplementation.nSwapBuffer
s
0.6% 0 + 6 org.lwjgl.opengl.Win32ContextImplementation.nCreate
0.2% 0 + 2 org.lwjgl.opengl.GL11.nglPopMatrix
0.2% 2 + 0 java.lang.ClassLoader.defineClass1
0.1% 0 + 1 java.lang.ClassLoader.findLoadedClass0
0.1% 0 + 1 java.lang.ClassLoader$NativeLibrary.load
0.1% 0 + 1 org.lwjgl.opengl.Win32DisplayPeerInfo.nDestroy
0.1% 0 + 1 org.lwjgl.opengl.Win32Display.destroyWindow
0.1% 0 + 1 org.lwjgl.opengl.GL11.nglGetError
0.1% 0 + 1 sun.misc.Unsafe.putByte
0.1% 0 + 1 org.lwjgl.opengl.Win32Display.nCreateWindow
0.1% 0 + 1 org.lwjgl.opengl.Win32Display.isCloseRequested
0.1% 0 + 1 org.lwjgl.opengl.Win32Display.createMouse
0.1% 0 + 1 org.lwjgl.opengl.Win32DisplayPeerInfo.nInitDC
0.1% 0 + 1 org.lwjgl.opengl.Win32Display.getAvailableDisplayModes
0.1% 0 + 1 sun.awt.windows.WDialogPeer.showModal
0.1% 0 + 1 java.util.zip.Inflater.init
0.1% 0 + 1 sun.awt.windows.WDialogPeer.create
0.1% 0 + 1 java.lang.Thread.currentThread
0.1% 1 + 0 sun.awt.Win32GraphicsEnvironment.createFontConfiguratio
n
0.1% 1 + 0 javax.swing.JEditorPane.<init>
0.1% 1 + 0 org.lwjgl.opengl.Display.getAvailableDisplayModes
10.6% 11 + 96 Total interpreted (including elided)
Compiled + native Method
0.5% 5 + 0 JavaGL.RenderPolygons.rendershit
0.1% 0 + 1 sun.net.www.ParseUtil.encodePath
0.1% 0 + 1 java.util.Properties$LineReader.readLine
0.7% 5 + 2 Total compiled
Stub + native Method
29.9% 0 + 301 org.lwjgl.opengl.GL11.nglRotatef
22.3% 0 + 224 org.lwjgl.opengl.GL11.nglDrawArrays
14.9% 0 + 150 org.lwjgl.opengl.GL11.nglPopMatrix
10.3% 0 + 104 org.lwjgl.opengl.GL11.nglInterleavedArrays
3.6% 0 + 36 org.lwjgl.opengl.GL11.nglScalef
3.6% 0 + 36 org.lwjgl.opengl.GL11.nglTranslatef
3.6% 0 + 36 org.lwjgl.opengl.GL11.nglPushMatrix
88.2% 0 + 887 Total stub
Thread-local ticks:
13.4% 155 Blocked (of total)
0.5% 5 Compilation
Global summary of 13.09 seconds:
100.0% 1164 Received ticks
0.3% 3 Received GC ticks
0.4% 5 Compilation
also here is the jogl version of the code
package joglspec;
import javax.swing.*;
import java.util.*;
import net.java.games.jogl.*;
import java.awt.*;
import java.awt.image.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class JtVertPointer2
extends JFrame implements JTest {
int texture_id;
BufferedImage img;
float g_fElpasedTime;
double g_dCurrentTime;
double g_dLastTime;
protected boolean loop = false;
protected int sleep = 10;
float[] g_cubeVertices = {
0.0f, 0.0f, -1.0f, -1.0f, 1.0f,
1.0f, 0.0f, 1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, -1.0f, 1.0f, 1.0f,
1.0f, 0.0f, -1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f, 1.0f, -1.0f,
0.0f, 1.0f, 1.0f, 1.0f, -1.0f,
0.0f, 0.0f, 1.0f, -1.0f, -1.0f,
0.0f, 1.0f, -1.0f, 1.0f, -1.0f,
0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f, -1.0f, -1.0f,
0.0f, 1.0f, 1.0f, -1.0f, -1.0f,
0.0f, 0.0f, 1.0f, -1.0f, 1.0f,
1.0f, 0.0f, -1.0f, -1.0f, 1.0f,
1.0f, 0.0f, 1.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f, 1.0f, -1.0f,
0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, -1.0f, 1.0f,
0.0f, 0.0f, -1.0f, -1.0f, -1.0f,
1.0f, 0.0f, -1.0f, -1.0f, 1.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f,
0.0f, 1.0f, -1.0f, 1.0f, -1.0f
};
GLDrawable drawable;
GLDrawable gldraw;
Component glComp;
int paintCount = 0;
GLCapabilities glCap;
public JtVertPointer2() {
}
void joglInit() {
img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_BGR);
Graphics2D g2d = img.createGraphics();
g2d.setPaint(new GradientPaint(0, 0, Color.RED, 256, 256, Color.GREEN));
g2d.fillRect(0, 0, 256, 256);
g2d.setColor(Color.BLUE);
g2d.setFont(g2d.getFont().deriveFont(30f));
g2d.drawString("Hello", 10, 130);
glComp = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
gldraw = (GLDrawable) glComp;
getContentPane().setLayout(new BorderLayout());
getContentPane().add(glComp);
gldraw.addGLEventListener(new GLEventListener() {
public void init(GLDrawable drawable) {
glinit(drawable);
}
public void display(GLDrawable drawable) {
gldisplay(drawable);
paintCount++;
if ( (loop) && (sleep <= 0))
glComp.repaint();
}
public void reshape(GLDrawable drawable, int x, int y, int width,
int height) {
glreshape(drawable, x, y, width, height);
}
public void displayChanged(GLDrawable drawable, boolean modeChanged,
boolean deviceChanged) {
gldisplayChanged(drawable, modeChanged, deviceChanged);
}
});
}
public static void main(String[] args) {
JtVertPointer2 f = new JtVertPointer2();
f.joglInit();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setBounds(10, 10, 512, 512);
f.setVisible(true);
}
public void glinit(GLDrawable drawable) {
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
texture_id = TestUtils.loadTexture(gl, img);
}
public void gldisplay(GLDrawable drawable) {
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
float fXrot = 200.0f;
float fYrot = 122.0f;
float fZrot = 12.0f;
g_fElpasedTime += .1;
fXrot += 10.1f * g_fElpasedTime;
fYrot += 10.2f * g_fElpasedTime;
fZrot += 10.3f * g_fElpasedTime;
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -5.0f);
gl.glRotatef(fXrot, 1.0f, 0.0f, 0.0f);
gl.glRotatef(fYrot, 0.0f, 1.0f, 0.0f);
gl.glRotatef(fZrot, 0.0f, 0.0f, 1.0f);
// gl.glBindTexture( GL.GL_TEXTURE_2D, g_textureID );
int n = 20;
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
for (int z = 0; z < n; z++) {
gl.glPushMatrix();
int n2 = n>>1;
gl.glTranslated(x-n2,y-n2,z-n2);
gl.glScaled(.1,.1,.1);
gl.glInterleavedArrays(GL.GL_T2F_V3F, 0, g_cubeVertices);
gl.glDrawArrays(GL.GL_QUADS, 0, 24);
gl.glPopMatrix();
}
}
}
}
public void anaminate() {
Thread t = new Thread() {
public void run() {
while (loop) {
try {
if (sleep > 0) {
Thread.sleep(sleep / 1000, sleep % 1000);
if (glComp != null)
glComp.repaint();
}
else
Thread.sleep(200);
}
catch (InterruptedException ex) {
}
}
}
};
t.setDaemon(true);
t.start();
}
public void glreshape(GLDrawable drawable, int x, int y, int width,
int height) {
}
public void gldisplayChanged(GLDrawable drawable, boolean modeChanged,
boolean deviceChanged) {
}
public void setDelay(int time) {
sleep = time;
}
long oldtime = 0;
float fps;
public float calcFPS() {
long time = System.currentTimeMillis();
int tmp = paintCount;
paintCount = 0;
fps = 1000 * tmp / (float) (time - oldtime);
oldtime = time;
return fps;
}
public void init() {
joglInit();
setBounds(5, 10, 512, 512);
setVisible(true);
}
public void stop() {
loop = false;
}
public String toString() {
return "phong color polygon";
}
public void end() {
stop();
this.setVisible(false);
this.getContentPane().remove(glComp);
glComp.setVisible(false);
glComp = null;
gldraw = null;
}
public String getPerfString() {
return this.toString() + " fps=" + fps;
}
boolean lightWeight = false;
public void setProp(Properties prop) {
String v = prop.getProperty(LIGHTWEIGHT);
lightWeight = ("true".equals(v));
}
public void start() {
if (!loop) {
loop = true;
anaminate();
}
}
}
I noticed a difference that could be the difference in speed....
GLU.gluLookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(angle, 1.0f, .0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f);
is inside the loops for drawing the cubes in the LWJGL version, but not in the JOGL version. The call to these inside of the loops could easily do that much of a performace hit.
That is, if I can read code correctly :roll:
I commented those all out and moved the lookat to my init. It did not make any diff. Man I am really stumped here..... I've also gone at the code with my netbeans profiler and have turned up zero nada' zilch......
Are you running in a window or are you running in fullscreen mode?
Are you running LWJGL through AWT versus just using the main LWJGL window?
Could you post your LWJGL init code? (Display.create() and other stuff that might be usefull that is specific to LWJGL).
EDIT: Maybe post all of your LWJGL code if its not too long...
... can't think of anything else :lol:
I think my answer lies here:
public void anaminate() {
Thread t = new Thread() {
public void run() {
while (loop) {
try {
if (sleep > 0) {
Thread.sleep(sleep / 1000, sleep % 1000);
if (glComp != null)
glComp.repaint();
}
else
Thread.sleep(200);
}
catch (InterruptedException ex) {
}
}
}
};
t.setDaemon(true);
t.start();
}
Ahaha :)
Cas :)