Panoramview with OpenGl?

Everything related to 3D programming
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Panoramview with OpenGl?

Post by dige »

Hello, folks,

currently I use OGRE to view 180 degree panoramas and 360 VR images.
Unfortunately, loading larger files is very slow and OGRE can't handle umlauts and long file names.

Is there a possibility to create the following code via OpenGl?

Code: Select all

  [..]
  If CreateMaterial(0, LoadTexture(0,file$))
    DisableMaterialLighting(0,#True)
    MaterialFilteringMode(0,#PB_Material_Trilinear)
    RotateMaterial(0,180,#PB_Material_Fixed)
    
    If IsCamera(0) And IsEntity(0)
      RotateEntity(0,0,0,0, #PB_Absolute)
      MoveCamera(0,0,0,0, #PB_Absolute  )
      RotateCamera(0,0,0,0, #PB_Absolute)
      CameraFOV(0, 90)
    EndIf
    
      If IsTexture(0)
        w = TextureWidth(0)
        h = TextureHeight(0)
      EndIf
    

    If  (g360 = 0 And CreateCylinder(0, -1, -1.5, 32, 32, 0)) Or ( g360 = 1 And CreateSphere(0, -10, 64, 64))
      CreateLight(#PB_Any, RGB(25, 25, 180), 0, 0, 0, #PB_Light_Point)
      
      If g360 = 0
        RotateCamera(0,0,0,180, #PB_Absolute)
      Else
        RotateCamera(0,0,0,0, #PB_Absolute)
      EndIf
      
      If CreateEntity(0,MeshID(0),MaterialID(0))
        Result = #True
      EndIf
    EndIf
  EndIf
I'm also thinking about using the webgadget, because viewing panoramas runs very well with Javascript in the browser.

Ciao Dige
"Daddy, I'll run faster, then it is not so far..."
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Panoramview with OpenGl?

Post by Olliv »

OpenGL can do it certainly but native statement too normally do it.

Code: Select all

CameraFOV(CamerAngle.D)
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Panoramview with OpenGl?

Post by applePi »

hope that this example of some usage, it is cooked from several examples. the picture is wide, and we can look at different parts of the scene by rotating the camera with left/right keys. there are complex codes in the web about the FishEye and spheric projection, unfortunately mostly written in modern opengl

i expect but not sure that CameraFOV have some resemblance with:
gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
and
gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ)


try different values for gluPerspective

if someone have more to add or to correct please help to enrich the subject.
save this picture as arches.jpg in the same folder as the code:
http://www.mundhenk.com/photos/panorama ... nk.com.jpg
or from http://s000.tinyupload.com/index.php?fi ... 6961855121

Code: Select all

Structure Point3D
  x.f
  y.f
  z.f
  tu.f
  tv.f
  r.f
  g.f
  b.f
EndStructure

UseJPEGImageDecoder()
UseJPEGImageEncoder()
UsePNGImageDecoder()

Declare FillArray()
Define event, quit

Dim *Buffer(1)

LoadImage(1, "arches.jpg")

*Buffer(1) = EncodeImage(1) ; default is: #PB_ImagePlugin_BMP : encode the image in BMP 

Dim TexID(1)
OpenWindow(0, 0, 0, 800, 600, "... Up/Down: zoom in/out...Left/Right: rotate the Camera .. 'W': wire frame... ")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 10, 10, WindowWidth(0) , WindowHeight(0) , #PB_OpenGL_Keyboard)

;- Generate textures

glGenTextures_(1, @TexID(1))
glBindTexture_(#GL_TEXTURE_2D, TexID(1))
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR)
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR)
glTexImage2D_(#GL_TEXTURE_2D, 0, 3, ImageWidth(1), ImageHeight(1), 0, #GL_BGR_EXT, #GL_UNSIGNED_BYTE, *Buffer(1))

FreeMemory(*Buffer(1))

glEnable_(#GL_TEXTURE_2D)   ; Enable texture mapping 
glBindTexture_(#GL_TEXTURE_2D, TexID(1))

glLoadIdentity_();
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glTranslatef_(0, 0, -5)
glEnable_(#GL_DEPTH_TEST)

Global NbX = 100
Global NbY = 100

Global Dim Point3D.Point3D(NbX,NbY)
Global Dim MeshDataInd.PB_MeshFace(60000)
Global indexsize = ArraySize(MeshDataInd()) + 1
Global r.f
Global dist.f = 40
;Debug indexsize
;Debug WindowWidth(0)
;Debug WindowHeight(0)
FillArray()
  ;Debug indx  
 ;=================================================================================
rot.f = 1
;glPointSize_( 1 )  
;glTranslatef_(0.0, 0.0, -30)
SetActiveGadget(0) ; make the openGLgadget active

glPushMatrix_(); to store the current state
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_();
;gluPerspective_(60.0, WindowWidth(0)/WindowHeight(0), 1.0, 200.0)
gluPerspective_(90.0, 800/5000, 1.0, 200.0)
glMatrixMode_(#GL_MODELVIEW)
;glTranslatef_(0, 0, -5)
glShadeModel_(#GL_SMOOTH) 
glEnable_(#GL_DEPTH_TEST)
glViewport_(0, 0, WindowWidth(0), WindowHeight(0))

gluLookAt_( 0, 0, dist, ; the camera looking from position 0,0,dist  to 0,0,0 from above
            0,  0, 0,
            0,  1,  0 ) 

glPopMatrix_()

Repeat
  
  Event = WindowEvent()
  
  glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
  glClearColor_(0.9, 0.9, 0.9, 1)
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
    
  glEnableClientState_(#GL_VERTEX_ARRAY )
  glEnableClientState_(#GL_COLOR_ARRAY)
  glEnableClientState_(#GL_TEXTURE_COORD_ARRAY)
  ;glRotatef_(rot/2, 0, 1, 0);
 
  glVertexPointer_(3, #GL_FLOAT,SizeOf(Point3D),@Point3D(0,0)\x)
  glColorPointer_(3, #GL_FLOAT, SizeOf(Point3D), @Point3D(0,0)\r)
  glTexCoordPointer_(2, #GL_FLOAT, SizeOf(Point3D), @Point3D(0,0)\tu)
    
  glDrawElements_(#GL_TRIANGLES,indexsize,#GL_UNSIGNED_INT, @MeshDataInd(0)\Index)
  ;glDrawElements_(#GL_POLYGON,indx,#GL_UNSIGNED_INT, @MeshDataInd(0)\Index)
  
  glDisableClientState_(#GL_TEXTURE_COORD_ARRAY)
  glDisableClientState_(#GL_COLOR_ARRAY)
  glDisableClientState_(#GL_VERTEX_ARRAY);
  
  If Event = #PB_Event_Gadget And EventGadget() = 0 
    If EventType() = #PB_EventType_KeyDown  ; like KeyboardReleased
            key = GetGadgetAttribute(0,#PB_OpenGL_Key )
            
            If key = #PB_Shortcut_Escape ;  Esc key to exit
               quit = 1
            
               ElseIf Key = #PB_Shortcut_W; display wire Frame or solid frame
               If fill
                glPolygonMode_(#GL_FRONT_AND_BACK, #GL_FILL )
                fill ! 1
               Else
                glPolygonMode_(#GL_FRONT_AND_BACK, #GL_LINE )
                fill ! 1
              EndIf
            ElseIf Key = #PB_Shortcut_Up
                dist - 0.2
                glLoadIdentity_()
                gluLookAt_( 0, 0.1, dist,  r, 0, 0,  0,  1,  0 )
                ;glScalef_(1.05,1.05,1.05)
              ElseIf Key = #PB_Shortcut_Down
                dist + 0.2
                glLoadIdentity_()
                gluLookAt_( 0, 0.1, dist,  r, 0, 0,  0,  1,  0 )
                ;glScalef_(0.95,0.95,0.95)
              ElseIf Key = #PB_Shortcut_Right
                r+0.05
                ;glMatrixMode_(#GL_MODELVIEW);
                glLoadIdentity_()
                gluLookAt_( 0, 0.1, dist,  r, 0, 0,  0,  1,  0 )
              ElseIf Key = #PB_Shortcut_Left
                r-0.05
                ;glMatrixMode_(#GL_MODELVIEW);
                glLoadIdentity_()
                gluLookAt_( 0, 0.1, dist,  r, 0, 0,  0,  1,  0 )
                                              
            EndIf
               
    EndIf
   EndIf
    
   SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
   Delay(5)
Until Event = #PB_Event_CloseWindow Or quit = 1

  glDeleteTextures_(1, @TexID(1))
    
    
Procedure FillArray()

xMin.f = -20 : yMin.f = -20: zMin.f = -20 : xMax.f = 20: yMax = 20 : zMax = 20
  range.f = xMax - xMin
  step1.f = range*1 / NbX
  x.f = xMin: z.f = zMin : y.f = yMin : tu.f: tv.f
  
  For b=0 To NbY
   t.f=0
    For a=0 To NbX
     t + #PI/(NbX+1)
      z.f = 0  ;-40*Sin(t)+Cos(t)
      
      ;**********************************************************************            
      
      Point3D(a,b)\x = x*1
      Point3D(a,b)\y = y*1.5 ; change to 2 to amplify the height
      Point3D(a,b)\z = z*1
      
      Point3D(a,b)\tu = a/NbX
      Point3D(a,b)\tv = b/NbY     
      
      Point3D(a,b)\r = 1 :Point3D(a,b)\g = 1 :Point3D(a,b)\b = 1 
            
      x.f + step1
      
    Next a
    
    x = xMin
    y.f + step1
  Next b
  
   ;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
  
  Nb=NbX+1
  For b=0 To NbY-1
    For a=0 To NbX-1
      
      P1=a+(b*Nb)
      P2=P1+1
      P3=a+(b+1)*Nb
      P4=P3+1
      ;MeshFace(P3, P2, P1)
      ;MeshFace(P2, P3, P4)
      MeshDataInd(indx)\Index = P3
      MeshDataInd(indx+1)\Index = P2
      MeshDataInd(indx+2)\Index = P1
      
      MeshDataInd(indx+3)\Index = P2
      MeshDataInd(indx+4)\Index = P3
      MeshDataInd(indx+5)\Index = P4
      indx+6
    Next
  Next  
    EndProcedure
    
  
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Panoramview with OpenGl?

Post by Mijikai »

Is it just scrolling or does it need to be mapped onto a sphere/ cylinder?
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Panoramview with OpenGl?

Post by applePi »

@Mijikai , the Ogre code above have CameraFOV and camera rotation so i guess it is scrolling the scene by rotating the camera. and not like these pictures http://idea.hosting.lv/a/gfx/cubeshots.html
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Panoramview with OpenGl?

Post by Olliv »

Does the compiler support that is following ?

CameraFOV(myCamera, 360)
ResizeCamera(myCamera, -100, -100, 300, 300)
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Panoramview with OpenGl?

Post by Olliv »

@ApplePi

I can see your code contains gl functions and I can see also you gave an other gl code. I will try to copy them and to test them.

I appreciate gl functions.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Panoramview with OpenGl?

Post by DK_PETER »

currently I use OGRE to view 180 degree panoramas and 360 VR images.
Unfortunately, loading larger files is very slow and OGRE can't handle umlauts and long file names.
The speed of loading images are based on size of memory (ram), ram speed and disk speed.
Your other problem can be circumventet by using LoadImage() and then draw it to
the texture.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Panoramview with OpenGl?

Post by dige »

@DK_PETER: thx for that hint. I'll try if its fix the problem :-)
"Daddy, I'll run faster, then it is not so far..."
Thierri005
New User
New User
Posts: 1
Joined: Sun Oct 13, 2019 1:49 am

Re: Panoramview with OpenGl?

Post by Thierri005 »

Mijikai wrote:Is it just scrolling transfert cdg or does it need to be mapped onto a sphere/ cylinder?
I am a newbie to this but so far the only post processor and I have not had these grooves you show.
Post Reply