Forum Discussion
whitehexagon
11 years agoExplorer
JOVR with JOGL and SDK rendering
I'm trying to get something really basic running with OSX, JOVR, OpenGL, JOGL, and SDK 0-4-1 rendering. But I'm getting this fatal error at step 5.5 in the code below. C [libGL.dylib+0x18b5] glG...
whitehexagon
11 years agoExplorer
Cracked it, kinda...
I got rid of my 2 offscreen buffers, and created 2 FBOs inside of a gl context attached to the NEWT window. That seems to have solved this 'tie buffer to screen' step I needed.
What I'm missing now is color on my geometry, its just gray. Also head tracking just seems to wobble the scene very slightly -might be noise.
What I have noticed that even with such a simple scene, this tired laptop only hits 30fps, which is suspicious because that's exactly what I get from the LWGJL RiftApp, and also the same from the far more complex SDK OculusWorldDemo.
Oh and the HSW is already driving me crazy!
I got rid of my 2 offscreen buffers, and created 2 FBOs inside of a gl context attached to the NEWT window. That seems to have solved this 'tie buffer to screen' step I needed.
What I'm missing now is color on my geometry, its just gray. Also head tracking just seems to wobble the scene very slightly -might be noise.
What I have noticed that even with such a simple scene, this tired laptop only hits 30fps, which is suspicious because that's exactly what I get from the LWGJL RiftApp, and also the same from the far more complex SDK OculusWorldDemo.
Oh and the HSW is already driving me crazy!
import static com.oculusvr.capi.OvrLibrary.ovrDistortionCaps.ovrDistortionCap_Chromatic;
import static com.oculusvr.capi.OvrLibrary.ovrDistortionCaps.ovrDistortionCap_TimeWarp;
import static com.oculusvr.capi.OvrLibrary.ovrDistortionCaps.ovrDistortionCap_Vignette;
import static com.oculusvr.capi.OvrLibrary.ovrTrackingCaps.ovrTrackingCap_Orientation;
import static com.oculusvr.capi.OvrLibrary.ovrTrackingCaps.ovrTrackingCap_Position;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.fixedfunc.GLLightingFunc;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
import javax.media.opengl.glu.GLU;
import org.saintandreas.gl.MatrixStack;
import org.saintandreas.math.Matrix4f;
import org.saintandreas.vr.RiftUtils;
import com.jogamp.newt.Display;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Screen;
import com.jogamp.newt.Window;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.FBObject;
import com.jogamp.opengl.FBObject.TextureAttachment;
import com.jogamp.opengl.util.Animator;
import com.oculusvr.capi.EyeRenderDesc;
import com.oculusvr.capi.FovPort;
import com.oculusvr.capi.Hmd;
import com.oculusvr.capi.OvrLibrary;
import com.oculusvr.capi.OvrLibrary.ovrEyeType;
import com.oculusvr.capi.OvrRecti;
import com.oculusvr.capi.OvrSizei;
import com.oculusvr.capi.OvrVector2i;
import com.oculusvr.capi.Posef;
import com.oculusvr.capi.RenderAPIConfig;
import com.oculusvr.capi.Texture;
import com.oculusvr.capi.TextureHeader;
public class TinyBox3 implements KeyListener {
//JOGL
//private WHAnimator animator;
private Animator animator;
private GLWindow glWindow;
//Rift Specific
private Hmd hmd;
private int frameCount;
private EyeRenderDesc eyeRenderDescs[];
private final OvrRecti[] eyeRenderViewport = (OvrRecti[]) new OvrRecti().toArray(2);
private final Posef eyeRenderPose[] = (Posef[]) new Posef().toArray(2);
private final Texture eyeTextures[] = (Texture[]) new Texture().toArray(2);
private final FovPort fovPorts[] = (FovPort[]) new FovPort().toArray(2);
private final Matrix4f projections[] = new Matrix4f[2];
private final class DK2EventListener implements GLEventListener {
private final FBObject leftEye;
private final FBObject rightEye;
public DK2EventListener() {
leftEye = new FBObject();
rightEye = new FBObject();
}
@Override
public void init(GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2();
gl.glClearColor(0.5f, 0.5f, 0.0f, 0.0f);
final float lightPos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, lightPos, 0);
gl.glEnable(GLLightingFunc.GL_LIGHTING);
gl.glEnable(GLLightingFunc.GL_LIGHT0);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glEnable(GLLightingFunc.GL_NORMALIZE);
RenderAPIConfig rc = new RenderAPIConfig();
rc.Header.RTSize = hmd.Resolution;
rc.Header.Multisample = 1;
int distortionCaps = ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp | ovrDistortionCap_Vignette;
eyeRenderDescs = hmd.configureRendering(rc, distortionCaps, fovPorts);
leftEye.reset(gl, eyeRenderViewport[ovrEyeType.ovrEye_Left].Size.w, eyeRenderViewport[ovrEyeType.ovrEye_Left].Size.h, 0, false);
rightEye.reset(gl, eyeRenderViewport[ovrEyeType.ovrEye_Right].Size.w, eyeRenderViewport[ovrEyeType.ovrEye_Right].Size.h, 0, false);
leftEye.detachAllColorbuffer(gl);
rightEye.detachAllColorbuffer(gl);
leftEye.detachAll(gl); //clears right eye...
TextureAttachment leftTA = leftEye.attachTexture2D(gl, 0, true);
TextureAttachment rightTA = rightEye.attachTexture2D(gl, 0, true);
eyeTextures[ovrEyeType.ovrEye_Left].TextureId = leftTA.getName();
eyeTextures[ovrEyeType.ovrEye_Right].TextureId = rightTA.getName();
}
@Override
public void dispose(GLAutoDrawable drawable) {
// TODO Auto-generated method stub
}
@Override
public void display(GLAutoDrawable drawable) {
GL2 gl2 = drawable.getGL().getGL2();
hmd.beginFrameTiming(++frameCount);
for (int eyeIndex = 0; eyeIndex < ovrEyeType.ovrEye_Count; eyeIndex++){
int eye = hmd.EyeRenderOrder[eyeIndex];
MatrixStack.PROJECTION.set(projections[eye]);
MatrixStack mv = MatrixStack.MODELVIEW;
mv.push();
{
Posef pose = hmd.getEyePose(eye);
eyeRenderPose[eye].Orientation = pose.Orientation;
eyeRenderPose[eye].Position = pose.Position;
gl2.glViewport(eyeRenderViewport[eye].Pos.x, eyeRenderViewport[eye].Pos.y, eyeRenderViewport[eye].Size.w, eyeRenderViewport[eye].Size.h);
mv.preTranslate(RiftUtils.toVector3f(eyeRenderPose[eye].Position).mult(-1));
mv.preRotate(RiftUtils.toQuaternion(eyeRenderPose[eye].Orientation).inverse());
mv.preTranslate(RiftUtils.toVector3f(eyeRenderDescs[eye].ViewAdjust));
gl2.glBindFramebuffer(GL2.GL_FRAMEBUFFER, eyeTextures[eye].TextureId);
gl2.glClear(GL2.GL_COLOR_BUFFER_BIT);
renderScene(gl2);
gl2.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0);
// gl2.glDisable(GL2.GL_TEXTURE_2D);
}
mv.pop();
}
hmd.endFrame(eyeRenderPose, eyeTextures);
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL2 gl2 = drawable.getGL().getGL2();
gl2.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl2.glLoadIdentity();
GLU glu = new GLU();
glu.gluPerspective(45.0f, ((float) width / (float) height), 0.1f, 10000.0f);
gl2.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl2.glLoadIdentity();
}
} //end inner class
public void run() {
frameCount = -1;
//step 1 - hmd init
Hmd.initialize();
try {
Thread.sleep(400);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
//step 2 - hmd create
hmd = Hmd.create(0); //assume 1 device at index 0
if (hmd == null) {
System.out.println("null hmd");
hmd = Hmd.createDebug(OvrLibrary.ovrHmdType.ovrHmd_DK2);
}
//step 3 - hmd size queries
OvrSizei resolution = hmd.Resolution;
System.out.println("resolution= "+resolution.w+"x"+resolution.h);
OvrSizei recommendedTex0Size = hmd.getFovTextureSize(OvrLibrary.ovrEyeType.ovrEye_Left, hmd.DefaultEyeFov[0], 1.0f);
OvrSizei recommendedTex1Size = hmd.getFovTextureSize(OvrLibrary.ovrEyeType.ovrEye_Right, hmd.DefaultEyeFov[1], 1.0f);
System.out.println("left= "+recommendedTex0Size.w+"x"+recommendedTex0Size.h);
System.out.println("right= "+recommendedTex1Size.w+"x"+recommendedTex1Size.h);
int displayW = recommendedTex0Size.w + recommendedTex1Size.w;
int displayH = Math.max(recommendedTex0Size.h, recommendedTex1Size.h);
OvrSizei renderTargetEyeSize = new OvrSizei(displayW / 2, displayH); //size of single eye
System.out.println("using eye size "+renderTargetEyeSize.w+"x"+renderTargetEyeSize.h);
eyeRenderViewport[0].Pos = new OvrVector2i(0, 0);
eyeRenderViewport[0].Size = renderTargetEyeSize;
eyeRenderViewport[1].Pos = eyeRenderViewport[0].Pos;
eyeRenderViewport[1].Size = renderTargetEyeSize;
eyeTextures[0].Header = new TextureHeader(renderTargetEyeSize, eyeRenderViewport[0]);
eyeTextures[1].Header = new TextureHeader(renderTargetEyeSize, eyeRenderViewport[1]);
//step 4 - tracking
System.out.println("step 4 - tracking");
if (hmd.configureTracking(ovrTrackingCap_Orientation | ovrTrackingCap_Position, 0) == 0) {
throw new IllegalStateException("Unable to start the sensor");
}
//step 5 - FOV
System.out.println("step 5 - FOV");
for (int eye = 0; eye < 2; ++eye) {
fovPorts[eye] = hmd.DefaultEyeFov[eye];
projections[eye] = RiftUtils.toMatrix4f(
Hmd.getPerspectiveProjection(
fovPorts[eye], 0.1f, 1000000f, true));
}
//step 6 - opengl window
System.out.println("step 6 - window");
//Display.dumpDisplayList(""); //only gives: DisplayList[] entries: 0 - main
final Display display = NewtFactory.createDisplay("tiny");
final Screen screen = NewtFactory.createScreen(display, 0);
GLProfile glProfile = GLProfile.get(GLProfile.GL2);
System.out.println("got: " + glProfile.getImplName());
final Window window = NewtFactory.createWindow(screen, new GLCapabilities(glProfile));
window.setSize(displayW, displayH);
glWindow = GLWindow.create(window);
glWindow.setAutoSwapBufferMode(false);
glWindow.setUndecorated(true);
glWindow.setFullscreen(true);
glWindow.addKeyListener(this);
glWindow.addGLEventListener(new DK2EventListener());
glWindow.setVisible(true);
//step 7 - loop
System.out.println("step 7 - loop");
//animator = new WHAnimator(75);
animator = new Animator();
animator.add(glWindow);
animator.start();
}
public void renderScene(GL2 gl2) {
gl2.glLoadIdentity();
gl2.glTranslatef(-1.5f, 0.0f, -6.0f);
gl2.glBegin(GL2.GL_TRIANGLES);
gl2.glColor3f(1.0f, 0.0f, 0.0f);
gl2.glVertex3f( 0.0f, 1.0f, 0.0f);
gl2.glColor3f(0.0f, 1.0f, 0.0f);
gl2.glVertex3f(-1.0f,-1.0f, 0.0f);
gl2.glColor3f(0.0f, 0.0f, 1.0f);
gl2.glVertex3f( 1.0f,-1.0f, 0.0f);
gl2.glEnd();
gl2.glTranslatef(3.0f, 0.0f, 0.0f);
gl2.glBegin(GL2.GL_QUADS);
gl2.glColor3f(0.5f, 0.5f, 1.0f);
gl2.glVertex3f(-1.0f, 1.0f, 0.0f);
gl2.glVertex3f( 1.0f, 1.0f, 0.0f);
gl2.glVertex3f( 1.0f,-1.0f, 0.0f);
gl2.glVertex3f(-1.0f,-1.0f, 0.0f);
gl2.glEnd();
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
hmd.destroy();
Hmd.shutdown();
animator.stop();
glWindow.destroy();
System.exit(0);
}
if(e.getKeyCode() == KeyEvent.VK_F5) {
new Thread() {
public void run() {
glWindow.setFullscreen(!glWindow.isFullscreen());
} }.start();
}
hmd.dismissHSWDisplay();
}
public static void main(String[] args) {
new TinyBox3().run();
}
}
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 1 year ago
- 2 years ago
- 10 months ago
- 10 years ago