vlitomsk

LibOVR + OpenGL strange behaviour

Jul 29th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ...
  2. BYTE *pixels;
  3. void initGL(void) {
  4.     /* init GLFW, GLEW...*/
  5.     glEnable(GL_TEXTURE_2D);
  6.     glGenTextures(1, &gltexture);
  7.     glBindTexture(GL_TEXTURE_2D, gltexture);
  8.     pixels = new BYTE[texW * texH * 3];
  9.     memset(pixels, 0x90, texW * texH * 3);
  10.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texW, texH, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  11.     glBindTexture(GL_TEXTURE_2D, 0);
  12.  
  13.     /* generate framebuffer */
  14.  
  15.     /* THIS piece of code */
  16.     /* vvvvvvvvvvvvvvvvvv */
  17.     glGenFramebuffers(1, &fbo);
  18.     glBindFramebuffer(GL_FRAMEBUFFER, fbo);
  19.     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gltexture, 0);
  20.     glBindFramebuffer(GL_FRAMEBUFFER, 0);
  21.     /* ^^^^^^^^^^^^^^^^^^ */
  22. }
  23.  
  24. /* It's standard usage */
  25. void draw(void) {
  26.     ovrFrameTiming hmdFrameTiming = ovrHmd_BeginFrame(hmd, 0);
  27.     for (int i = 0; i < 2; ++i) {
  28.         ovrEyeType eye = hmdDesc.EyeRenderOrder[i];
  29.         ovrPosef eyePose = ovrHmd_BeginEyeRender(hmd, eye);
  30.         ovrHmd_EndEyeRender(hmd, eye, eyePose, &eyeTexture[i].Texture);
  31.     }
  32.  
  33.     ovrHmd_EndFrame(hmd);
  34. }
  35.  
  36. void initOR(void) {
  37.     // creating ovrHmd, ... ovrHmdDesc
  38.     ovrGLConfig cfg;
  39.     memset(&cfg, 0, sizeof(cfg));
  40.     memset(eyes, 0, sizeof(eyes));
  41.  
  42.     cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
  43.     cfg.OGL.Header.RTSize = { screenW, screenH };
  44.     cfg.OGL.Header.Multisample = 1;
  45.     cfg.OGL.Window = 0;
  46.  
  47.     ovrFovPort fov[2];
  48.     // setting fov...
  49.  
  50.     if (!ovrHmd_ConfigureRendering(hmd, &cfg.Config, ovrDistortionCap_TimeWarp | ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette, fov,   eyes)) {
  51.         MSG("Can't configure OculusRift rendering!");
  52.         exit(EXIT_FAILURE);
  53.     }
  54.  
  55.     for (int i = 0; i < 2; ++i) {
  56.         eyeTexture[i].OGL.Header.API = ovrRenderAPI_OpenGL;
  57.         eyeTexture[i].OGL.Header.TextureSize = { texW, texH };
  58.         eyeTexture[i].OGL.Header.RenderViewport.Pos = { i*(screenW >> 1), 0 };
  59.         eyeTexture[i].OGL.Header.RenderViewport.Size = { screenW >> 1, screenH };
  60.         eyeTexture[i].OGL.TexId = gltexture;
  61.     }
  62. }
  63.  
  64. // ....
Advertisement
Add Comment
Please, Sign In to add comment